Search in sources :

Example 11 with MessagingTemplate

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

the class HeaderEnricherTests method priority.

@Test
public void priority() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("priorityInput", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, 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 12 with MessagingTemplate

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

the class HeaderEnricherTests method refWithMethod.

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

Example 13 with MessagingTemplate

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

the class HeaderEnricherTests method ref.

@Test
public void ref() {
    MessagingTemplate template = new MessagingTemplate();
    MessageChannel channel = context.getBean("ref", MessageChannel.class);
    Message<?> result = template.sendAndReceive(channel, new GenericMessage<String>("test"));
    assertNotNull(result);
    assertEquals(TestBean.class, result.getHeaders().get("testHeader").getClass());
    TestBean testBeanForRef = context.getBean("testBean1", TestBean.class);
    assertSame(testBeanForRef, result.getHeaders().get("testHeader"));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test)

Example 14 with MessagingTemplate

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

the class BridgeParserTests method bridgeWithSendTimeout.

@Test
public void bridgeWithSendTimeout() {
    BridgeHandler handler = (BridgeHandler) new DirectFieldAccessor(bridgeWithSendTimeout).getPropertyValue("handler");
    MessagingTemplate template = (MessagingTemplate) new DirectFieldAccessor(handler).getPropertyValue("messagingTemplate");
    assertEquals(new Long(1234), new DirectFieldAccessor(template).getPropertyValue("sendTimeout"));
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) BridgeHandler(org.springframework.integration.handler.BridgeHandler) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 15 with MessagingTemplate

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

the class ControlBusTests method testControlHeaderChannelReaper.

@Test
public void testControlHeaderChannelReaper() throws InterruptedException {
    MessagingTemplate messagingTemplate = new MessagingTemplate();
    messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
    Message<?> result = this.output.receive(0);
    assertNotNull(result);
    // No channels in the registry
    assertEquals(0, result.getPayload());
    this.registry.channelToChannelName(new DirectChannel());
    // Sleep a bit to be sure that we aren't reaped by registry TTL as 60000
    Thread.sleep(100);
    messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
    result = this.output.receive(0);
    assertNotNull(result);
    assertEquals(1, result.getPayload());
    // Some DirectFieldAccessor magic to modify 'expireAt' to the past to avoid timing issues on high-loaded build
    Object messageChannelWrapper = TestUtils.getPropertyValue(this.registry, "channels", Map.class).values().iterator().next();
    DirectFieldAccessor dfa = new DirectFieldAccessor(messageChannelWrapper);
    dfa.setPropertyValue("expireAt", System.currentTimeMillis() - 60000);
    messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.runReaper()");
    messagingTemplate.convertAndSend(input, "@integrationHeaderChannelRegistry.size()");
    result = this.output.receive(0);
    assertNotNull(result);
    assertEquals(0, result.getPayload());
}
Also used : MessagingTemplate(org.springframework.integration.core.MessagingTemplate) DirectChannel(org.springframework.integration.channel.DirectChannel) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) 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