Search in sources :

Example 31 with MessagingTemplate

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

the class FileOutboundGatewayParserTests method gatewayWithAppendMode.

/**
 * Test uses the Append Mode of the File Outbound Gateway. When persisting
 * a payload using the File Outbound Gateway and the mode is set to APPEND,
 * then the destination file will be created and written, if it does not yet
 * exist. BUT if it exists it will be appended to the existing file.
 *
 * The reply message will contain the concatenated destination
 * {@link File} as its payload.
 */
@Test
public void gatewayWithAppendMode() throws Exception {
    final MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setDefaultDestination(this.gatewayWithAppendModeChannel);
    String expectedFileContent = "Initial File Content:String content:";
    File testFile = new File("test/fileToAppend.txt");
    if (testFile.exists()) {
        testFile.delete();
    }
    messagingTemplate.sendAndReceive(new GenericMessage<String>("Initial File Content:"));
    Message<?> m = messagingTemplate.sendAndReceive(new GenericMessage<String>("String content:"));
    String actualFileContent = new String(FileCopyUtils.copyToByteArray(testFile));
    assertEquals(expectedFileContent, actualFileContent);
    assertTrue(m.getPayload() instanceof File);
    File replyPayload = (File) m.getPayload();
    assertEquals(expectedFileContent, new String(FileCopyUtils.copyToByteArray(replyPayload)));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) File(java.io.File) Test(org.junit.Test)

Example 32 with MessagingTemplate

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

the class HeaderEnricherOverwriteTests method priorityExplicitOverwriteTrue.

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

Example 33 with MessagingTemplate

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

the class HeaderEnricherTests method testRoutingSlip.

@Test
public void testRoutingSlip() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("routingSlipInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    Object routingSlip = new IntegrationMessageHeaderAccessor(result).getHeader(IntegrationMessageHeaderAccessor.ROUTING_SLIP);
    assertNotNull(routingSlip);
    assertThat(routingSlip, instanceOf(Map.class));
    @SuppressWarnings("unchecked") List<Object> routingSlipPath = (List<Object>) ((Map<?, ?>) routingSlip).keySet().iterator().next();
    assertEquals("fooChannel", routingSlipPath.get(0));
    assertThat(routingSlipPath.get(1), instanceOf(ExpressionEvaluatingRoutingSlipRouteStrategy.class));
    assertEquals("bazRoutingSlip", routingSlipPath.get(2));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageChannel(org.springframework.messaging.MessageChannel) ExpressionEvaluatingRoutingSlipRouteStrategy(org.springframework.integration.routingslip.ExpressionEvaluatingRoutingSlipRouteStrategy) List(java.util.List) Map(java.util.Map) Test(org.junit.Test)

Example 34 with MessagingTemplate

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

the class HeaderEnricherTests method correlationIdValueWithType.

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

Example 35 with MessagingTemplate

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

the class HeaderEnricherTests method innerBeanWithMethod.

@Test
public void innerBeanWithMethod() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("innerBeanWithMethod", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(String.class, result.getHeaders().get("testHeader").getClass());
    assertEquals("testBeanForInnerBeanWithMethod", result.getHeaders().get("testHeader"));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MessageChannel(org.springframework.messaging.MessageChannel) 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