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();
}
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();
}
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());
}
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());
}
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());
}
Aggregations