Search in sources :

Example 6 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method testTransformer.

@Test
public void testTransformer() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    context.registerChannel("inputChannel", inputChannel);
    QueueChannel outputChannel = new QueueChannel();
    context.registerChannel("outputChannel", outputChannel);
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    TransformerAnnotationTestBean testBean = new TransformerAnnotationTestBean();
    postProcessor.postProcessAfterInitialization(testBean, "testBean");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("foo"));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("FOO", reply.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 7 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInherited.

@Test
public void testMessageEndpointAnnotationInherited() {
    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 SimpleAnnotatedEndpointSubclass(), "subclass");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("world"));
    Message<?> message = outputChannel.receive(1000);
    assertEquals("hello world", 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 8 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method testChannelResolution.

@Test
public void testChannelResolution() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel();
    DirectChannel eventBus = new DirectChannel();
    context.registerChannel("inputChannel", inputChannel);
    context.registerChannel("outputChannel", outputChannel);
    context.registerChannel("eventBus", eventBus);
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    ServiceActivatorAnnotatedBean bean = new ServiceActivatorAnnotatedBean();
    postProcessor.postProcessAfterInitialization(bean, "testBean");
    context.refresh();
    Message<?> message = MessageBuilder.withPayload("test").setReplyChannelName("outputChannel").build();
    inputChannel.send(message);
    Message<?> reply = outputChannel.receive(0);
    assertNotNull(reply);
    eventBus.send(new GenericMessage<String>("foo"));
    assertTrue(bean.getInvoked());
    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 9 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method serviceActivatorAnnotation.

@Test
public void serviceActivatorAnnotation() {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    DirectChannel inputChannel = new DirectChannel();
    context.registerChannel("inputChannel", inputChannel);
    context.refresh();
    MessagingAnnotationPostProcessor postProcessor = new MessagingAnnotationPostProcessor();
    postProcessor.setBeanFactory(context.getBeanFactory());
    postProcessor.afterPropertiesSet();
    ServiceActivatorAnnotatedBean bean = new ServiceActivatorAnnotatedBean();
    postProcessor.postProcessAfterInitialization(bean, "testBean");
    assertTrue(context.containsBean("testBean.test.serviceActivator"));
    Object endpoint = context.getBean("testBean.test.serviceActivator");
    assertTrue(endpoint instanceof AbstractEndpoint);
}
Also used : AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) DirectChannel(org.springframework.integration.channel.DirectChannel) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 10 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedWithProxy.

@Test
public void testMessageEndpointAnnotationInheritedWithProxy() {
    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();
    ProxyFactory proxyFactory = new ProxyFactory(new SimpleAnnotatedEndpointSubclass());
    Object proxy = proxyFactory.getProxy();
    postProcessor.postProcessAfterInitialization(proxy, "proxy");
    context.refresh();
    inputChannel.send(new GenericMessage<String>("world"));
    Message<?> message = outputChannel.receive(1000);
    assertEquals("hello world", message.getPayload());
    context.stop();
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ProxyFactory(org.springframework.aop.framework.ProxyFactory) 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