Search in sources :

Example 21 with MongoDbAvailable

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

the class MongoDbOutboundChannelAdapterIntegrationTests method testWithDefaultMongoFactory.

@Test
@MongoDbAvailable
public void testWithDefaultMongoFactory() throws Exception {
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
    MessageChannel channel = context.getBean("simpleAdapter", MessageChannel.class);
    Message<Person> message = new GenericMessage<MongoDbAvailableTests.Person>(this.createPerson("Bob"));
    channel.send(message);
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    assertNotNull(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "data"));
    context.close();
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) 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) MongoDbAvailableTests(org.springframework.integration.mongodb.rules.MongoDbAvailableTests) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 22 with MongoDbAvailable

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

the class MongoDbOutboundChannelAdapterIntegrationTests method testWithNamedCollection.

@Test
@MongoDbAvailable
public void testWithNamedCollection() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
    ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
    MessageChannel channel = context.getBean("simpleAdapterWithNamedCollection", MessageChannel.class);
    Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).setHeader("collectionName", "foo").build();
    channel.send(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    assertNotNull(template.find(new BasicQuery("{'name' : 'Bob'}"), Person.class, "foo"));
    context.close();
}
Also used : 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)

Example 23 with MongoDbAvailable

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

the class MongoDbMessageSourceTests method validateSuccessfulQueryWithCustomConverter.

@SuppressWarnings("unchecked")
@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithCustomConverter() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    template.save(this.createPerson("Manny"), "data");
    template.save(this.createPerson("Moe"), "data");
    template.save(this.createPerson("Jack"), "data");
    Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
    MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
    MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
    messageSource.setBeanFactory(mock(BeanFactory.class));
    converter.afterPropertiesSet();
    converter = spy(converter);
    messageSource.setMongoConverter(converter);
    messageSource.afterPropertiesSet();
    List<Person> persons = (List<Person>) messageSource.receive().getPayload();
    assertEquals(3, persons.size());
    verify(converter, times(3)).read((Class<Person>) Mockito.any(), Mockito.any(Bson.class));
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) LiteralExpression(org.springframework.expression.common.LiteralExpression) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bson(org.bson.conversions.Bson) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeanFactory(org.springframework.beans.factory.BeanFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) List(java.util.List) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 24 with MongoDbAvailable

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

the class MongoDbMessageSourceTests method validateSuccessfulQueryWithMultipleElements.

@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithMultipleElements() throws Exception {
    List<Person> persons = queryMultipleElements(new LiteralExpression("{'address.state' : 'PA'}"));
    assertEquals(3, persons.size());
}
Also used : LiteralExpression(org.springframework.expression.common.LiteralExpression) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 25 with MongoDbAvailable

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

the class MongoDbMessageSourceTests method validateSuccessfulQueryWithNullReturn.

@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithNullReturn() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    template.save(this.createPerson("Manny"), "data");
    template.save(this.createPerson("Moe"), "data");
    template.save(this.createPerson("Jack"), "data");
    Expression queryExpression = new LiteralExpression("{'address.state' : 'NJ'}");
    MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
    messageSource.setBeanFactory(mock(BeanFactory.class));
    messageSource.afterPropertiesSet();
    assertNull(messageSource.receive());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) LiteralExpression(org.springframework.expression.common.LiteralExpression) Expression(org.springframework.expression.Expression) LiteralExpression(org.springframework.expression.common.LiteralExpression) BeanFactory(org.springframework.beans.factory.BeanFactory) 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