Search in sources :

Example 66 with MongoDbAvailable

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

the class MongoDbMetadataStoreTests method testConfigureCustomCollection.

@MongoDbAvailable
@Test
public void testConfigureCustomCollection() throws Exception {
    final String collectionName = "testMetadataStore";
    final MongoDbFactory mongoDbFactory = this.prepareMongoFactory(collectionName);
    final MongoTemplate template = new MongoTemplate(mongoDbFactory);
    store = new MongoDbMetadataStore(template, collectionName);
    testBasics();
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 67 with MongoDbAvailable

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

the class MongoDbStoringMessageHandlerTests method validateMessageHandlingWithMongoTemplate.

@Test
@MongoDbAvailable
public void validateMessageHandlingWithMongoTemplate() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
    converter.afterPropertiesSet();
    converter = spy(converter);
    MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
    MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(template);
    handler.setCollectionNameExpression(new LiteralExpression("foo"));
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
    handler.handleMessage(message);
    MongoTemplate readingTemplate = new MongoTemplate(mongoDbFactory);
    Query query = new BasicQuery("{'name' : 'Bob'}");
    Person person = readingTemplate.findOne(query, Person.class, "foo");
    assertEquals("Bob", person.getName());
    assertEquals("PA", person.getAddress().getState());
    verify(converter, times(1)).write(Mockito.any(), Mockito.any(Bson.class));
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Query(org.springframework.data.mongodb.core.query.Query) LiteralExpression(org.springframework.expression.common.LiteralExpression) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bson(org.bson.conversions.Bson) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeanFactory(org.springframework.beans.factory.BeanFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 68 with MongoDbAvailable

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

the class MongoDbStoringMessageHandlerTests method validateMessageHandlingWithDefaultCollection.

@Test
@MongoDbAvailable
public void validateMessageHandlingWithDefaultCollection() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(mongoDbFactory);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
    handler.handleMessage(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    Query query = new BasicQuery("{'name' : 'Bob'}");
    Person person = template.findOne(query, Person.class, "data");
    assertEquals("Bob", person.getName());
    assertEquals("PA", person.getAddress().getState());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Query(org.springframework.data.mongodb.core.query.Query) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) BeanFactory(org.springframework.beans.factory.BeanFactory) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Test(org.junit.Test) MongoDbAvailable(org.springframework.integration.mongodb.rules.MongoDbAvailable)

Example 69 with MongoDbAvailable

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

the class MongoDbStoringMessageHandlerTests method validateMessageHandlingWithNamedCollection.

@Test
@MongoDbAvailable
public void validateMessageHandlingWithNamedCollection() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(mongoDbFactory);
    handler.setCollectionNameExpression(new LiteralExpression("foo"));
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
    handler.handleMessage(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    Query query = new BasicQuery("{'name' : 'Bob'}");
    Person person = template.findOne(query, Person.class, "foo");
    assertEquals("Bob", person.getName());
    assertEquals("PA", person.getAddress().getState());
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Query(org.springframework.data.mongodb.core.query.Query) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) 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)

Example 70 with MongoDbAvailable

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

the class MongoDbStoringMessageHandlerTests method validateMessageHandlingWithMongoConverter.

@Test
@MongoDbAvailable
public void validateMessageHandlingWithMongoConverter() throws Exception {
    MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
    MongoDbStoringMessageHandler handler = new MongoDbStoringMessageHandler(mongoDbFactory);
    handler.setCollectionNameExpression(new LiteralExpression("foo"));
    MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
    converter.afterPropertiesSet();
    converter = spy(converter);
    handler.setMongoConverter(converter);
    handler.setBeanFactory(mock(BeanFactory.class));
    handler.afterPropertiesSet();
    Message<Person> message = MessageBuilder.withPayload(this.createPerson("Bob")).build();
    handler.handleMessage(message);
    MongoTemplate template = new MongoTemplate(mongoDbFactory);
    Query query = new BasicQuery("{'name' : 'Bob'}");
    Person person = template.findOne(query, Person.class, "foo");
    assertEquals("Bob", person.getName());
    assertEquals("PA", person.getAddress().getState());
    verify(converter, times(1)).write(Mockito.any(), Mockito.any(Bson.class));
}
Also used : MongoDbFactory(org.springframework.data.mongodb.MongoDbFactory) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) Query(org.springframework.data.mongodb.core.query.Query) LiteralExpression(org.springframework.expression.common.LiteralExpression) MongoTemplate(org.springframework.data.mongodb.core.MongoTemplate) Bson(org.bson.conversions.Bson) BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) BeanFactory(org.springframework.beans.factory.BeanFactory) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) 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