use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-boot by spring-projects.
the class MongoDataAutoConfigurationTests method createsMongoDatabaseFactoryForFallbackMongoClient.
@Test
void createsMongoDatabaseFactoryForFallbackMongoClient() {
this.contextRunner.withUserConfiguration(FallbackMongoClientConfiguration.class).run((context) -> {
MongoDatabaseFactory dbFactory = context.getBean(MongoDatabaseFactory.class);
assertThat(dbFactory).isInstanceOf(SimpleMongoClientDatabaseFactory.class);
});
}
use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-boot by spring-projects.
the class MongoDataAutoConfigurationTests method whenGridFsDatabaseIsConfiguredThenGridFsTemplateIsAutoConfiguredAndUsesIt.
@Test
void whenGridFsDatabaseIsConfiguredThenGridFsTemplateIsAutoConfiguredAndUsesIt() {
this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.database:grid").run((context) -> {
assertThat(context).hasSingleBean(GridFsTemplate.class);
GridFsTemplate template = context.getBean(GridFsTemplate.class);
MongoDatabaseFactory factory = (MongoDatabaseFactory) ReflectionTestUtils.getField(template, "dbFactory");
assertThat(factory.getMongoDatabase().getName()).isEqualTo("grid");
});
}
use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.
the class ReactiveMongoTemplate method changeStream.
@Override
public <T> Flux<ChangeStreamEvent<T>> changeStream(@Nullable String database, @Nullable String collectionName, ChangeStreamOptions options, Class<T> targetType) {
List<Document> filter = prepareFilter(options);
FullDocument fullDocument = ClassUtils.isAssignable(Document.class, targetType) ? FullDocument.DEFAULT : FullDocument.UPDATE_LOOKUP;
return //
ReactiveMongoDatabaseUtils.getDatabase(database, mongoDatabaseFactory).map(db -> {
ChangeStreamPublisher<Document> publisher;
if (StringUtils.hasText(collectionName)) {
publisher = filter.isEmpty() ? db.getCollection(collectionName).watch(Document.class) : db.getCollection(collectionName).watch(filter, Document.class);
} else {
publisher = filter.isEmpty() ? db.watch(Document.class) : db.watch(filter, Document.class);
}
publisher = options.getResumeToken().map(BsonValue::asDocument).map(publisher::resumeAfter).orElse(publisher);
publisher = options.getCollation().map(Collation::toMongoCollation).map(publisher::collation).orElse(publisher);
publisher = options.getResumeBsonTimestamp().map(publisher::startAtOperationTime).orElse(publisher);
return publisher.fullDocument(options.getFullDocumentLookup().orElse(fullDocument));
}).flatMapMany(publisher -> Flux.from(publisher).map(document -> new ChangeStreamEvent<>(document, targetType, getConverter())));
}
use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MongoDbFactoryParserIntegrationTests method usesMongoClientClientRef.
// DATAMONGO-2384
@Test
public void usesMongoClientClientRef() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("namespace/db-factory-bean.xml");
MongoDatabaseFactory dbFactory = ctx.getBean("with-mongo-client-client-ref", MongoDatabaseFactory.class);
assertThat(dbFactory).isInstanceOf(SimpleMongoClientDatabaseFactory.class);
assertThat(ReflectionTestUtils.getField(dbFactory, "mongoClient")).isInstanceOf(com.mongodb.client.MongoClient.class);
}
use of org.springframework.data.mongodb.MongoDatabaseFactory in project spring-data-mongodb by spring-projects.
the class MongoDbFactoryParserIntegrationTests method usesConnectionStringToCreateClientClient.
// DATAMONGO-2384
@Test
public void usesConnectionStringToCreateClientClient() {
ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("namespace/db-factory-bean.xml");
MongoDatabaseFactory dbFactory = ctx.getBean("with-connection-string", MongoDatabaseFactory.class);
assertThat(dbFactory).isInstanceOf(SimpleMongoClientDatabaseFactory.class);
assertThat(ReflectionTestUtils.getField(dbFactory, "mongoClient")).isInstanceOf(com.mongodb.client.MongoClient.class);
}
Aggregations