List of usage examples for org.springframework.integration.xmpp.inbound ChatMessageListeningEndpoint afterPropertiesSet
@Override public final void afterPropertiesSet()
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test /*/*from w ww . j ava 2 s . c om*/ * Should add/remove StanzaListener when endpoint started/stopped */ public void testLifecycle() { final Set<StanzaListener> packetListSet = new HashSet<>(); XMPPConnection connection = mock(XMPPConnection.class); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(connection); willAnswer(invocation -> { packetListSet.add(invocation.getArgument(0)); return null; }).given(connection).addAsyncStanzaListener(any(StanzaListener.class), isNull()); willAnswer(invocation -> { packetListSet.remove(invocation.getArgument(0)); return null; }).given(connection).removeAsyncStanzaListener(any(StanzaListener.class)); assertEquals(0, packetListSet.size()); endpoint.setOutputChannel(new QueueChannel()); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); endpoint.start(); assertEquals(1, packetListSet.size()); endpoint.stop(); assertEquals(0, packetListSet.size()); }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testWithImplicitXmppConnection() { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, mock(XMPPConnection.class)); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(); endpoint.setBeanFactory(bf);//from w w w. ja v a 2 s. c o m endpoint.setOutputChannel(new QueueChannel()); endpoint.afterPropertiesSet(); assertNotNull(TestUtils.getPropertyValue(endpoint, "xmppConnection")); }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test(expected = IllegalArgumentException.class) public void testNoXmppConnection() { ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testWithErrorChannel() throws NotConnectedException { DefaultListableBeanFactory bf = new DefaultListableBeanFactory(); XMPPConnection connection = mock(XMPPConnection.class); bf.registerSingleton(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, connection); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(); DirectChannel outChannel = new DirectChannel(); outChannel.subscribe(message -> { throw new RuntimeException("ooops"); });/*from ww w .j av a2 s . c om*/ PollableChannel errorChannel = new QueueChannel(); endpoint.setBeanFactory(bf); endpoint.setOutputChannel(outChannel); endpoint.setErrorChannel(errorChannel); endpoint.afterPropertiesSet(); StanzaListener listener = (StanzaListener) TestUtils.getPropertyValue(endpoint, "stanzaListener"); Message smackMessage = new Message("kermit@frog.com"); smackMessage.setBody("hello"); smackMessage.setThread("1234"); listener.processPacket(smackMessage); ErrorMessage msg = (ErrorMessage) errorChannel.receive(); assertEquals("hello", ((MessagingException) msg.getPayload()).getFailedMessage().getPayload()); }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testExpression() throws Exception { TestXMPPConnection testXMPPConnection = new TestXMPPConnection(); QueueChannel inputChannel = new QueueChannel(); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(testXMPPConnection); SpelExpressionParser parser = new SpelExpressionParser(); endpoint.setPayloadExpression(parser.parseExpression("#root")); endpoint.setOutputChannel(inputChannel); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); endpoint.start();/*from w ww .ja v a 2s .c om*/ Message smackMessage = new Message(); smackMessage.setBody("foo"); XmlPullParser xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString())); xmlPullParser.next(); testXMPPConnection.parseAndProcessStanza(xmlPullParser); org.springframework.messaging.Message<?> receive = inputChannel.receive(10000); assertNotNull(receive); Object payload = receive.getPayload(); assertThat(payload, instanceOf(Message.class)); assertEquals(smackMessage.getStanzaId(), ((Message) payload).getStanzaId()); assertEquals(smackMessage.getBody(), ((Message) payload).getBody()); Log logger = Mockito.spy(TestUtils.getPropertyValue(endpoint, "logger", Log.class)); given(logger.isInfoEnabled()).willReturn(true); final CountDownLatch logLatch = new CountDownLatch(1); willAnswer(invocation -> { Object result = invocation.callRealMethod(); logLatch.countDown(); return result; }).given(logger).info(anyString()); new DirectFieldAccessor(endpoint).setPropertyValue("logger", logger); endpoint.setPayloadExpression(null); smackMessage = new Message(); xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString())); xmlPullParser.next(); testXMPPConnection.parseAndProcessStanza(xmlPullParser); ArgumentCaptor<String> argumentCaptor = ArgumentCaptor.forClass(String.class); assertTrue(logLatch.await(10, TimeUnit.SECONDS)); verify(logger).info(argumentCaptor.capture()); assertEquals("The XMPP Message [" + smackMessage + "] with empty body is ignored.", argumentCaptor.getValue()); endpoint.stop(); }
From source file:org.springframework.integration.xmpp.inbound.ChatMessageListeningEndpointTests.java
@Test public void testGcmExtension() throws Exception { String data = "{\n" + " \"to\":\"me\",\n" + " \"notification\": {\n" + " \"title\": \"Something interesting\",\n" + " \"text\": \"Here we go\"\n" + " },\n" + " \"time_to_live\":\"600\"\n" + " }\n" + "}"; GcmPacketExtension packetExtension = new GcmPacketExtension(data); Message smackMessage = new Message(); smackMessage.addExtension(packetExtension); TestXMPPConnection testXMPPConnection = new TestXMPPConnection(); QueueChannel inputChannel = new QueueChannel(); ChatMessageListeningEndpoint endpoint = new ChatMessageListeningEndpoint(testXMPPConnection); Expression payloadExpression = new SpelExpressionParser().parseExpression("#extension.json"); endpoint.setPayloadExpression(payloadExpression); endpoint.setOutputChannel(inputChannel); endpoint.setBeanFactory(mock(BeanFactory.class)); endpoint.afterPropertiesSet(); endpoint.start();//from ww w . j av a 2 s . c o m XmlPullParser xmlPullParser = PacketParserUtils.newXmppParser(new StringReader(smackMessage.toString())); xmlPullParser.next(); testXMPPConnection.parseAndProcessStanza(xmlPullParser); org.springframework.messaging.Message<?> receive = inputChannel.receive(10000); assertNotNull(receive); assertEquals(data, receive.getPayload()); endpoint.stop(); }