use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbOutboundChannelAdapterIntegrationTests method testWithTemplate.
@Test
@MongoDbAvailable
public void testWithTemplate() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory("foo");
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithTemplate", 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 MongoDbOutboundChannelAdapterIntegrationTests method testWithMongoConverter.
@Test
@MongoDbAvailable
public void testWithMongoConverter() throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("outbound-adapter-config.xml", this.getClass());
MessageChannel channel = context.getBean("simpleAdapterWithConverter", 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 MongoDbMessageSourceTests method validateSuccessfulQueryWithSingleElementIfOneInListAsDbObject.
@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithSingleElementIfOneInListAsDbObject() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(this.createPerson(), "data");
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
@SuppressWarnings("unchecked") List<Document> results = ((List<Document>) messageSource.receive().getPayload());
assertEquals(1, results.size());
Document resultObject = results.get(0);
assertEquals("Oleg", resultObject.get("name"));
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbMessageSourceTests method validateSuccessfulQueryWithSingleElementIfOneInList.
@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithSingleElementIfOneInList() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(this.createPerson(), "data");
Expression queryExpression = new LiteralExpression("{'name' : 'Oleg'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
messageSource.setEntityClass(Object.class);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
@SuppressWarnings("unchecked") List<Person> results = ((List<Person>) messageSource.receive().getPayload());
assertEquals(1, results.size());
Person person = results.get(0);
assertEquals("Oleg", person.getName());
assertEquals("PA", person.getAddress().getState());
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbMessageSourceTests method validateSuccessfulQueryWithMongoTemplate.
@SuppressWarnings("unchecked")
@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithMongoTemplate() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MappingMongoConverter converter = new TestMongoConverter(mongoDbFactory, new MongoMappingContext());
converter.afterPropertiesSet();
converter = spy(converter);
MongoTemplate template = new MongoTemplate(mongoDbFactory, converter);
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(template, queryExpression);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
MongoTemplate writingTemplate = new MongoTemplate(mongoDbFactory, converter);
writingTemplate.save(this.createPerson("Manny"), "data");
writingTemplate.save(this.createPerson("Moe"), "data");
writingTemplate.save(this.createPerson("Jack"), "data");
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));
}
Aggregations