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