@Test public void withAdvice() throws InterruptedException { adapter1.start(); MessageChannel channel = ctx.getBean("input", MessageChannel.class); channel.send(new GenericMessage<String>("foo")); assertTrue(adviceCalled.await(10, TimeUnit.SECONDS)); }
@Test public void testOutboundChannelAdapterWithinChain() throws Exception { AbstractApplicationContext ctx = new ClassPathXmlApplicationContext( "TcpOutboundChannelAdapterWithinChainTests-context.xml", this.getClass()); AbstractServerConnectionFactory scf = ctx.getBean(AbstractServerConnectionFactory.class); TestingUtilities.waitListening(scf, null); ctx.getBean(AbstractClientConnectionFactory.class).setPort(scf.getPort()); ctx.getBeansOfType(ConsumerEndpointFactoryBean.class).values().forEach(c -> c.start()); MessageChannel channelAdapterWithinChain = ctx.getBean("tcpOutboundChannelAdapterWithinChain", MessageChannel.class); PollableChannel inbound = ctx.getBean("inbound", PollableChannel.class); String testPayload = "Hello, world!"; channelAdapterWithinChain.send(new GenericMessage<String>(testPayload)); Message<?> m = inbound.receive(1000); assertNotNull(m); assertEquals(testPayload, new String((byte[]) m.getPayload())); ctx.close(); }
/** * Tests a loopback. The client-side outbound adapter sends a message over * a connection from the client connection factory; the server side * receives the message, puts in on a channel which is the input channel * for the outbound adapter that's sharing the connections. The response * comes back to an inbound adapter that is sharing the client's * connection and we verify we get the echo back as expected. * * @throws Exception */ @Test public void test1() throws Exception { TestingUtilities.waitListening(this.server, null); this.client.setPort(this.server.getPort()); this.ctx.getBeansOfType(ConsumerEndpointFactoryBean.class).values().forEach(c -> c.start()); for (int i = 0; i < 5; i++) { MessageChannel input = ctx.getBean("input", MessageChannel.class); input.send(MessageBuilder.withPayload("Test").build()); QueueChannel replies = ctx.getBean("replies", QueueChannel.class); Message<?> message = replies.receive(10000); assertNotNull(message); assertEquals("Test", message.getPayload()); } assertThat(this.listener.openEvent, notNullValue()); assertThat(this.listener.openEvent.getConnectionFactoryName(), equalTo("client")); }
/** * Tests a loopback. The client-side outbound adapter sends a message over * a connection from the client connection factory; the server side * receives the message, puts in on a channel which is the input channel * for the outbound adapter that's sharing the connections. The response * comes back to an inbound adapter that is sharing the client's * connection and we verify we get the echo back as expected. * * @throws Exception */ @Test public void test1() throws Exception { TestingUtilities.waitListening(this.server, null); this.client.setPort(this.server.getPort()); this.ctx.getBeansOfType(ConsumerEndpointFactoryBean.class).values().forEach(c -> c.start()); MessageChannel input = ctx.getBean("input", MessageChannel.class); input.send(MessageBuilder.withPayload("Test").build()); QueueChannel replies = ctx.getBean("replies", QueueChannel.class); Message<?> message = replies.receive(10000); MessageHistory history = MessageHistory.read(message); assertNotNull(history); Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "inboundClient", 0); assertNotNull(componentHistoryRecord); assertEquals("ip:tcp-inbound-channel-adapter", componentHistoryRecord.getProperty("type")); assertNotNull(message); assertEquals("Test", message.getPayload()); }
Map<String, ConsumerEndpointFactoryBean> consumers = this.ctx.getBeansOfType(ConsumerEndpointFactoryBean.class); consumers.values().forEach(g -> g.start()); initializedFactories = true;