use of org.springframework.integration.handler.MethodInvokingMessageHandler in project spring-integration by spring-projects.
the class MethodInvokingMessageHandlerTests method subscription.
@Test
public void subscription() throws Exception {
TestApplicationContext context = TestUtils.createTestApplicationContext();
SynchronousQueue<String> queue = new SynchronousQueue<String>();
TestBean testBean = new TestBean(queue);
QueueChannel channel = new QueueChannel();
context.registerChannel("channel", channel);
Message<String> message = new GenericMessage<String>("testing");
channel.send(message);
assertNull(queue.poll());
MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo");
PollingConsumer endpoint = new PollingConsumer(channel, handler);
endpoint.setTrigger(new PeriodicTrigger(10));
context.registerEndpoint("testEndpoint", endpoint);
context.refresh();
String result = queue.poll(2000, TimeUnit.MILLISECONDS);
assertNotNull(result);
assertEquals("testing", result);
context.stop();
}
use of org.springframework.integration.handler.MethodInvokingMessageHandler in project spring-integration by spring-projects.
the class ReactiveStreamsConsumerTests method testReactiveStreamsConsumerFluxMessageChannel.
@Test
public void testReactiveStreamsConsumerFluxMessageChannel() throws InterruptedException {
FluxMessageChannel testChannel = new FluxMessageChannel();
List<Message<?>> result = new LinkedList<>();
CountDownLatch stopLatch = new CountDownLatch(2);
MessageHandler messageHandler = m -> {
result.add(m);
stopLatch.countDown();
};
MessageHandler testSubscriber = new MethodInvokingMessageHandler(messageHandler, (String) null);
ReactiveStreamsConsumer reactiveConsumer = new ReactiveStreamsConsumer(testChannel, testSubscriber);
reactiveConsumer.setBeanFactory(mock(BeanFactory.class));
reactiveConsumer.afterPropertiesSet();
reactiveConsumer.start();
Message<?> testMessage = new GenericMessage<>("test");
testChannel.send(testMessage);
reactiveConsumer.stop();
try {
testChannel.send(testMessage);
} catch (Exception e) {
assertThat(e, instanceOf(MessageDeliveryException.class));
assertThat(e.getCause(), instanceOf(IllegalStateException.class));
assertThat(e.getMessage(), containsString("doesn't have subscribers to accept messages"));
}
reactiveConsumer.start();
Message<?> testMessage2 = new GenericMessage<>("test2");
testChannel.send(testMessage2);
assertTrue(stopLatch.await(10, TimeUnit.SECONDS));
assertThat(result, Matchers.<Message<?>>contains(testMessage, testMessage2));
}
use of org.springframework.integration.handler.MethodInvokingMessageHandler in project spring-integration by spring-projects.
the class MethodInvokingMessageHandlerTests method validMethod.
@Test
public void validMethod() {
MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(new TestSink(), "validMethod");
handler.handleMessage(new GenericMessage<String>("test"));
}
use of org.springframework.integration.handler.MethodInvokingMessageHandler in project spring-integration by spring-projects.
the class MethodInvokingMessageHandlerTests method methodWithReturnValue.
@Test(expected = MessagingException.class)
public void methodWithReturnValue() {
Message<?> message = new GenericMessage<String>("test");
try {
MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(new TestSink(), "methodWithReturnValue");
handler.handleMessage(message);
} catch (MessagingException e) {
assertEquals(e.getFailedMessage(), message);
throw e;
}
}
Aggregations