Search in sources :

Example 21 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class MessagingAnnotationsWithBeanAnnotationTests method testMessagingAnnotationsFlow.

@Test
public void testMessagingAnnotationsFlow() {
    Stream.of(this.sourcePollingChannelAdapters).forEach(a -> a.start());
    // this.sourcePollingChannelAdapter.start();
    for (int i = 0; i < 10; i++) {
        Message<?> receive = this.discardChannel.receive(10000);
        assertNotNull(receive);
        assertTrue(((Integer) receive.getPayload()) % 2 == 0);
        receive = this.counterErrorChannel.receive(10000);
        assertNotNull(receive);
        assertThat(receive, instanceOf(ErrorMessage.class));
        assertThat(receive.getPayload(), instanceOf(MessageRejectedException.class));
        MessageRejectedException exception = (MessageRejectedException) receive.getPayload();
        assertThat(exception.getMessage(), containsString("MessageFilter " + "'messagingAnnotationsWithBeanAnnotationTests.ContextConfiguration.filter.filter.handler'" + " rejected Message"));
    }
    for (Message<?> message : collector) {
        assertFalse(((Integer) message.getPayload()) % 2 == 0);
        MessageHistory messageHistory = MessageHistory.read(message);
        assertNotNull(messageHistory);
        String messageHistoryString = messageHistory.toString();
        assertThat(messageHistoryString, Matchers.containsString("routerChannel"));
        assertThat(messageHistoryString, Matchers.containsString("filterChannel"));
        assertThat(messageHistoryString, Matchers.containsString("aggregatorChannel"));
        assertThat(messageHistoryString, Matchers.containsString("splitterChannel"));
        assertThat(messageHistoryString, Matchers.containsString("serviceChannel"));
        assertThat(messageHistoryString, Matchers.not(Matchers.containsString("discardChannel")));
    }
    assertNull(this.skippedServiceActivator);
    assertNull(this.skippedMessageHandler);
    assertNull(this.skippedChannel);
    assertNull(this.skippedChannel2);
    assertNull(this.skippedMessageSource);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) MessageHistory(org.springframework.integration.history.MessageHistory) EnableMessageHistory(org.springframework.integration.config.EnableMessageHistory) Matchers.containsString(org.hamcrest.Matchers.containsString) ErrorMessage(org.springframework.messaging.support.ErrorMessage) MessageRejectedException(org.springframework.integration.MessageRejectedException) Test(org.junit.Test)

Example 22 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class RoutingSlipTests method testRoutingSlip.

@Test
@SuppressWarnings("unchecked")
public void testRoutingSlip() {
    PollableChannel replyChannel = new QueueChannel();
    Message<List<String>> request = MessageBuilder.withPayload(Arrays.asList("test1", "test2")).setReplyChannel(replyChannel).setHeader("myRoutingSlipChannel", "channel5").build();
    this.input.send(request);
    Message<?> reply = replyChannel.receive(10000);
    assertNotNull(reply);
    List<Message<?>> messages = (List<Message<?>>) reply.getPayload();
    for (Message<?> message : messages) {
        Map<List<String>, Integer> routingSlip = message.getHeaders().get(IntegrationMessageHeaderAccessor.ROUTING_SLIP, Map.class);
        assertEquals(routingSlip.keySet().iterator().next().size(), routingSlip.values().iterator().next().intValue());
        MessageHistory messageHistory = MessageHistory.read(message);
        List<String> channelNames = Arrays.asList("input", "split", "process", "channel1", "channel2", "channel3", "channel4", "channel5", "aggregate");
        for (Properties properties : messageHistory) {
            assertTrue(channelNames.contains(properties.getProperty("name")));
        }
    }
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) Matchers.containsString(org.hamcrest.Matchers.containsString) Properties(java.util.Properties) MessageHistory(org.springframework.integration.history.MessageHistory) PollableChannel(org.springframework.messaging.PollableChannel) List(java.util.List) Test(org.junit.Test)

Example 23 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class MessageHistoryTests method addComponents.

@Test
public void addComponents() {
    GenericMessage<String> original = new GenericMessage<String>("foo");
    assertNull(MessageHistory.read(original));
    Message<String> result1 = MessageHistory.write(original, new TestComponent(1));
    MessageHistory history1 = MessageHistory.read(result1);
    assertNotNull(history1);
    assertEquals("testComponent-1", history1.toString());
    Message<String> result2 = MessageHistory.write(result1, new TestComponent(2));
    MessageHistory history2 = MessageHistory.read(result2);
    assertNotNull(history2);
    assertEquals("testComponent-1,testComponent-2", history2.toString());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) MessageHistory(org.springframework.integration.history.MessageHistory) Test(org.junit.Test)

Example 24 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class MessageHistoryTests method verifyImmutability.

@Test(expected = UnsupportedOperationException.class)
public void verifyImmutability() {
    Message<?> message = MessageHistory.write(MessageBuilder.withPayload("test").build(), new TestComponent(1));
    MessageHistory history = MessageHistory.read(message);
    history.add(new Properties());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) Properties(java.util.Properties) Test(org.junit.Test)

Example 25 with MessageHistory

use of org.springframework.integration.history.MessageHistory in project spring-integration by spring-projects.

the class MessageHistoryTests method testCorrectMutableMessageAfterWrite.

@Test
public void testCorrectMutableMessageAfterWrite() {
    MutableMessage<String> original = new MutableMessage<>("foo");
    assertNull(MessageHistory.read(original));
    Message<String> result1 = MessageHistory.write(original, new TestComponent(1));
    assertThat(result1, instanceOf(MutableMessage.class));
    assertSame(original, result1);
    MessageHistory history1 = MessageHistory.read(result1);
    assertNotNull(history1);
    assertEquals("testComponent-1", history1.toString());
    Message<String> result2 = MessageHistory.write(result1, new TestComponent(2));
    assertSame(original, result2);
    MessageHistory history2 = MessageHistory.read(result2);
    assertNotNull(history2);
    assertEquals("testComponent-1,testComponent-2", history2.toString());
}
Also used : MessageHistory(org.springframework.integration.history.MessageHistory) MutableMessage(org.springframework.integration.support.MutableMessage) Test(org.junit.Test)

Aggregations

MessageHistory (org.springframework.integration.history.MessageHistory)37 Test (org.junit.Test)34 Properties (java.util.Properties)26 GenericMessage (org.springframework.messaging.support.GenericMessage)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 DirectChannel (org.springframework.integration.channel.DirectChannel)8 PollableChannel (org.springframework.messaging.PollableChannel)8 Message (org.springframework.messaging.Message)5 Matchers.containsString (org.hamcrest.Matchers.containsString)4 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)3 QueueChannel (org.springframework.integration.channel.QueueChannel)3 EnableMessageHistory (org.springframework.integration.config.EnableMessageHistory)3 MongoClient (com.mongodb.MongoClient)2 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)2 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)2 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)2 TcpConnection (org.springframework.integration.ip.tcp.connection.TcpConnection)2 JmsMessageDrivenEndpoint (org.springframework.integration.jms.JmsMessageDrivenEndpoint)2 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)2 MessageChannel (org.springframework.messaging.MessageChannel)2