Search in sources :

Example 21 with DirectChannel

use of org.springframework.integration.channel.DirectChannel in project spring-integration by spring-projects.

the class MessagingAnnotationPostProcessorTests method testProxiedMessageEndpointAnnotation.

@Test
public void testProxiedMessageEndpointAnnotation() {
    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 AnnotatedTestService());
    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)

Example 22 with DirectChannel

use of org.springframework.integration.channel.DirectChannel 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 23 with DirectChannel

use of org.springframework.integration.channel.DirectChannel 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 24 with DirectChannel

use of org.springframework.integration.channel.DirectChannel 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 25 with DirectChannel

use of org.springframework.integration.channel.DirectChannel 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)

Aggregations

DirectChannel (org.springframework.integration.channel.DirectChannel)207 Test (org.junit.Test)179 Message (org.springframework.messaging.Message)62 MessageChannel (org.springframework.messaging.MessageChannel)60 QueueChannel (org.springframework.integration.channel.QueueChannel)58 BeanFactory (org.springframework.beans.factory.BeanFactory)45 GenericMessage (org.springframework.messaging.support.GenericMessage)37 MessageHandler (org.springframework.messaging.MessageHandler)32 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)28 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)26 CountDownLatch (java.util.concurrent.CountDownLatch)25 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)23 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)22 HashMap (java.util.HashMap)20 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)19 MessagingException (org.springframework.messaging.MessagingException)18 SubscribableChannel (org.springframework.messaging.SubscribableChannel)16 Properties (java.util.Properties)15 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)15 Expression (org.springframework.expression.Expression)14