List of usage examples for org.springframework.integration.support MessageBuilder withPayload
public static <T> MessageBuilder<T> withPayload(T payload)
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);/*from ww w .j a va 2 s . c o m*/ 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);/*from www.j av a2s . co m*/ 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 testHeaderEnricher() { QueueChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder .withPayload("<root><elementOne>1</elementOne><elementTwo>2</elementTwo></root>") .setReplyChannel(replyChannel).build(); try {// w ww . j a v a 2 s . c o m this.xpathHeaderEnricherInput.send(message); fail("Expected MessageDispatchingException"); } catch (Exception e) { assertThat(e, instanceOf(MessageDeliveryException.class)); assertThat(e.getCause(), instanceOf(MessageDispatchingException.class)); assertThat(e.getMessage(), containsString("Dispatcher has no subscribers")); } this.controlBus.send("@xpathHeaderEnricher.start()"); this.xpathHeaderEnricherInput.send(message); Message<?> result = replyChannel.receive(2000); assertNotNull(result); MessageHeaders headers = result.getHeaders(); assertEquals("1", headers.get("one")); assertEquals("2", headers.get("two")); assertThat(headers.getReplyChannel(), instanceOf(String.class)); }
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 www .j av a 2s. 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 testRecipientListRouter() { Message<String> fooMessage = MessageBuilder.withPayload("fooPayload").setHeader("recipient", true).build(); Message<String> barMessage = MessageBuilder.withPayload("barPayload").setHeader("recipient", true).build(); Message<String> badMessage = new GenericMessage<>("badPayload"); this.recipientListInput.send(fooMessage); Message<?> result1a = this.fooChannel.receive(2000); assertNotNull(result1a);/*from w ww .j a va 2 s . com*/ assertEquals("foo", result1a.getPayload()); Message<?> result1b = this.barChannel.receive(2000); assertNotNull(result1b); assertEquals("foo", result1b.getPayload()); this.recipientListInput.send(barMessage); assertNull(this.fooChannel.receive(0)); Message<?> result2b = this.barChannel.receive(2000); assertNotNull(result2b); assertEquals("bar", result2b.getPayload()); this.recipientListInput.send(badMessage); assertNull(this.fooChannel.receive(0)); assertNull(this.barChannel.receive(0)); Message<?> result3c = this.defaultOutputChannel.receive(2000); assertNotNull(result3c); assertEquals("bad", result3c.getPayload()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testPriority() throws InterruptedException { Message<String> message = MessageBuilder.withPayload("1").setPriority(1).build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("-1").setPriority(-1).build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("3").setPriority(3).build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("0").setPriority(0).build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("2").setPriority(2).build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("none").build(); this.priorityChannel.send(message); message = MessageBuilder.withPayload("31").setPriority(3).build(); this.priorityChannel.send(message); this.controlBus.send("@priorityChannelBridge.start()"); Message<?> receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive);// w w w .j a v a2 s . c o m assertEquals("3", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("31", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("2", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("1", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("0", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("-1", receive.getPayload()); receive = this.priorityReplyChannel.receive(2000); assertNotNull(receive); assertEquals("none", receive.getPayload()); this.controlBus.send("@priorityChannelBridge.stop()"); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testGatewayFlow() throws Exception { PollableChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build(); this.gatewayInput.send(message); Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);/*from ww w .j a v a2 s. c om*/ assertEquals("FOO", receive.getPayload()); assertNull(this.gatewayError.receive(1)); message = MessageBuilder.withPayload("bar").setReplyChannel(replyChannel).build(); this.gatewayInput.send(message); receive = replyChannel.receive(1); assertNull(receive); receive = this.gatewayError.receive(2000); assertNotNull(receive); assertThat(receive, instanceOf(ErrorMessage.class)); assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class)); assertThat(((Exception) receive.getPayload()).getMessage(), containsString("' rejected Message")); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testAmqpOutboundFlow() throws Exception { this.amqpOutboundInput .send(MessageBuilder.withPayload("hello through the amqp").setHeader("routingKey", "foo").build()); Message<?> receive = null;// w w w . jav a 2s . c o m int i = 0; do { receive = this.amqpReplyChannel.receive(); if (receive != null) { break; } Thread.sleep(100); i++; } while (i < 10); assertNotNull(receive); assertEquals("HELLO THROUGH THE AMQP", receive.getPayload()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testJmsOutboundInboundFlow() { this.jmsOutboundInboundChannel.send(MessageBuilder.withPayload("hello THROUGH the JMS") .setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "jmsInbound").build()); Message<?> receive = this.jmsOutboundInboundReplyChannel.receive(5000); assertNotNull(receive);// w w w . j av a 2s.c om assertEquals("HELLO THROUGH THE JMS", receive.getPayload()); this.jmsOutboundInboundChannel.send(MessageBuilder.withPayload("hello THROUGH the JMS") .setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "jmsMessageDriver").build()); receive = this.jmsOutboundInboundReplyChannel.receive(5000); assertNotNull(receive); assertEquals("hello through the jms", receive.getPayload()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testJmsPipelineFlow() { PollableChannel replyChannel = new QueueChannel(); Message<String> message = MessageBuilder.withPayload("hello through the jms pipeline") .setReplyChannel(replyChannel).setHeader("destination", "jmsPipelineTest").build(); this.jmsOutboundGatewayChannel.send(message); Message<?> receive = replyChannel.receive(5000); assertNotNull(receive);//from www. j a va 2s . c o m assertEquals("HELLO THROUGH THE JMS PIPELINE", receive.getPayload()); }