@Test public void adapterWithPollableChannel() { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext( "mailOutboundChannelAdapterParserTests.xml", this.getClass()); PollingConsumer pc = context.getBean("adapterWithPollableChannel", PollingConsumer.class); QueueChannel pollableChannel = TestUtils.getPropertyValue(pc, "inputChannel", QueueChannel.class); assertEquals("pollableChannel", pollableChannel.getComponentName()); context.close(); }
@Test public void testPollingConsumer() { Object pollingConsumer = context.getBean("withHeaderMapper"); QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(pollingConsumer, "inputChannel"); assertEquals("outboundPollingChannel", channel.getComponentName()); assertTrue(pollingConsumer instanceof PollingConsumer); }
@Test @SuppressWarnings({"rawtypes", "unchecked"}) public void testInboundAdapter() { ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class); MessageChannel errorChannel = (MessageChannel) TestUtils.getPropertyValue(adapter, "errorChannel"); assertEquals(context.getBean("errorChannel"), errorChannel); assertFalse(adapter.isAutoStartup()); QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(adapter, "outputChannel"); assertEquals("xmppInbound", channel.getComponentName()); XMPPConnection connection = (XMPPConnection) TestUtils.getPropertyValue(adapter, "xmppConnection"); assertSame(connection, context.getBean("testConnection")); Object stanzaFilter = context.getBean("stanzaFilter"); assertSame(stanzaFilter, TestUtils.getPropertyValue(adapter, "stanzaFilter")); assertEquals("#root", TestUtils.getPropertyValue(adapter, "payloadExpression.expression")); adapter.start(); Map asyncRecvListeners = TestUtils.getPropertyValue(connection, "asyncRecvListeners", Map.class); assertEquals(6, asyncRecvListeners.size()); Object lastListener = asyncRecvListeners.values().stream().reduce((first, second) -> second).get(); assertSame(stanzaFilter, TestUtils.getPropertyValue(lastListener, "packetFilter")); adapter.stop(); }
/** * Purges all messages from a message channel. Prerequisite is that channel is * of type {@link QueueChannel}. * * @param channel */ private void purgeChannel(MessageChannel channel) { if (channel instanceof QueueChannel) { List<Message<?>> messages = ((QueueChannel)channel).purge(messageSelector); if (log.isDebugEnabled()) { log.debug("Purged channel " + ((QueueChannel)channel).getComponentName() + " - removed " + messages.size() + " messages"); } } }
@Test public void testPollingConsumer() { Object pollingConsumer = context.getBean("withHeaderMapper"); QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(pollingConsumer, "inputChannel"); assertEquals("outboundPollingChannel", channel.getComponentName()); assertTrue(pollingConsumer instanceof PollingConsumer); }
@Test public void testInboundAdapter() { ChatMessageListeningEndpoint adapter = context.getBean("xmppInboundAdapter", ChatMessageListeningEndpoint.class); MessageChannel errorChannel = (MessageChannel) TestUtils.getPropertyValue(adapter, "errorChannel"); assertEquals(context.getBean("errorChannel"), errorChannel); assertFalse(adapter.isAutoStartup()); QueueChannel channel = (QueueChannel) TestUtils.getPropertyValue(adapter, "outputChannel"); assertEquals("xmppInbound", channel.getComponentName()); XMPPConnection connection = (XMPPConnection) TestUtils.getPropertyValue(adapter, "xmppConnection"); assertEquals(connection, context.getBean("testConnection")); }