Search in sources :

Example 11 with DirectChannel

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

the class GatewayInterfaceTests method testWithServiceSuperclassAnnotatedMethodOverridePE.

@Test
public void testWithServiceSuperclassAnnotatedMethodOverridePE() throws Exception {
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests2-context.xml", this.getClass());
    DirectChannel channel = ac.getBean("requestChannelFoo", DirectChannel.class);
    final Method fooMethod = Foo.class.getMethod("foo", String.class);
    final AtomicBoolean called = new AtomicBoolean();
    MessageHandler handler = message -> {
        assertThat((String) message.getHeaders().get("name"), equalTo("foo"));
        assertThat((String) message.getHeaders().get("string"), equalTo("public abstract void org.springframework.integration.gateway.GatewayInterfaceTests$Foo.foo(java.lang.String)"));
        assertThat((Method) message.getHeaders().get("object"), equalTo(fooMethod));
        assertThat((String) message.getPayload(), equalTo("foo"));
        called.set(true);
    };
    channel.subscribe(handler);
    Bar bar = ac.getBean(Bar.class);
    bar.foo("hello");
    assertTrue(called.get());
    ac.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) DirtiesContext(org.springframework.test.annotation.DirtiesContext) IntegrationComponentScan(org.springframework.integration.annotation.IntegrationComponentScan) AsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor) LiteralExpression(org.springframework.expression.common.LiteralExpression) Autowired(org.springframework.beans.factory.annotation.Autowired) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Map(java.util.Map) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) AnnotationConstants(org.springframework.integration.annotation.AnnotationConstants) PollableChannel(org.springframework.messaging.PollableChannel) BridgeTo(org.springframework.integration.annotation.BridgeTo) Method(java.lang.reflect.Method) AsyncResult(org.springframework.scheduling.annotation.AsyncResult) Header(org.springframework.messaging.handler.annotation.Header) Collection(java.util.Collection) EnableIntegration(org.springframework.integration.config.EnableIntegration) MessageChannel(org.springframework.messaging.MessageChannel) Matchers.startsWith(org.hamcrest.Matchers.startsWith) ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Configuration(org.springframework.context.annotation.Configuration) ServiceActivator(org.springframework.integration.annotation.ServiceActivator) BridgeHandler(org.springframework.integration.handler.BridgeHandler) CountDownLatch(java.util.concurrent.CountDownLatch) IntegrationProperties(org.springframework.integration.context.IntegrationProperties) MessageHandler(org.springframework.messaging.MessageHandler) Assert.assertFalse(org.junit.Assert.assertFalse) Matchers.equalTo(org.hamcrest.Matchers.equalTo) Payload(org.springframework.messaging.handler.annotation.Payload) DirectChannel(org.springframework.integration.channel.DirectChannel) Mockito.mock(org.mockito.Mockito.mock) MessagingException(org.springframework.messaging.MessagingException) ListenableFuture(org.springframework.util.concurrent.ListenableFuture) RunWith(org.junit.runner.RunWith) GatewayHeader(org.springframework.integration.annotation.GatewayHeader) MessagingGateway(org.springframework.integration.annotation.MessagingGateway) SubscribableChannel(org.springframework.messaging.SubscribableChannel) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TestUtils(org.springframework.integration.test.util.TestUtils) AtomicReference(java.util.concurrent.atomic.AtomicReference) ListenableFutureCallback(org.springframework.util.concurrent.ListenableFutureCallback) Retention(java.lang.annotation.Retention) Assert.assertSame(org.junit.Assert.assertSame) MessageBuilder(org.springframework.integration.support.MessageBuilder) ArgumentCaptor(org.mockito.ArgumentCaptor) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Nullable(org.springframework.lang.Nullable) Message(org.springframework.messaging.Message) FilterType(org.springframework.context.annotation.FilterType) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) Properties(java.util.Properties) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Mockito.times(org.mockito.Mockito.times) Target(java.lang.annotation.Target) Test(org.junit.Test) ElementType(java.lang.annotation.ElementType) Gateway(org.springframework.integration.annotation.Gateway) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) ComponentScan(org.springframework.context.annotation.ComponentScan) IntegrationContextUtils(org.springframework.integration.context.IntegrationContextUtils) Mockito.verify(org.mockito.Mockito.verify) TimeUnit(java.util.concurrent.TimeUnit) Mockito(org.mockito.Mockito) Component(org.springframework.stereotype.Component) Assert.assertNull(org.junit.Assert.assertNull) ContextConfiguration(org.springframework.test.context.ContextConfiguration) Expression(org.springframework.expression.Expression) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) Bean(org.springframework.context.annotation.Bean) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RetentionPolicy(java.lang.annotation.RetentionPolicy) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) MessageHandler(org.springframework.messaging.MessageHandler) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 12 with DirectChannel

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

the class GatewayInterfaceTests method testWithServiceAnnotatedMethod.

@Test
public void testWithServiceAnnotatedMethod() {
    ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
    DirectChannel channel = ac.getBean("requestChannelBar", DirectChannel.class);
    MessageHandler handler = mock(MessageHandler.class);
    channel.subscribe(handler);
    Bar bar = ac.getBean(Bar.class);
    bar.bar("hello");
    verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
    ac.close();
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) MessageHandler(org.springframework.messaging.MessageHandler) Message(org.springframework.messaging.Message) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 13 with DirectChannel

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

the class AsyncMessagingTemplateTests method asyncConvertSendAndReceiveWithDefaultChannel.

@Test
public void asyncConvertSendAndReceiveWithDefaultChannel() throws Exception {
    DirectChannel channel = new DirectChannel();
    channel.subscribe(new EchoHandler(200));
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setDefaultDestination(channel);
    long start = System.currentTimeMillis();
    Future<String> result = template.asyncConvertSendAndReceive("test");
    assertNotNull(result.get());
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
    assertEquals("TEST", result.get());
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 14 with DirectChannel

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

the class AsyncMessagingTemplateTests method asyncConvertSendAndReceiveWithExplicitChannelAndMessagePostProcessor.

@Test
public void asyncConvertSendAndReceiveWithExplicitChannelAndMessagePostProcessor() throws Exception {
    DirectChannel channel = new DirectChannel();
    channel.subscribe(new EchoHandler(200));
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    long start = System.currentTimeMillis();
    Future<String> result = template.asyncConvertSendAndReceive(channel, "test", new TestMessagePostProcessor());
    assertNotNull(result.get());
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
    assertEquals("TEST-bar", result.get());
}
Also used : DirectChannel(org.springframework.integration.channel.DirectChannel) Test(org.junit.Test)

Example 15 with DirectChannel

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

the class AsyncMessagingTemplateTests method asyncConvertSendAndReceiveWithResolvedChannelAndMessagePostProcessor.

@Test
public void asyncConvertSendAndReceiveWithResolvedChannelAndMessagePostProcessor() throws Exception {
    StaticApplicationContext context = new StaticApplicationContext();
    context.registerSingleton("testChannel", DirectChannel.class);
    context.refresh();
    DirectChannel channel = context.getBean("testChannel", DirectChannel.class);
    channel.subscribe(new EchoHandler(200));
    AsyncMessagingTemplate template = new AsyncMessagingTemplate();
    template.setBeanFactory(context);
    long start = System.currentTimeMillis();
    Future<String> result = template.asyncConvertSendAndReceive("testChannel", "test", new TestMessagePostProcessor());
    assertNotNull(result.get());
    long elapsed = System.currentTimeMillis() - start;
    assertTrue(elapsed >= 200 - safety);
    assertEquals("TEST-bar", result.get());
}
Also used : StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) 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