use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project cas by apereo.
the class MongoDbPropertySourceLocatorTests method verifyOperation.
@Test
public void verifyOperation() {
val factory = new SimpleMongoClientDatabaseFactory(MongoDbCloudConfigBootstrapConfigurationTests.MONGODB_URI);
val template = new MongoTemplate(factory);
val loc = new MongoDbPropertySourceLocator(template);
assertNull(loc.locate(mock(Environment.class)));
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-integration-samples by spring-projects.
the class DemoUtils method prepareMongoFactory.
public static MongoDatabaseFactory prepareMongoFactory(String... additionalCollectionToDrop) throws Exception {
MongoDatabaseFactory mongoDbFactory = new SimpleMongoClientDatabaseFactory(MongoClients.create(), "test");
MongoTemplate template = new MongoTemplate(mongoDbFactory);
template.dropCollection("messages");
template.dropCollection("data");
for (String additionalCollection : additionalCollectionToDrop) {
template.dropCollection(additionalCollection);
}
return mongoDbFactory;
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MongoDbFactoryParserIntegrationTests method testWriteConcern.
// DATAMONGO-2199
@Test
public void testWriteConcern() throws Exception {
try (MongoClient client = MongoTestUtils.client()) {
SimpleMongoClientDatabaseFactory dbFactory = new SimpleMongoClientDatabaseFactory(client, "database");
dbFactory.setWriteConcern(WriteConcern.ACKNOWLEDGED);
dbFactory.getMongoDatabase();
assertThat(ReflectionTestUtils.getField(dbFactory, "writeConcern")).isEqualTo(WriteConcern.ACKNOWLEDGED);
}
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MongoDbFactoryParserIntegrationTests method assertWriteConcern.
private static void assertWriteConcern(ClassPathXmlApplicationContext ctx, WriteConcern expectedWriteConcern) {
SimpleMongoClientDatabaseFactory dbFactory = ctx.getBean("first", SimpleMongoClientDatabaseFactory.class);
MongoDatabase db = dbFactory.getMongoDatabase();
assertThat(db.getName()).isEqualTo("db");
WriteConcern configuredConcern = (WriteConcern) ReflectionTestUtils.getField(dbFactory, "writeConcern");
assertThat(configuredConcern).isEqualTo(expectedWriteConcern);
assertThat(db.getWriteConcern()).isEqualTo(expectedWriteConcern);
assertThat(db.getWriteConcern()).isEqualTo(expectedWriteConcern);
}
use of org.springframework.data.mongodb.core.SimpleMongoClientDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MappingTests method testIndexesCreatedInRightCollection.
@Test
public void testIndexesCreatedInRightCollection() {
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setAutoIndexCreation(true);
MongoTemplate template = new MongoTemplate(new SimpleMongoClientDatabaseFactory(client, DB_NAME), new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext));
CustomCollectionWithIndex ccwi = new CustomCollectionWithIndex("test");
template.insert(ccwi);
assertThat(template.execute("foobar", new CollectionCallback<Boolean>() {
public Boolean doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
List<Document> indexes = new ArrayList<Document>();
collection.listIndexes(Document.class).into(indexes);
for (Document document : indexes) {
if (document.get("name") != null && document.get("name") instanceof String && ((String) document.get("name")).startsWith("name")) {
return true;
}
}
return false;
}
})).isTrue();
DetectedCollectionWithIndex dcwi = new DetectedCollectionWithIndex("test");
template.insert(dcwi);
assertThat(template.execute(MongoCollectionUtils.getPreferredCollectionName(DetectedCollectionWithIndex.class), new CollectionCallback<Boolean>() {
public Boolean doInCollection(MongoCollection<Document> collection) throws MongoException, DataAccessException {
List<Document> indexes = new ArrayList<Document>();
collection.listIndexes(Document.class).into(indexes);
for (Document document : indexes) {
if (document.get("name") != null && document.get("name") instanceof String && ((String) document.get("name")).startsWith("name")) {
return true;
}
}
return false;
}
})).isTrue();
}
Aggregations