use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.
the class GatewayParserTests method testSolicitResponse.
@Test
public void testSolicitResponse() {
PollableChannel channel = (PollableChannel) context.getBean("replyChannel");
channel.send(new GenericMessage<String>("foo"));
TestService service = (TestService) context.getBean("solicitResponse");
String result = service.solicitResponse();
assertEquals("foo", result);
}
use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.
the class GatewayParserTests method testAsyncCompletableNoAsync.
@Test
public void testAsyncCompletableNoAsync() 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);
CompletableFuture<String> result = service.completable("flowCompletable");
String reply = result.get(10, TimeUnit.SECONDS);
assertEquals("SYNC_COMPLETABLE", reply);
assertEquals(Thread.currentThread(), thread.get());
assertNull(TestUtils.getPropertyValue(context.getBean("&completableNoAsync"), "asyncExecutor"));
}
use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.
the class GatewayParserTests method testOneWayOverride.
@Test
public void testOneWayOverride() {
TestService service = (TestService) context.getBean("methodOverride");
service.oneWay("foo");
PollableChannel channel = (PollableChannel) context.getBean("otherRequestChannel");
Message<?> result = channel.receive(10000);
assertNotNull(result);
assertEquals("fiz", result.getPayload());
assertEquals("bar", result.getHeaders().get("foo"));
assertEquals("qux", result.getHeaders().get("baz"));
GatewayProxyFactoryBean fb = context.getBean("&methodOverride", GatewayProxyFactoryBean.class);
assertEquals(1000L, TestUtils.getPropertyValue(fb, "defaultRequestTimeout", Expression.class).getValue());
assertEquals(2000L, TestUtils.getPropertyValue(fb, "defaultReplyTimeout", Expression.class).getValue());
Map<?, ?> methods = TestUtils.getPropertyValue(fb, "methodMetadataMap", Map.class);
GatewayMethodMetadata meta = (GatewayMethodMetadata) methods.get("oneWay");
assertNotNull(meta);
assertEquals("456", meta.getRequestTimeout());
assertEquals("123", meta.getReplyTimeout());
assertEquals("foo", meta.getReplyChannelName());
meta = (GatewayMethodMetadata) methods.get("oneWayWithTimeouts");
assertNotNull(meta);
assertEquals("#args[1]", meta.getRequestTimeout());
assertEquals("#args[2]", meta.getReplyTimeout());
service.oneWayWithTimeouts("foo", 100L, 200L);
result = channel.receive(10000);
assertNotNull(result);
}
use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.
the class GatewayParserTests method testAsyncCompletableMessage.
@Test
public void testAsyncCompletableMessage() 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<Message<?>> result = service.completableReturnsMessage("foo");
Message<?> reply = result.get(10, TimeUnit.SECONDS);
assertEquals("foo", reply.getPayload());
assertThat(thread.get().getName(), startsWith("testExec-"));
assertNotNull(TestUtils.getPropertyValue(context.getBean("&asyncCompletable"), "asyncExecutor"));
}
use of org.springframework.integration.gateway.TestService in project spring-integration by spring-projects.
the class GatewayParserTests method testCustomCompletableNoAsyncAttemptAsync.
@Test
public void testCustomCompletableNoAsyncAttemptAsync() throws Exception {
Object gateway = context.getBean("&customCompletableAttemptAsync");
Log logger = spy(TestUtils.getPropertyValue(gateway, "logger", Log.class));
when(logger.isDebugEnabled()).thenReturn(true);
new DirectFieldAccessor(gateway).setPropertyValue("logger", logger);
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("customCompletableAttemptAsync", TestService.class);
MyCompletableFuture result = service.customCompletable("flowCustomCompletable");
String reply = result.get(10, TimeUnit.SECONDS);
assertEquals("SYNC_CUSTOM_COMPLETABLE", reply);
assertEquals(Thread.currentThread(), thread.get());
assertNotNull(TestUtils.getPropertyValue(gateway, "asyncExecutor"));
verify(logger).debug("AsyncTaskExecutor submit*() return types are incompatible with the method return type; " + "running on calling thread; the downstream flow must return the required Future: " + "MyCompletableFuture");
}
Aggregations