Search in sources :

Example 71 with EventDrivenConsumer

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"));
    }
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) MessagingException(org.springframework.messaging.MessagingException) BeanFactory(org.springframework.beans.factory.BeanFactory) Test(org.junit.Test)

Example 72 with EventDrivenConsumer

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);
}
Also used : GatewayProxyFactoryBean(org.springframework.integration.gateway.GatewayProxyFactoryBean) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 73 with EventDrivenConsumer

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();
}
Also used : Field(java.lang.reflect.Field) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) ApplicationEvent(org.springframework.context.ApplicationEvent) ApplicationListener(org.springframework.context.ApplicationListener) Properties(java.util.Properties) Test(org.junit.Test)

Example 74 with EventDrivenConsumer

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));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ReplyRequiredException(org.springframework.integration.handler.ReplyRequiredException) MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) MessagingException(org.springframework.messaging.MessagingException) Test(org.junit.Test)

Example 75 with EventDrivenConsumer

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);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) MessageHandler(org.springframework.messaging.MessageHandler) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5