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();
}
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));
}
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());
}
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());
}
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));
}
Aggregations