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)));
}
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());
}
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));
}
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);
}
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"));
}
Aggregations