use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class ControlBusTests method testRouterMappings.
@Test
public void testRouterMappings() {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.setReceiveTimeout(1000);
messagingTemplate.convertAndSend(input, "@'router.handler'.getChannelMappings()");
Message<?> result = this.output.receive(0);
assertNotNull(result);
Map<?, ?> mappings = (Map<?, ?>) result.getPayload();
assertEquals("bar", mappings.get("foo"));
assertEquals("qux", mappings.get("baz"));
messagingTemplate.convertAndSend(input, "@'router.handler'.replaceChannelMappings('foo=qux \n baz=bar')");
messagingTemplate.convertAndSend(input, "@'router.handler'.getChannelMappings()");
result = this.output.receive(0);
assertNotNull(result);
mappings = (Map<?, ?>) result.getPayload();
assertEquals("bar", mappings.get("baz"));
assertEquals("qux", mappings.get("foo"));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class HeaderChannelRegistryTests method testReplaceError.
/**
* MessagingTemplate sets the errorChannel to the replyChannel so it gets any async
* exceptions via the default {@link MessagePublishingErrorHandler}.
*/
@Test
public void testReplaceError() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputPolled);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("bar"));
assertNotNull(reply);
assertTrue(reply instanceof ErrorMessage);
assertNotNull(((ErrorMessage) reply).getOriginalMessage());
assertThat(reply.getPayload(), not(instanceOf(MessagingExceptionWrapper.class)));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class HeaderChannelRegistryTests method testReplace.
@Test
public void testReplace() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.input);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("foo"));
assertNotNull(reply);
assertEquals("echo:foo", reply.getPayload());
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(TestUtils.getPropertyValue(registry, "channels", Map.class).get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(), lessThan(61000L));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class HeaderChannelRegistryTests method testReplaceTtl.
@Test
public void testReplaceTtl() {
MessagingTemplate template = new MessagingTemplate();
template.setDefaultDestination(this.inputTtl);
Message<?> reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
assertNotNull(reply);
assertEquals("echo:ttl", reply.getPayload());
String stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
assertThat(TestUtils.getPropertyValue(TestUtils.getPropertyValue(registry, "channels", Map.class).get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(), greaterThan(100000L));
}
use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.
the class NestedAggregationTests method sendAndReceiveMessage.
private List<String> sendAndReceiveMessage(DirectChannel channel, int timeout, Message<?> input) {
MessagingTemplate messagingTemplate = new MessagingTemplate();
messagingTemplate.setReceiveTimeout(timeout);
@SuppressWarnings("unchecked") Message<List<String>> message = (Message<List<String>>) messagingTemplate.sendAndReceive(channel, input);
return message == null ? null : message.getPayload();
}
Aggregations