Search in sources :

Example 11 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testOneWay.

@Test
public void testOneWay() {
    TestService service = (TestService) context.getBean("oneWay");
    service.oneWay("foo");
    PollableChannel channel = (PollableChannel) context.getBean("requestChannel");
    Message<?> result = channel.receive(10000);
    assertEquals("foo", result.getPayload());
}
Also used : TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 12 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncGateway.

@Test
public void testAsyncGateway() throws Exception {
    PollableChannel requestChannel = (PollableChannel) context.getBean("requestChannel");
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("async", TestService.class);
    Future<Message<?>> result = service.async("foo");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("foo", reply.getPayload());
    assertEquals("testExecutor", reply.getHeaders().get("executor"));
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&async"), "asyncExecutor"));
}
Also used : MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 13 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testCustomCompletableNoAsyncMessage.

@Test
public void testCustomCompletableNoAsyncMessage() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("completableNoAsync", TestService.class);
    MyCompletableMessageFuture result = service.customCompletableReturnsMessage("flowCustomCompletableM");
    Message<?> reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("flowCustomCompletableM", reply.getPayload());
    assertEquals(Thread.currentThread(), thread.get());
    assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) MyCompletableMessageFuture(org.springframework.integration.gateway.TestService.MyCompletableMessageFuture) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Example 14 with TestService

use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.

the class GatewayParserTests method testAsyncCompletable.

@Test
public void testAsyncCompletable() throws Exception {
    QueueChannel requestChannel = (QueueChannel) context.getBean("requestChannel");
    final AtomicReference<Thread> thread = new AtomicReference<>();
    requestChannel.addInterceptor(new ChannelInterceptorAdapter() {

        @Override
        public Message<?> preSend(Message<?> message, MessageChannel channel) {
            thread.set(Thread.currentThread());
            return super.preSend(message, channel);
        }
    });
    MessageChannel replyChannel = (MessageChannel) context.getBean("replyChannel");
    this.startResponder(requestChannel, replyChannel);
    TestService service = context.getBean("asyncCompletable", TestService.class);
    CompletableFuture<String> result = service.completable("foo").thenApply(String::toUpperCase);
    String reply = result.get(10, TimeUnit.SECONDS);
    assertEquals("FOO", reply);
    assertThat(thread.get().getName(), startsWith("testExec-"));
    assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "asyncExecutor"));
}
Also used : ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageChannel(org.springframework.messaging.MessageChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) TestService(org.springframework.integration.gateway.TestService) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 TestService (org.springframework.integration.gateway.TestService)14 MessageChannel (org.springframework.messaging.MessageChannel)11 Message (org.springframework.messaging.Message)10 GenericMessage (org.springframework.messaging.support.GenericMessage)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)7 QueueChannel (org.springframework.integration.channel.QueueChannel)7 PollableChannel (org.springframework.messaging.PollableChannel)7 ChannelInterceptorAdapter (org.springframework.messaging.support.ChannelInterceptorAdapter)7 MyCompletableFuture (org.springframework.integration.gateway.TestService.MyCompletableFuture)2 Log (org.apache.commons.logging.Log)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 GatewayMethodMetadata (org.springframework.integration.gateway.GatewayMethodMetadata)1 GatewayProxyFactoryBean (org.springframework.integration.gateway.GatewayProxyFactoryBean)1 MyCompletableMessageFuture (org.springframework.integration.gateway.TestService.MyCompletableMessageFuture)1