Search in sources :

Example 26 with MessagingTemplate

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

the class JdbcPollingChannelAdapterParserTests method setupMessagingTemplate.

protected void setupMessagingTemplate() {
    PollableChannel pollableChannel = this.appCtx.getBean("target", PollableChannel.class);
    this.messagingTemplate = new MessagingTemplate();
    this.messagingTemplate.setDefaultDestination(pollableChannel);
    this.messagingTemplate.setReceiveTimeout(10000);
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) PollableChannel(org.springframework.messaging.PollableChannel)

Example 27 with MessagingTemplate

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

the class JdbcOutboundGatewayParserTests method testReplyTimeoutIsSet.

@Test
public void testReplyTimeoutIsSet() {
    setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
    PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
    DirectFieldAccessor accessor = new DirectFieldAccessor(outboundGateway);
    Object source = accessor.getPropertyValue("handler");
    accessor = new DirectFieldAccessor(source);
    source = accessor.getPropertyValue("messagingTemplate");
    MessagingTemplate messagingTemplate = (MessagingTemplate) source;
    accessor = new DirectFieldAccessor(messagingTemplate);
    Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
    assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout);
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) PollingConsumer(org.springframework.integration.endpoint.PollingConsumer) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 28 with MessagingTemplate

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

the class MailHeaderEnricherTests method literalValues.

@Test
public void literalValues() {
    MessagingTemplate template = new MessagingTemplate();
    template.setDefaultDestination(literalValuesInput);
    Message<?> result = template.sendAndReceive(new GenericMessage<String>("test"));
    Map<String, Object> headers = result.getHeaders();
    assertEquals("test.to", headers.get(MailHeaders.TO));
    assertEquals("test.cc", headers.get(MailHeaders.CC));
    assertEquals("test.bcc", headers.get(MailHeaders.BCC));
    assertEquals("test.from", headers.get(MailHeaders.FROM));
    assertEquals("test.reply-to", headers.get(MailHeaders.REPLY_TO));
    assertEquals("test.subject", headers.get(MailHeaders.SUBJECT));
    assertEquals("foo.txt", headers.get(MailHeaders.ATTACHMENT_FILENAME));
    assertEquals("1", headers.get(MailHeaders.MULTIPART_MODE));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Test(org.junit.Test)

Example 29 with MessagingTemplate

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

the class MailHeaderEnricherTests method expressions.

@Test
public void expressions() {
    MessagingTemplate template = new MessagingTemplate();
    template.setDefaultDestination(expressionsInput);
    Message<?> result = template.sendAndReceive(new GenericMessage<String>("foo"));
    Map<String, Object> headers = result.getHeaders();
    assertEquals("foo.to", headers.get(MailHeaders.TO));
    assertEquals("foo.cc", headers.get(MailHeaders.CC));
    assertEquals("foo.bcc", headers.get(MailHeaders.BCC));
    assertEquals("foo.from", headers.get(MailHeaders.FROM));
    assertEquals("foo.reply-to", headers.get(MailHeaders.REPLY_TO));
    assertEquals("foo.subject", headers.get(MailHeaders.SUBJECT));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) Test(org.junit.Test)

Example 30 with MessagingTemplate

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

the class FileOutboundGatewayParserTests method gatewayWithReplaceMode.

/**
 * Test uses the Replace Mode of the File OutboundGateway. When persisting
 * a payload using the File Outbound Gateway and the mode is set to REPLACE,
 * then the destination file will be created and written if it does not yet exist.
 * If the destination file exists, it will be replaced.
 *
 * The reply message will contain the concatenated destination
 * {@link File} as its payload.
 */
@Test
public void gatewayWithReplaceMode() throws Exception {
    assertFalse(TestUtils.getPropertyValue(this.gatewayWithReplaceModeHandler, "requiresReply", Boolean.class));
    final MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.setDefaultDestination(this.gatewayWithReplaceModeChannel);
    String expectedFileContent = "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)

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