List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testContentEnricher() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build(); this.enricherInput.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive);//from ww w. jav a 2 s.c o m assertEquals("Bar Bar", receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar Bar", result.getName()); assertNotNull(result.getDate()); assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate())); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testContentEnricher2() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build(); this.enricherInput2.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive);/*from w w w . jav a 2 s . co m*/ assertNull(receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar Bar", result.getName()); assertNotNull(result.getDate()); assertThat(new Date(), Matchers.greaterThanOrEqualTo(result.getDate())); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testContentEnricher3() { QueueChannel replyChannel = new QueueChannel(); Message<?> message = MessageBuilder.withPayload(new TestPojo("Bar")) .setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel).build(); this.enricherInput3.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive);// w ww .j ava2 s.c o m assertEquals("Bar Bar", receive.getHeaders().get("foo")); Object payload = receive.getPayload(); assertThat(payload, instanceOf(TestPojo.class)); TestPojo result = (TestPojo) payload; assertEquals("Bar", result.getName()); assertNull(result.getDate()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testSplitterResequencer() { QueueChannel replyChannel = new QueueChannel(); this.splitInput .send(MessageBuilder.withPayload("").setReplyChannel(replyChannel).setHeader("foo", "bar").build()); for (int i = 0; i < 12; i++) { Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);// ww w .j av a 2 s .c om assertFalse(receive.getHeaders().containsKey("foo")); assertTrue(receive.getHeaders().containsKey("FOO")); assertEquals("BAR", receive.getHeaders().get("FOO")); assertEquals(i + 1, receive.getPayload()); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testSplitterAggregator() { List<Character> payload = Arrays.asList('a', 'b', 'c', 'd', 'e'); QueueChannel replyChannel = new QueueChannel(); this.splitAggregateInput.send(MessageBuilder.withPayload(payload).setReplyChannel(replyChannel).build()); Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);/* w w w .j a va 2 s .c om*/ assertThat(receive.getPayload(), instanceOf(List.class)); @SuppressWarnings("unchecked") List<Object> result = (List<Object>) receive.getPayload(); for (int i = 0; i < payload.size(); i++) { assertEquals(payload.get(i), result.get(i)); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testRouter() { int[] payloads = new int[] { 1, 2, 3, 4, 5, 6 }; for (int payload : payloads) { this.routerInput.send(new GenericMessage<>(payload)); }/*from www . j a va 2s. co m*/ for (int i = 0; i < 3; i++) { Message<?> receive = this.oddChannel.receive(2000); assertNotNull(receive); assertEquals(i * 2 + 1, receive.getPayload()); receive = this.evenChannel.receive(2000); assertNotNull(receive); assertEquals(i * 2 + 2, receive.getPayload()); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testMethodInvokingRouter() { Message<String> fooMessage = new GenericMessage<>("foo"); Message<String> barMessage = new GenericMessage<>("bar"); Message<String> badMessage = new GenericMessage<>("bad"); this.routerMethodInput.send(fooMessage); Message<?> result1a = this.fooChannel.receive(2000); assertNotNull(result1a);/*from w ww . ja va 2 s.co m*/ assertEquals("foo", result1a.getPayload()); assertNull(this.barChannel.receive(0)); this.routerMethodInput.send(barMessage); assertNull(this.fooChannel.receive(0)); Message<?> result2b = this.barChannel.receive(2000); assertNotNull(result2b); assertEquals("bar", result2b.getPayload()); try { this.routerMethodInput.send(badMessage); fail("MessageDeliveryException expected."); } catch (MessageDeliveryException e) { assertThat(e.getMessage(), containsString("no channel resolved by router and no default output channel defined")); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testMethodInvokingRouter2() { Message<String> fooMessage = MessageBuilder.withPayload("foo").setHeader("targetChannel", "foo").build(); Message<String> barMessage = MessageBuilder.withPayload("bar").setHeader("targetChannel", "bar").build(); Message<String> badMessage = MessageBuilder.withPayload("bad").setHeader("targetChannel", "bad").build(); this.routerMethod2Input.send(fooMessage); Message<?> result1a = this.fooChannel.receive(2000); assertNotNull(result1a);//from ww w .j av a 2 s. c o m assertEquals("foo", result1a.getPayload()); assertNull(this.barChannel.receive(0)); this.routerMethod2Input.send(barMessage); assertNull(this.fooChannel.receive(0)); Message<?> result2b = this.barChannel.receive(2000); assertNotNull(result2b); assertEquals("bar", result2b.getPayload()); try { this.routerMethod2Input.send(badMessage); fail("DestinationResolutionException expected."); } catch (MessagingException e) { assertThat(e.getCause(), instanceOf(DestinationResolutionException.class)); assertThat(e.getCause().getMessage(), containsString("failed to look up MessageChannel with name 'bad-channel'")); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testMethodInvokingRouter3() { Message<String> fooMessage = new GenericMessage<>("foo"); Message<String> barMessage = new GenericMessage<>("bar"); Message<String> badMessage = new GenericMessage<>("bad"); this.routerMethod3Input.send(fooMessage); Message<?> result1a = this.fooChannel.receive(2000); assertNotNull(result1a);//from ww w . j a v a 2 s . c o m assertEquals("foo", result1a.getPayload()); assertNull(this.barChannel.receive(0)); this.routerMethod3Input.send(barMessage); assertNull(this.fooChannel.receive(0)); Message<?> result2b = this.barChannel.receive(2000); assertNotNull(result2b); assertEquals("bar", result2b.getPayload()); try { this.routerMethod3Input.send(badMessage); fail("DestinationResolutionException expected."); } catch (MessagingException e) { assertThat(e.getCause(), instanceOf(DestinationResolutionException.class)); assertThat(e.getCause().getMessage(), containsString("failed to look up MessageChannel with name 'bad-channel'")); } }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testMultiRouter() { Message<String> fooMessage = new GenericMessage<>("foo"); Message<String> barMessage = new GenericMessage<>("bar"); Message<String> badMessage = new GenericMessage<>("bad"); this.routerMultiInput.send(fooMessage); Message<?> result1a = this.fooChannel.receive(2000); assertNotNull(result1a);// w ww. j ava2s . c o m assertEquals("foo", result1a.getPayload()); Message<?> result1b = this.barChannel.receive(2000); assertNotNull(result1b); assertEquals("foo", result1b.getPayload()); this.routerMultiInput.send(barMessage); Message<?> result2a = this.fooChannel.receive(2000); assertNotNull(result2a); assertEquals("bar", result2a.getPayload()); Message<?> result2b = this.barChannel.receive(2000); assertNotNull(result2b); assertEquals("bar", result2b.getPayload()); try { this.routerMultiInput.send(badMessage); fail("MessageDeliveryException expected."); } catch (MessageDeliveryException e) { assertThat(e.getMessage(), containsString("no channel resolved by router and no default output channel defined")); } }