List of usage examples for org.springframework.messaging.support GenericMessage GenericMessage
public GenericMessage(T payload)
From source file:org.springframework.integration.core.MessageIdGenerationTests.java
@Test public void testCustomIdGenerationWithChildRegistrar() throws Exception { ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext( "MessageIdGenerationTests-context.xml", this.getClass()); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent); IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); Mockito.reset(idGenerator);//w ww.ja v a 2s.co m MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage<Integer>(0)); verify(idGenerator, atLeastOnce()).generateId(); child.close(); parent.close(); this.assertDestroy(); }
From source file:org.springframework.integration.core.MessageIdGenerationTests.java
@Test public void testCustomIdGenerationWithChildRegistrarClosed() throws Exception { ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext( "MessageIdGenerationTests-context.xml", this.getClass()); ClassPathXmlApplicationContext child = new ClassPathXmlApplicationContext( new String[] { "MessageIdGenerationTests-context-withGenerator.xml" }, this.getClass(), parent); IdGenerator idGenerator = child.getBean("idGenerator", IdGenerator.class); Mockito.reset(idGenerator);//from w ww .ja v a 2s .c om MessageChannel inputChannel = child.getBean("input", MessageChannel.class); inputChannel.send(new GenericMessage<Integer>(0)); verify(idGenerator, atLeastOnce()).generateId(); child.close(); parent.close(); this.assertDestroy(); }
From source file:org.springframework.integration.core.MessageIdGenerationTests.java
@Test @Ignore/*from w w w . j a v a2 s . com*/ public void performanceTest() { int times = 1000000; StopWatch watch = new StopWatch(); watch.start(); for (int i = 0; i < times; i++) { new GenericMessage<Integer>(0); } watch.stop(); double defaultGeneratorElapsedTime = watch.getTotalTimeSeconds(); Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator"); ReflectionUtils.makeAccessible(idGeneratorField); ReflectionUtils.setField(idGeneratorField, null, (IdGenerator) () -> TimeBasedUUIDGenerator.generateId()); watch = new StopWatch(); watch.start(); for (int i = 0; i < times; i++) { new GenericMessage<Integer>(0); } watch.stop(); double timebasedGeneratorElapsedTime = watch.getTotalTimeSeconds(); logger.info("Generated " + times + " messages using default UUID generator " + "in " + defaultGeneratorElapsedTime + " seconds"); logger.info("Generated " + times + " messages using Timebased UUID generator " + "in " + timebasedGeneratorElapsedTime + " seconds"); logger.info("Time-based ID generator is " + defaultGeneratorElapsedTime / timebasedGeneratorElapsedTime + " times faster"); }
From source file:org.springframework.integration.dsl.test.ftp.FtpTests.java
@Test @SuppressWarnings("unchecked") public void testFtpMgetFlow() { String dir = "ftpSource/"; this.ftpMgetInputChannel.send(new GenericMessage<>(dir + "*")); Message<?> result = this.remoteFileOutputChannel.receive(1000); assertNotNull(result);//w ww . j a v a 2s . com List<File> localFiles = (List<File>) result.getPayload(); // should have filtered ftpSource2.txt assertEquals(2, localFiles.size()); for (File file : localFiles) { assertThat(file.getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir)); } assertThat(localFiles.get(1).getPath().replaceAll(Matcher.quoteReplacement(File.separator), "/"), Matchers.containsString(dir + "subFtpSource")); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testHandle() { assertNull(this.eventHolder.get()); this.flow3Input.send(new GenericMessage<>("2")); assertNotNull(this.eventHolder.get()); assertEquals(4, this.eventHolder.get()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testBridge() { GenericMessage<String> message = new GenericMessage<>("test"); this.bridgeFlowInput.send(message); Message<?> reply = this.bridgeFlowOutput.receive(5000); assertNotNull(reply);//from ww w. j a v a 2 s. c o m assertEquals("test", reply.getPayload()); assertTrue(this.beanFactory.containsBean("bridgeFlow2.channel#0")); assertThat(this.beanFactory.getBean("bridgeFlow2.channel#0"), instanceOf(FixedSubscriberChannel.class)); try { this.bridgeFlow2Input.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("@bridge.start()"); this.bridgeFlow2Input.send(message); reply = this.bridgeFlow2Output.receive(5000); assertNotNull(reply); assertEquals("test", reply.getPayload()); assertTrue(this.delayedAdvice.getInvoked()); }
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)); }// ww w. jav a 2 s. c o 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 w w . j a v a 2s.c o 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 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);// w w w . jav a2 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);//ww w . j av a 2 s. c om 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")); } }