Search in sources :

Example 16 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method outboundOnlyServiceActivator.

@Test
public void outboundOnlyServiceActivator() throws InterruptedException {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    context.registerChannel("testChannel", new DirectChannel());
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    CountDownLatch latch = new CountDownLatch(1);
    OutboundOnlyTestBean testBean = new OutboundOnlyTestBean(latch);
    postProcessor.postProcessAfterInitialization(testBean, "testBean");
    context.refresh();
    DestinationResolver<MessageChannel> channelResolver = new BeanFactoryChannelResolver(context);
    MessageChannel testChannel = channelResolver.resolveDestination("testChannel");
    testChannel.send(new GenericMessage<String>("foo"));
    latch.await(1000, TimeUnit.MILLISECONDS);
    assertEquals(0, latch.getCount());
    assertEquals("foo", testBean.getMessageText());
    context.stop();
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) CountDownLatch(java.util.concurrent.CountDownLatch) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 17 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedFromInterface.

@Test
public void testMessageEndpointAnnotationInheritedFromInterface() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    context.registerChannel("inputChannel", inputChannel);
    context.registerChannel("outputChannel", outputChannel);
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    postProcessor.postProcessAfterInitialization(new SimpleAnnotatedEndpointImplementation(), "impl");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("ABC"));
    Message<?> message = outputChannel.receive(1000);
    assertEquals("test-ABC", message.getPayload());
    context.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 18 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedFromInterfaceWithAutoCreatedChannels.

@Test
public void testMessageEndpointAnnotationInheritedFromInterfaceWithAutoCreatedChannels() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    context.registerChannel("inputChannel", inputChannel);
    context.registerChannel("outputChannel", outputChannel);
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    postProcessor.postProcessAfterInitialization(new SimpleAnnotatedEndpointImplementation(), "impl");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("ABC"));
    Message<?> message = outputChannel.receive(1000);
    assertEquals("test-ABC", message.getPayload());
    context.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 19 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext in project spring-integration by spring-projects.

the class ApplicationContextMessageBusTests method exactlyOneConsumerReceivesPointToPointMessage.

@Test
public void exactlyOneConsumerReceivesPointToPointMessage() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    QueueChannel inputChannel = new QueueChannel();
    QueueChannel outputChannel1 = new QueueChannel();
    QueueChannel outputChannel2 = new QueueChannel();
    AbstractReplyProducingMessageHandler handler1 = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            return message;
        }
    };
    AbstractReplyProducingMessageHandler handler2 = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            return message;
        }
    };
    context.registerChannel("input", inputChannel);
    context.registerChannel("output1", outputChannel1);
    context.registerChannel("output2", outputChannel2);
    handler1.setOutputChannel(outputChannel1);
    handler2.setOutputChannel(outputChannel2);
    PollingConsumer endpoint1 = new PollingConsumer(inputChannel, handler1);
    endpoint1.setBeanFactory(mock(BeanFactory.class));
    PollingConsumer endpoint2 = new PollingConsumer(inputChannel, handler2);
    endpoint2.setBeanFactory(mock(BeanFactory.class));
    context.registerEndpoint("testEndpoint1", endpoint1);
    context.registerEndpoint("testEndpoint2", endpoint2);
    context.refresh();
    inputChannel.send(new GenericMessage<String>("testing"));
    Message<?> message1 = outputChannel1.receive(10000);
    Message<?> message2 = outputChannel2.receive(0);
    context.stop();
    assertTrue("exactly one message should be null", message1 == null ^ message2 == null);
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 20 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext in project spring-integration by spring-projects.

the class ApplicationContextMessageBusTests method endpointRegistrationWithInputChannelReference.

@Test
public void endpointRegistrationWithInputChannelReference() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    QueueChannel sourceChannel = new QueueChannel();
    QueueChannel targetChannel = new QueueChannel();
    context.registerChannel("sourceChannel", sourceChannel);
    context.registerChannel("targetChannel", targetChannel);
    Message<String> message = MessageBuilder.withPayload("test").setReplyChannelName("targetChannel").build();
    sourceChannel.send(message);
    AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {

        @Override
        public Object handleRequestMessage(Message<?> message) {
            return message;
        }
    };
    handler.setBeanFactory(context);
    handler.afterPropertiesSet();
    PollingConsumer endpoint = new PollingConsumer(sourceChannel, handler);
    endpoint.setBeanFactory(mock(BeanFactory.class));
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    Message<?> result = targetChannel.receive(10000);
    assertEquals("test", result.getPayload());
    context.stop();
}
Also used : PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) BeanFactory(org.springframework.beans.factory.BeanFactory) AbstractReplyProducingMessageHandler(org.springframework.integration.handler.AbstractReplyProducingMessageHandler) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Aggregations

TestApplicationContext (org.springframework.integration.test.util.TestUtils.TestApplicationContext)25 Test (org.junit.Test)24 QueueChannel (org.springframework.integration.channel.QueueChannel)17 DirectChannel (org.springframework.integration.channel.DirectChannel)14 GenericMessage (org.springframework.messaging.support.GenericMessage)8 CountDownLatch (java.util.concurrent.CountDownLatch)7 BeanFactory (org.springframework.beans.factory.BeanFactory)6 Message (org.springframework.messaging.Message)6 ErrorMessage (org.springframework.messaging.support.ErrorMessage)5 PollingConsumer (org.springframework.integration.endpoint.PollingConsumer)4 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)4 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)3 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)3 PollerMetadata (org.springframework.integration.scheduling.PollerMetadata)3 TestUtils (org.springframework.integration.test.util.TestUtils)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2