use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class AsyncHandlerTests method testGatewayWithException.
@Test
public void testGatewayWithException() throws Exception {
this.whichTest = 0;
GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class);
gpfb.setBeanFactory(mock(BeanFactory.class));
DirectChannel input = new DirectChannel();
gpfb.setDefaultRequestChannel(input);
gpfb.setDefaultReplyTimeout(10000L);
gpfb.afterPropertiesSet();
Foo foo = (Foo) gpfb.getObject();
this.handler.setOutputChannel(null);
EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler);
consumer.afterPropertiesSet();
consumer.start();
this.latch.countDown();
try {
foo.exchange("foo");
} catch (MessagingException e) {
assertThat(e.getClass().getSimpleName(), equalTo("RuntimeException"));
assertThat(e.getMessage(), equalTo("foo"));
}
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class AsyncHandlerTests method testGateway.
@Test
public void testGateway() throws Exception {
this.whichTest = 0;
GatewayProxyFactoryBean gpfb = new GatewayProxyFactoryBean(Foo.class);
gpfb.setBeanFactory(mock(BeanFactory.class));
DirectChannel input = new DirectChannel();
gpfb.setDefaultRequestChannel(input);
gpfb.setDefaultReplyTimeout(10000L);
gpfb.afterPropertiesSet();
Foo foo = (Foo) gpfb.getObject();
this.handler.setOutputChannel(null);
EventDrivenConsumer consumer = new EventDrivenConsumer(input, this.handler);
consumer.afterPropertiesSet();
consumer.start();
this.latch.countDown();
String result = foo.exchange("foo");
assertEquals("reply", result);
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class AnnotatedTests method testHistoryWithAnnotatedComponents.
@Test
public void testHistoryWithAnnotatedComponents() throws Exception {
ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("annotated-config.xml", this.getClass());
ApplicationListener<ApplicationEvent> listener = new ApplicationListener<ApplicationEvent>() {
@Override
public void onApplicationEvent(ApplicationEvent event) {
MessageHistory history = MessageHistory.read((Message<?>) event.getSource());
Properties adapterHistory = history.get(1);
assertEquals("myAdapter", adapterHistory.get("name"));
assertEquals("outbound-channel-adapter", adapterHistory.get("type"));
}
};
listener = spy(listener);
ac.addApplicationListener(listener);
MessageChannel channel = ac.getBean("inputChannel", MessageChannel.class);
EventDrivenConsumer consumer = ac.getBean("myAdapter", EventDrivenConsumer.class);
MessageHandler handler = (MessageHandler) TestUtils.getPropertyValue(consumer, "handler");
Field handlerField = consumer.getClass().getDeclaredField("handler");
handlerField.setAccessible(true);
handlerField.set(consumer, handler);
channel.send(new GenericMessage<String>("hello"));
verify(listener, times(1)).onApplicationEvent((ApplicationEvent) Mockito.any());
ac.close();
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class JpaOutboundGatewayParserTests method advised.
@Test
public void advised() throws Throwable {
setUp("JpaOutboundGatewayParserTests.xml", getClass(), "advised");
EventDrivenConsumer jpaOutboundGatewayEndpoint = context.getBean("advised", EventDrivenConsumer.class);
MessageHandler jpaOutboundGateway = TestUtils.getPropertyValue(jpaOutboundGatewayEndpoint, "handler", MessageHandler.class);
FooAdvice advice = context.getBean("jpaFooAdvice", FooAdvice.class);
assertTrue(AopUtils.isAopProxy(jpaOutboundGateway));
try {
jpaOutboundGateway.handleMessage(new GenericMessage<String>("foo"));
fail("expected ReplyRequiredException");
} catch (MessagingException e) {
assertTrue(e instanceof ReplyRequiredException);
}
Mockito.verify(advice).doInvoke(Mockito.any(ExecutionCallback.class), Mockito.any(Object.class), Mockito.any(Message.class));
}
use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.
the class JpaMessageHandlerParserTests method advisedAndTransactional.
/*
* Tests that an already advised handler (tx) gets the request handler advice added to its chain.
*/
@Test
public void advisedAndTransactional() throws Exception {
setUp("JpaMessageHandlerParserTests.xml", getClass());
EventDrivenConsumer consumer = this.context.getBean("advisedAndTransactional", EventDrivenConsumer.class);
final AbstractMessageChannel inputChannel = TestUtils.getPropertyValue(consumer, "inputChannel", AbstractMessageChannel.class);
assertEquals("target", inputChannel.getComponentName());
final MessageHandler handler = TestUtils.getPropertyValue(consumer, "handler", MessageHandler.class);
adviceCalled = 0;
handler.handleMessage(new GenericMessage<String>("foo"));
assertEquals(1, adviceCalled);
}
Aggregations