Search in sources :

Example 36 with EventDrivenConsumer

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

the class MongoDbOutboundGatewayXmlTests method testCollectionCallback.

@Test
@MongoDbAvailable
public void testCollectionCallback() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayCollectionCallback", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    long personsCount = (Long) result.getPayload();
    assertEquals(4, personsCount);
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 37 with EventDrivenConsumer

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

the class MongoDbOutboundGatewayXmlTests method testQueryExpressionWithLimit.

@Test
@MongoDbAvailable
public void testQueryExpressionWithLimit() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayQueryExpressionLimit", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    List<Person> persons = getPersons(result);
    assertEquals(2, persons.size());
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) PollableChannel(org.springframework.messaging.PollableChannel) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 38 with EventDrivenConsumer

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

the class JmsOutboundGatewayParserTests method gatewayWithDefaultPubSubDomain.

@Test
public void gatewayWithDefaultPubSubDomain() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayWithPubSubSettings.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("defaultGateway");
    DirectFieldAccessor accessor = new DirectFieldAccessor(new DirectFieldAccessor(endpoint).getPropertyValue("handler"));
    assertFalse((Boolean) accessor.getPropertyValue("requestPubSubDomain"));
    assertFalse((Boolean) accessor.getPropertyValue("replyPubSubDomain"));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 39 with EventDrivenConsumer

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

the class JmsOutboundGatewayParserTests method testAdvised.

@Test
public void testAdvised() {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayWithDeliveryPersistent.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("advised");
    JmsOutboundGateway gateway = TestUtils.getPropertyValue(endpoint, "handler", JmsOutboundGateway.class);
    assertFalse(TestUtils.getPropertyValue(gateway, "async", Boolean.class));
    gateway.handleMessage(new GenericMessage<String>("foo"));
    assertEquals(1, adviceCalled);
    assertEquals(3, TestUtils.getPropertyValue(gateway, "replyContainer.sessionAcknowledgeMode"));
    context.close();
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 40 with EventDrivenConsumer

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

the class JmsOutboundGatewayParserTests method gatewayWithDestExpression.

@Test
public void gatewayWithDestExpression() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("jmsOutboundGatewayReplyDestOptions.xml", this.getClass());
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("jmsGatewayDestExpression");
    DirectFieldAccessor accessor = new DirectFieldAccessor(endpoint);
    JmsOutboundGateway gateway = (JmsOutboundGateway) accessor.getPropertyValue("handler");
    ExpressionEvaluatingMessageProcessor<?> processor = TestUtils.getPropertyValue(gateway, "replyDestinationExpressionProcessor", ExpressionEvaluatingMessageProcessor.class);
    Expression expression = TestUtils.getPropertyValue(gateway, "replyDestinationExpressionProcessor.expression", Expression.class);
    assertEquals("payload", expression.getExpressionString());
    Message<?> message = MessageBuilder.withPayload("foo").build();
    assertEquals("foo", processor.processMessage(message));
    Method method = JmsOutboundGateway.class.getDeclaredMethod("determineReplyDestination", Message.class, Session.class);
    method.setAccessible(true);
    Session session = mock(Session.class);
    Queue queue = mock(Queue.class);
    when(session.createQueue("foo")).thenReturn(queue);
    Destination replyQ = (Destination) method.invoke(gateway, message, session);
    assertSame(queue, replyQ);
    context.close();
}
Also used : Destination(javax.jms.Destination) EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) JmsOutboundGateway(org.springframework.integration.jms.JmsOutboundGateway) Method(java.lang.reflect.Method) Queue(javax.jms.Queue) Session(javax.jms.Session) 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