Search in sources :

Example 16 with MessagingTemplate

use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.

the class ControlBusRecipientListRouterTests method testAddRecipientWithNullExpression.

@Test
public void testAddRecipientWithNullExpression() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel3')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel3 = (PollableChannel) context.getBean("channel3");
    assertTrue(chanel3.receive(0).getPayload().equals(1));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 17 with MessagingTemplate

use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.

the class ControlBusRecipientListRouterTests method testGetRecipients.

@Test
@SuppressWarnings("unchecked")
public void testGetRecipients() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.getRecipients()");
    PollableChannel channel1 = (PollableChannel) context.getBean("channel1");
    Message<?> result = this.output.receive(0);
    Collection<Recipient> mappings = (Collection<Recipient>) result.getPayload();
    assertEquals(channel1, mappings.iterator().next().getChannel());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) PollableChannel(org.springframework.messaging.PollableChannel) Collection(java.util.Collection) Recipient(org.springframework.integration.router.RecipientListRouter.Recipient) Test(org.junit.Test)

Example 18 with MessagingTemplate

use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.

the class ControlBusRecipientListRouterTests method testRemoveRecipient.

@Test
public void testRemoveRecipient() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel4')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.removeRecipient('channel4')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
    PollableChannel chanel4 = (PollableChannel) context.getBean("channel4");
    assertTrue(chanel1.receive(0).getPayload().equals(1));
    assertNull(chanel4.receive(0));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 19 with MessagingTemplate

use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.

the class ControlBusRecipientListRouterTests method testReplaceRecipients.

@Test
public void testReplaceRecipients() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.replaceRecipients('channel7=true')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel7 = (PollableChannel) context.getBean("channel7");
    assertTrue(chanel7.receive(0).getPayload().equals(1));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 20 with MessagingTemplate

use of org.springframework.integration.core.MessagingTemplate in project spring-integration by spring-projects.

the class HeaderChannelRegistryTests method testReplaceCustomTtl.

@Test
public void testReplaceCustomTtl() {
    MessagingTemplate template = new MessagingTemplate();
    template.setDefaultDestination(this.inputCustomTtl);
    Message<String> requestMessage = MessageBuilder.withPayload("ttl").setHeader("channelTTL", 180000).build();
    Message<?> reply = template.sendAndReceive(requestMessage);
    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(), allOf(greaterThan(160000L), lessThan(181000L)));
    // Now for Elvis...
    reply = template.sendAndReceive(new GenericMessage<String>("ttl"));
    assertNotNull(reply);
    assertEquals("echo:ttl", reply.getPayload());
    stringReplyChannel = reply.getHeaders().get("stringReplyChannel", String.class);
    assertThat(TestUtils.getPropertyValue(TestUtils.getPropertyValue(registry, "channels", Map.class).get(stringReplyChannel), "expireAt", Long.class) - System.currentTimeMillis(), greaterThan(220000L));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) GenericMessage(org.springframework.messaging.support.GenericMessage) Test(org.junit.Test)

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