Search in sources :

Example 66 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessageFilterTests method filterThrowsExceptionWithChannels.

@Test(expected = MessageRejectedException.class)
public void filterThrowsExceptionWithChannels() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> false);
    filter.setOutputChannel(outputChannel);
    filter.setThrowExceptionOnRejection(true);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 67 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessageFilterTests method filterRejectsSilentlyWithChannels.

@Test
public void filterRejectsSilentlyWithChannels() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> false);
    filter.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
    assertNull(outputChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 68 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessageFilterTests method filterDiscardsMessageAndThrowsException.

@Test(expected = MessageRejectedException.class)
public void filterDiscardsMessageAndThrowsException() throws Exception {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    QueueChannel discardChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> false);
    filter.setOutputChannel(outputChannel);
    filter.setDiscardChannel(discardChannel);
    filter.setThrowExceptionOnRejection(true);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    try {
        assertTrue(inputChannel.send(message));
    } catch (Exception e) {
        throw e;
    } finally {
        Message<?> reply = discardChannel.receive(0);
        assertNotNull(reply);
        assertEquals(message, reply);
        assertNull(outputChannel.receive(0));
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 69 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class MessageFilterTests method filterDiscardsMessage.

@Test
public void filterDiscardsMessage() {
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    QueueChannel discardChannel = new QueueChannel();
    MessageFilter filter = new MessageFilter(message -> false);
    filter.setOutputChannel(outputChannel);
    filter.setDiscardChannel(discardChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, filter);
    endpoint.start();
    Message<?> message = new GenericMessage<String>("test");
    assertTrue(inputChannel.send(message));
    Message<?> reply = discardChannel.receive(0);
    assertNotNull(reply);
    assertEquals(message, reply);
    assertNull(outputChannel.receive(0));
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 70 with EventDrivenConsumer

use of org.springframework.integration.endpoint.EventDrivenConsumer in project spring-integration by spring-projects.

the class GatewayProxyFactoryBeanTests method testCheckedExceptionRethrownAsIs.

@Test(expected = TestException.class)
public void testCheckedExceptionRethrownAsIs() throws Exception {
    GatewayProxyFactoryBean proxyFactory = new GatewayProxyFactoryBean();
    DirectChannel channel = new DirectChannel();
    EventDrivenConsumer consumer = new EventDrivenConsumer(channel, new MessageHandler() {

        @Override
        public void handleMessage(Message<?> message) {
            Method method = ReflectionUtils.findMethod(GatewayProxyFactoryBeanTests.class, "throwTestException");
            ReflectionUtils.invokeMethod(method, this);
        }
    });
    consumer.start();
    proxyFactory.setDefaultRequestChannel(channel);
    proxyFactory.setServiceInterface(TestExceptionThrowingInterface.class);
    proxyFactory.setBeanName("testGateway");
    proxyFactory.setBeanFactory(mock(BeanFactory.class));
    proxyFactory.afterPropertiesSet();
    TestExceptionThrowingInterface proxy = (TestExceptionThrowingInterface) proxyFactory.getObject();
    proxy.throwCheckedException("test");
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageHandler(org.springframework.messaging.MessageHandler) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Method(java.lang.reflect.Method) 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