use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbMessageSourceTests method validateSuccessfulSubObjectQueryWithSingleElementIfOneInList.
@Test
@MongoDbAvailable
public void validateSuccessfulSubObjectQueryWithSingleElementIfOneInList() throws Exception {
MongoDbFactory mongoDbFactory = this.prepareMongoFactory();
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.save(this.createPerson(), "data");
Expression queryExpression = new LiteralExpression("{'address.state' : 'PA'}");
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());
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 MongoDbOutboundGatewayTests method testNoFactorySpecified.
@SuppressWarnings("ConstantConditions")
@Test
@MongoDbAvailable
public void testNoFactorySpecified() {
MongoDbFactory nullFactory = null;
try {
new MongoDbOutboundGateway(nullFactory);
Assert.fail("Expected the test case to throw an IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals("MongoDbFactory translator 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 testWithNullCollectionNameExpression.
@Test
@MongoDbAvailable
public void testWithNullCollectionNameExpression() throws Exception {
MongoDbOutboundGateway gateway = new MongoDbOutboundGateway(mongoDbFactory);
gateway.setBeanFactory(beanFactory);
gateway.setQueryExpression(new LiteralExpression("{name : 'Xavi'}"));
gateway.setExpectSingleResult(true);
try {
gateway.afterPropertiesSet();
Assert.fail("Expected the test case to throw an IllegalArgumentException");
} catch (IllegalStateException e) {
assertEquals("no collection name specified", e.getMessage());
}
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class MongoDbOutboundGatewayTests method testWithCollectionCallbackCount.
@Test
@MongoDbAvailable
public void testWithCollectionCallbackCount() throws Exception {
Message<String> message = MessageBuilder.withPayload("").build();
MongoDbOutboundGateway gateway = createGateway();
gateway.setEntityClass(Person.class);
gateway.setCollectionNameExpression(new LiteralExpression("data"));
gateway.setCollectionCallback(MongoCollection::count);
gateway.afterPropertiesSet();
long result = (long) gateway.handleRequestMessage(message);
assertEquals(4, result);
}
use of org.springframework.integration.mongodb.rules.MongoDbAvailable in project spring-integration by spring-projects.
the class AbstractMongoDbMessageStoreTests method testAddGetWithObjectDefaultConstructorPayload.
@Test
@MongoDbAvailable
public void testAddGetWithObjectDefaultConstructorPayload() throws Exception {
cleanupCollections(new SimpleMongoDbFactory(new MongoClient(), "test"));
MessageStore store = getMessageStore();
Person p = new Person();
p.setFname("John");
p.setLname("Doe");
Message<?> messageToStore = MessageBuilder.withPayload(p).build();
store.addMessage(messageToStore);
Message<?> retrievedMessage = store.getMessage(messageToStore.getHeaders().getId());
assertNotNull(retrievedMessage);
assertEquals(messageToStore.getPayload(), retrievedMessage.getPayload());
assertEquals(messageToStore.getHeaders(), retrievedMessage.getHeaders());
assertEquals(messageToStore, retrievedMessage);
}
Aggregations