use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbMessageSourceTests method validatePipelineInModifyOut.
@Test
@MongoDbAvailable
public void validatePipelineInModifyOut() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(BasicDBObject.parse("{'name' : 'Manny', 'id' : 1}"), "data");
Expression queryExpression = new LiteralExpression("{'name' : 'Manny'}");
MongoDbMessageSource messageSource = new MongoDbMessageSource(mongoDbFactory, queryExpression);
messageSource.setExpectSingleResult(true);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
Document result = (Document) messageSource.receive().getPayload();
Object id = result.get("_id");
result.put("company", "PepBoys");
template.save(result, "data");
result = (Document) messageSource.receive().getPayload();
assertEquals(id, result.get("_id"));
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbMessageSourceTests method validateSuccessfulQueryWithSingleElementIfOneInListAndSingleResult.
@Test
@MongoDbAvailable
public void validateSuccessfulQueryWithSingleElementIfOneInListAndSingleResult() 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.setExpectSingleResult(true);
messageSource.setBeanFactory(mock(BeanFactory.class));
messageSource.afterPropertiesSet();
Person person = (Person) messageSource.receive().getPayload();
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 MongoDbOutboundGatewayTests method testNoTemplateSpecified.
@SuppressWarnings("ConstantConditions")
@Test
@MongoDbAvailable
public void testNoTemplateSpecified() {
MongoOperations mongoTemplate = null;
try {
new MongoDbOutboundGateway(mongoTemplate);
Assert.fail("Expected the test case to throw an IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals("mongoTemplate must not be null.", e.getMessage());
}
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbOutboundGatewayTests method testSingleResultWithQueryExpressionAndNoEntityClass.
@Test
@MongoDbAvailable
public void testSingleResultWithQueryExpressionAndNoEntityClass() {
Message<String> message = MessageBuilder.withPayload("").build();
MongoDbOutboundGateway gateway = createGateway();
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
gateway.setExpectSingleResult(true);
gateway.afterPropertiesSet();
Object result = gateway.handleRequestMessage(message);
Document person = (Document) result;
assertEquals("Xavi", person.get("name"));
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbOutboundGatewayTests method testWithCollectionNameExpressionSpecified.
@Test
@MongoDbAvailable
public void testWithCollectionNameExpressionSpecified() throws Exception {
Message<String> message = MessageBuilder.withPayload("").build();
MongoDbOutboundGateway gateway = createGateway();
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
gateway.setExpectSingleResult(true);
gateway.setCollectionNameExpression(new LiteralExpression("anotherCollection"));
gateway.afterPropertiesSet();
Object result = gateway.handleRequestMessage(message);
assertNull(result);
LiteralExpression collectionNameExpression = (LiteralExpression) TestUtils.getPropertyValue(gateway, "collectionNameExpression");
assertNotNull(collectionNameExpression);
assertEquals("anotherCollection", collectionNameExpression.getValue());
}
Aggregations