Search in sources :

Example 1 with TestApplicationContext

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

the class MessagingGatewayTests method validateErrorChannelWithSuccessfulReply.

// should not fail but it does now
@Test
public void validateErrorChannelWithSuccessfulReply() {
    TestUtils.TestApplicationContext testApplicationContext = TestUtils.createTestApplicationContext();
    testApplicationContext.refresh();
    DirectChannel reqChannel = new DirectChannel();
    reqChannel.subscribe(message -> {
        throw new RuntimeException("ooops");
    });
    PublishSubscribeChannel errorChannel = new PublishSubscribeChannel();
    ServiceActivatingHandler handler = new ServiceActivatingHandler(new MyOneWayErrorService());
    handler.setBeanFactory(testApplicationContext);
    handler.afterPropertiesSet();
    errorChannel.subscribe(handler);
    this.messagingGateway = new MessagingGatewaySupport() {
    };
    this.messagingGateway.setRequestChannel(reqChannel);
    this.messagingGateway.setErrorChannel(errorChannel);
    this.messagingGateway.setReplyChannel(null);
    this.messagingGateway.setBeanFactory(mock(BeanFactory.class));
    this.messagingGateway.afterPropertiesSet();
    this.messagingGateway.start();
    this.messagingGateway.send("hello");
    testApplicationContext.close();
}
Also used : TestUtils(org.springframework.integration.test.util.TestUtils) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) PublishSubscribeChannel(org.springframework.integration.channel.PublishSubscribeChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 2 with TestApplicationContext

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

the class MessagingGatewayTests method initializeSample.

@Before
public void initializeSample() {
    this.messagingGateway = new MessagingGatewaySupport() {
    };
    this.messagingGateway.setRequestChannel(requestChannel);
    this.messagingGateway.setReplyChannel(replyChannel);
    TestApplicationContext applicationContext = TestUtils.createTestApplicationContext();
    this.messagingGateway.setBeanFactory(applicationContext);
    this.messagingGateway.setCountsEnabled(true);
    this.messagingGateway.afterPropertiesSet();
    this.messagingGateway.start();
    applicationContext.refresh();
    Mockito.when(this.messageMock.getHeaders()).thenReturn(new MessageHeaders(Collections.emptyMap()));
}
Also used : MessageHeaders(org.springframework.messaging.MessageHeaders) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Before(org.junit.Before)

Example 3 with TestApplicationContext

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

the class MethodInvokingMessageHandlerTests method subscription.

@Test
public void subscription() throws Exception {
    TestApplicationContext context = TestUtils.createTestApplicationContext();
    SynchronousQueue<String> queue = new SynchronousQueue<String>();
    TestBean testBean = new TestBean(queue);
    QueueChannel channel = new QueueChannel();
    context.registerChannel("channel", channel);
    Message<String> message = new GenericMessage<String>("testing");
    channel.send(message);
    assertNull(queue.poll());
    MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo");
    PollingConsumer endpoint = new PollingConsumer(channel, handler);
    endpoint.setTrigger(new PeriodicTrigger(10));
    context.registerEndpoint("testEndpoint", endpoint);
    context.refresh();
    String result = queue.poll(2000, TimeUnit.MILLISECONDS);
    assertNotNull(result);
    assertEquals("testing", result);
    context.stop();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MethodInvokingMessageHandler(org.springframework.integration.handler.MethodInvokingMessageHandler) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) QueueChannel(org.springframework.integration.channel.QueueChannel) SynchronousQueue(java.util.concurrent.SynchronousQueue) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Test(org.junit.Test)

Example 4 with TestApplicationContext

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

the class MessagingAnnotationPostProcessorTests method testMessageEndpointAnnotationInheritedFromInterfaceWithProxy.

@Test
public void testMessageEndpointAnnotationInheritedFromInterfaceWithProxy() {
    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 SimpleAnnotatedEndpointImplementation());
    Object proxy = proxyFactory.getProxy();
    postProcessor.postProcessAfterInitialization(proxy, "proxy");
    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) ProxyFactory(org.springframework.aop.framework.ProxyFactory) TestApplicationContext(org.springframework.integration.test.util.TestUtils.TestApplicationContext) Test(org.junit.Test)

Example 5 with TestApplicationContext

use of org.springframework.integration.test.util.TestUtils.TestApplicationContext 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)

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