Search in sources :

Example 16 with EventDrivenConsumer

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

the class ChannelAdapterParserTests method targetOnly.

@Test
public void targetOnly() {
    String beanName = "outboundWithImplicitChannel";
    Object channel = this.applicationContext.getBean(beanName);
    assertTrue(channel instanceof DirectChannel);
    BeanFactoryChannelResolver channelResolver = new BeanFactoryChannelResolver(this.applicationContext);
    assertNotNull(channelResolver.resolveDestination(beanName));
    Object adapter = this.applicationContext.getBean(beanName + ".adapter");
    assertNotNull(adapter);
    assertTrue(adapter instanceof EventDrivenConsumer);
    assertFalse(((EventDrivenConsumer) adapter).isAutoStartup());
    assertEquals(-1, ((EventDrivenConsumer) adapter).getPhase());
    TestConsumer consumer = (TestConsumer) this.applicationContext.getBean("consumer");
    assertNull(consumer.getLastMessage());
    Message<?> message = new GenericMessage<String>("test");
    try {
        ((MessageChannel) channel).send(message);
        fail("MessageDispatchingException is expected.");
    } catch (Exception e) {
        assertThat(e, Matchers.instanceOf(MessageDeliveryException.class));
        assertThat(e.getCause(), Matchers.instanceOf(MessageDispatchingException.class));
    }
    ((EventDrivenConsumer) adapter).start();
    ((MessageChannel) channel).send(message);
    assertNotNull(consumer.getLastMessage());
    assertEquals(message, consumer.getLastMessage());
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) MessageChannel(org.springframework.messaging.MessageChannel) DirectChannel(org.springframework.integration.channel.DirectChannel) BeanFactoryChannelResolver(org.springframework.integration.support.channel.BeanFactoryChannelResolver) DestinationResolutionException(org.springframework.messaging.core.DestinationResolutionException) MessageDispatchingException(org.springframework.integration.MessageDispatchingException) MessageDeliveryException(org.springframework.messaging.MessageDeliveryException) BeanDefinitionParsingException(org.springframework.beans.factory.parsing.BeanDefinitionParsingException) Test(org.junit.Test)

Example 17 with EventDrivenConsumer

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

the class ResequencerParserTests method shouldSetReleasePartialSequencesFlag.

@Test
public void shouldSetReleasePartialSequencesFlag() {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("completelyDefinedResequencer");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag", true, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Example 18 with EventDrivenConsumer

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

the class ResequencerParserTests method testCorrelationStrategyRefOnly.

@Test
public void testCorrelationStrategyRefOnly() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithCorrelationStrategyRefOnly");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertEquals("The ResequencerEndpoint is not configured with the appropriate CorrelationStrategy", context.getBean("testCorrelationStrategy"), getPropertyValue(resequencer, "correlationStrategy"));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Example 19 with EventDrivenConsumer

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

the class ResequencerParserTests method testCorrelationStrategyRefAndMethod.

@Test
public void testCorrelationStrategyRefAndMethod() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithCorrelationStrategyRefAndMethod");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    Object correlationStrategy = getPropertyValue(resequencer, "correlationStrategy");
    assertEquals("The ResequencerEndpoint is not configured with a CorrelationStrategy adapter", MethodInvokingCorrelationStrategy.class, correlationStrategy.getClass());
    MethodInvokingCorrelationStrategy adapter = (MethodInvokingCorrelationStrategy) correlationStrategy;
    assertEquals("foo", adapter.getCorrelationKey(MessageBuilder.withPayload("not important").build()));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) MethodInvokingCorrelationStrategy(org.springframework.integration.aggregator.MethodInvokingCorrelationStrategy) Test(org.junit.Test)

Example 20 with EventDrivenConsumer

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

the class ResequencerParserTests method testReleaseStrategyRefOnly.

@Test
public void testReleaseStrategyRefOnly() throws Exception {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategyRefOnly");
    ResequencingMessageHandler resequencer = getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertEquals("The ResequencerEndpoint is not configured with the appropriate ReleaseStrategy", context.getBean("testReleaseStrategy"), getPropertyValue(resequencer, "releaseStrategy"));
    assertFalse(TestUtils.getPropertyValue(resequencer, "expireGroupsUponTimeout", Boolean.class));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) Test(org.junit.Test)

Aggregations

EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)106 Test (org.junit.Test)96 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)27 DirectChannel (org.springframework.integration.channel.DirectChannel)19 PollableChannel (org.springframework.messaging.PollableChannel)19 GenericMessage (org.springframework.messaging.support.GenericMessage)18 MessageChannel (org.springframework.messaging.MessageChannel)16 QueueChannel (org.springframework.integration.channel.QueueChannel)14 MessageHandler (org.springframework.messaging.MessageHandler)12 List (java.util.List)9 ResequencingMessageHandler (org.springframework.integration.aggregator.ResequencingMessageHandler)9 Message (org.springframework.messaging.Message)8 SmartLifecycle (org.springframework.context.SmartLifecycle)6 JmsOutboundGateway (org.springframework.integration.jms.JmsOutboundGateway)6 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)6 SmartLifecycleRoleController (org.springframework.integration.support.SmartLifecycleRoleController)6 MethodInvokingReleaseStrategy (org.springframework.integration.aggregator.MethodInvokingReleaseStrategy)5 ReleaseStrategy (org.springframework.integration.aggregator.ReleaseStrategy)5 AbstractReplyProducingMessageHandler (org.springframework.integration.handler.AbstractReplyProducingMessageHandler)5