Search in sources :

Example 56 with IntegrationMessageHeaderAccessor

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

the class CorrelationIdTests method testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler.

@Test
public void testCorrelationNotCopiedFromRequestMessgeIdIfAlreadySetByHandler() throws Exception {
    Message<?> message = new GenericMessage<String>("test");
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "createMessage");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals("456-XYZ", new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 57 with IntegrationMessageHeaderAccessor

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

the class CorrelationIdTests method testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable.

@Test
public void testCorrelationIdCopiedFromMessageCorrelationIdIfAvailable() {
    Message<String> message = MessageBuilder.withPayload("test").setCorrelationId("correlationId").build();
    DirectChannel inputChannel = new DirectChannel();
    QueueChannel outputChannel = new QueueChannel(1);
    ServiceActivatingHandler serviceActivator = new ServiceActivatingHandler(new TestBean(), "upperCase");
    serviceActivator.setOutputChannel(outputChannel);
    EventDrivenConsumer endpoint = new EventDrivenConsumer(inputChannel, serviceActivator);
    endpoint.start();
    assertTrue(inputChannel.send(message));
    Message<?> reply = outputChannel.receive(0);
    assertEquals(new IntegrationMessageHeaderAccessor(message).getCorrelationId(), new IntegrationMessageHeaderAccessor(reply).getCorrelationId());
    assertTrue(new IntegrationMessageHeaderAccessor(message).getCorrelationId().equals(new IntegrationMessageHeaderAccessor(reply).getCorrelationId()));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) QueueChannel(org.springframework.integration.channel.QueueChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) ServiceActivatingHandler(org.springframework.integration.handler.ServiceActivatingHandler) Test(org.junit.Test)

Example 58 with IntegrationMessageHeaderAccessor

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

the class MethodInvokingReleaseStrategyTests method testAdapterWithWildcardParametrizedMessageBasedMethod.

@Test
public void testAdapterWithWildcardParametrizedMessageBasedMethod() {
    class TestReleaseStrategy {

        @SuppressWarnings("unused")
        public boolean checkCompletenessOnListOfMessagesParametrizedWithWildcard(List<Message<?>> messages) {
            Assert.assertTrue(messages.size() > 0);
            return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
        }
    }
    ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnListOfMessagesParametrizedWithWildcard");
    MessageGroup messages = createListOfMessages(3);
    Assert.assertTrue(adapter.canRelease(messages));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 59 with IntegrationMessageHeaderAccessor

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

the class MethodInvokingReleaseStrategyTests method testAdapterWithTypeParametrizedMessageBasedMethod.

@Test
public void testAdapterWithTypeParametrizedMessageBasedMethod() {
    class TestReleaseStrategy {

        @SuppressWarnings("unused")
        public boolean checkCompletenessOnListOfMessagesParametrizedWithString(List<Message<String>> messages) {
            Assert.assertTrue(messages.size() > 0);
            return messages.size() > new IntegrationMessageHeaderAccessor(messages.iterator().next()).getSequenceSize();
        }
    }
    ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), "checkCompletenessOnListOfMessagesParametrizedWithString");
    MessageGroup messages = createListOfMessages(3);
    Assert.assertTrue(adapter.canRelease(messages));
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageGroup(org.springframework.integration.store.MessageGroup) SimpleMessageGroup(org.springframework.integration.store.SimpleMessageGroup) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 60 with IntegrationMessageHeaderAccessor

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

the class HeaderAnnotationTransformerTests method headerAnnotationWithPrefixedHeaderAndRelativeExpression.

// INT-1082
@Test
public void headerAnnotationWithPrefixedHeaderAndRelativeExpression() {
    Object target = new TestTransformer();
    MethodInvokingTransformer transformer = new MethodInvokingTransformer(target, "evalCorrelationId");
    MessageTransformingHandler handler = new MessageTransformingHandler(transformer);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    QueueChannel outputChannel = new QueueChannel();
    handler.setOutputChannel(outputChannel);
    handler.handleMessage(MessageBuilder.withPayload("test").setCorrelationId("abc").build());
    Message<?> result = outputChannel.receive(0);
    assertNotNull(result);
    assertEquals("ABC", result.getPayload());
    assertEquals("abc", new IntegrationMessageHeaderAccessor(result).getCorrelationId());
}
Also used : IntegrationMessageHeaderAccessor(org.springframework.integration.IntegrationMessageHeaderAccessor) MessageTransformingHandler(org.springframework.integration.transformer.MessageTransformingHandler) QueueChannel(org.springframework.integration.channel.QueueChannel) BeanFactory(org.springframework.beans.factory.BeanFactory) MethodInvokingTransformer(org.springframework.integration.transformer.MethodInvokingTransformer) Test(org.junit.Test)

Aggregations

IntegrationMessageHeaderAccessor (org.springframework.integration.IntegrationMessageHeaderAccessor)68 Test (org.junit.Test)56 QueueChannel (org.springframework.integration.channel.QueueChannel)32 Message (org.springframework.messaging.Message)21 GenericMessage (org.springframework.messaging.support.GenericMessage)19 MessageChannel (org.springframework.messaging.MessageChannel)15 ArrayList (java.util.ArrayList)10 MessagingTemplate (org.springframework.integration.core.MessagingTemplate)9 DirectChannel (org.springframework.integration.channel.DirectChannel)8 ServiceActivatingHandler (org.springframework.integration.handler.ServiceActivatingHandler)6 List (java.util.List)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 MessageSequenceComparator (org.springframework.integration.aggregator.MessageSequenceComparator)4 Aggregator (org.springframework.integration.annotation.Aggregator)4 InputStream (java.io.InputStream)3 LinkedList (java.util.LinkedList)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)3 MessageGroup (org.springframework.integration.store.MessageGroup)3 SimpleMessageGroup (org.springframework.integration.store.SimpleMessageGroup)3