List of usage examples for org.springframework.integration.channel QueueChannel receive
@Override @Nullable public Message<?> receive(long timeout)
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);/*from www. ja va2 s.c om*/ 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);//from w w w.j a v a 2s .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 ww .j av a 2 s. c o 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 {//from w w w . j a v a2 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 testClaimCheck() { QueueChannel replyChannel = new QueueChannel(); Message<String> message = MutableMessageBuilder.withPayload("foo").setReplyChannel(replyChannel).build(); this.claimCheckInput.send(message); Message<?> receive = replyChannel.receive(2000); assertNotNull(receive);//from www . j a v a 2 s . c o m assertSame(message, receive); assertEquals(1, this.messageStore.getMessageCount()); assertSame(message, this.messageStore.getMessage(message.getHeaders().getId())); }
From source file:org.springframework.integration.dsl.test.xml.XmlTests.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 {//from w ww. ja va 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.controlBusFlowInput.send(new GenericMessage<>("@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)); assertFalse(headers.containsKey("foo")); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void stringPayloadCopiedToNewFile() throws Exception { long lastModified = 1234000L; Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT) .setHeader(FileHeaders.SET_MODIFIED, lastModified).build(); QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);/* w w w. j ava 2 s.com*/ handler.setPreserveTimestamp(true); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); assertLastModifiedIs(result, lastModified); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void testFileNameHeader() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT) .setHeader(FileHeaders.FILENAME, "dir1" + File.separator + "dir2/test").build(); QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);/* w w w . j a va 2 s .c om*/ handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); File destFile = (File) result.getPayload(); assertThat(destFile.getAbsolutePath(), containsString(TestUtils.applySystemFileSeparator("/dir1/dir2/test"))); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void stringPayloadCopiedToNewFileWithNewLines() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT).build(); QueueChannel output = new QueueChannel(); String newLine = System.getProperty("line.separator"); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);//from ww w . j a va 2s .c o m handler.setAppendNewLine(true); handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIs(result, SAMPLE_CONTENT + newLine); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void byteArrayPayloadCopiedToNewFile() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT.getBytes(DEFAULT_ENCODING)).build(); QueueChannel output = new QueueChannel(); handler.setOutputChannel(output);// w ww . j av a 2 s . c om handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); }