Search in sources :

Example 36 with MessagingTemplate

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

the class HeaderEnricherTests method correlationIdRef.

@Test
public void correlationIdRef() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("correlationIdRefInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(123, new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 37 with MessagingTemplate

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

the class HeaderEnricherTests method priorityExpression.

@Test
public void priorityExpression() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("priorityExpressionInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<Map<String, String>>(Collections.singletonMap("priority", "-10")));
    assertNotNull(result);
    assertEquals(new Integer(-10), new IntegrationMessageHeaderAccessor(result).getPriority());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) Map(java.util.Map) Test(org.junit.Test)

Example 38 with MessagingTemplate

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

the class ControlBusRecipientListRouterTests method testRemoveRecipientWithExpression.

@Test
public void testRemoveRecipientWithExpression() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel1','true')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel5','true')");
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.removeRecipient('channel5','true')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel1 = (PollableChannel) context.getBean("channel1");
    PollableChannel chanel5 = (PollableChannel) context.getBean("channel5");
    assertTrue(chanel1.receive(0).getPayload().equals(1));
    assertNull(chanel5.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 39 with MessagingTemplate

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

the class ControlBusRecipientListRouterTests method testSetRecipients.

@Test
public void testSetRecipients() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    Map<String, String> map = new HashMap<String, String>();
    map.put("channel6", "true");
    Message<?> message = MessageBuilder.withPayload("@'simpleRouter.handler'.setRecipientMappings(headers.recipientMap)").setHeader("recipientMap", map).build();
    this.input.send(message);
    message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel6 = (PollableChannel) context.getBean("channel6");
    assertTrue(chanel6.receive(0).getPayload().equals(1));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) HashMap(java.util.HashMap) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test)

Example 40 with MessagingTemplate

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

the class ControlBusRecipientListRouterTests method testAddRecipient.

@Test
public void testAddRecipient() {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setReceiveTimeout(1000);
    messagingTemplate.convertAndSend(input, "@'simpleRouter.handler'.addRecipient('channel2','true')");
    Message<?> message = new GenericMessage<Integer>(1);
    channel.send(message);
    PollableChannel chanel2 = (PollableChannel) context.getBean("channel2");
    assertTrue(chanel2.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)

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