Search in sources :

Example 16 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class MongoDbOutboundGatewayXmlTests method testSingleQueryExpression.

@Test
@MongoDbAvailable
public void testSingleQueryExpression() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewaySingleQueryExpression", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("query", "{'name' : 'Gary'}").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    Person person = getPerson(result);
    assertEquals("Gary", person.getName());
}
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 17 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class MongoDbOutboundGatewayXmlTests method testQueryExpression.

@Test
@MongoDbAvailable
public void testQueryExpression() throws Exception {
    EventDrivenConsumer consumer = context.getBean("gatewayQueryExpression", EventDrivenConsumer.class);
    PollableChannel outChannel = context.getBean("out", PollableChannel.class);
    Message<String> message = MessageBuilder.withPayload("").setHeader("query", "{}").setHeader("collectionName", "data").build();
    consumer.getHandler().handleMessage(message);
    Message<?> result = outChannel.receive(10000);
    List<Person> persons = getPersons(result);
    assertEquals(4, 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 18 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable 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 19 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable 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 20 with MongoDbAvailable

use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.

the class MongoDbOutboundChannelAdapterIntegrationTests method testSavingDbObject.

@Test
@MongoDbAvailable
public void testSavingDbObject() throws Exception {
    BasicDBObject dbObject = BasicDBObject.parse("{'foo' : 'bar'}");
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
    MessageChannel channel = context.getBean("simpleAdapterWithTemplate", MessageChannel.class);
    Message<BasicDBObject> message = MessageBuilder.withPayload(dbObject).setHeader("collectionName", "foo").build();
    channel.send(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    assertNotNull(template.find(new BasicQuery("{'foo' : 'bar'}"), BasicDBObject.class, "foo"));
    context.close();
}
Also used : BasicDBObject(com.mongodb.BasicDBObject) MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) MessageChannel(org.springframework.messaging.MessageChannel) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) ClassPathXmlApplicationContext(org.springframework.context.support.ClassPathXmlApplicationContext) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Aggregations

Test (org.junit.Test)70 MongoDbAvailable (org.springframework.integration.mongodb.rules.MongoDbAvailable)70 MongoClient (com.mongodb.MongoClient)28 SimpleMongoDbFactory (org.springframework.data.mongodb.core.SimpleMongoDbFactory)28 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)27 GenericMessage (org.springframework.messaging.support.GenericMessage)20 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)19 LiteralExpression (org.springframework.expression.common.LiteralExpression)17 AbstractBatchingMessageGroupStore (org.springframework.integration.store.AbstractBatchingMessageGroupStore)17 MessageGroupStore (org.springframework.integration.store.MessageGroupStore)17 MessageStore (org.springframework.integration.store.MessageStore)14 BeanFactory (org.springframework.beans.factory.BeanFactory)13 MessageGroup (org.springframework.integration.store.MessageGroup)13 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)11 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)8 Expression (org.springframework.expression.Expression)8 Matchers.containsString (org.hamcrest.Matchers.containsString)7 EventDrivenConsumer (org.springframework.integration.endpoint.EventDrivenConsumer)6 MessageChannel (org.springframework.messaging.MessageChannel)6 PollableChannel (org.springframework.messaging.PollableChannel)6