Search in sources :

Example 41 with MessagingTemplate

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"));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Map(java.util.Map) Test(org.junit.Test)

Example 42 with MessagingTemplate

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)));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) ErrorMessage(org.springframework.messaging.support.ErrorMessage) Test(org.junit.Test)

Example 43 with MessagingTemplate

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));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Test(org.junit.Test)

Example 44 with MessagingTemplate

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));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Test(org.junit.Test)

Example 45 with MessagingTemplate

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();
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) List(java.util.List)

Aggregations

MessagingTemplate (org.springframework.integration.core.MessagingTemplate)63 Test (org.junit.Test)58 MessageChannel (org.springframework.messaging.MessageChannel)22 PollableChannel (org.springframework.messaging.PollableChannel)12 GenericMessage (org.springframework.messaging.support.GenericMessage)11 IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 Message (org.springframework.messaging.Message)6 File (java.io.File)5 Map (java.util.Map)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Assert.assertThat (org.junit.Assert.assertThat)4 Assert.assertTrue (org.junit.Assert.assertTrue)4 Assert.fail (org.junit.Assert.fail)4 MessageHandler (org.springframework.messaging.MessageHandler)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)3 Assert.assertEquals (org.junit.Assert.assertEquals)3