|
|
@ -16,8 +16,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.data.mongo;
|
|
|
|
package org.springframework.boot.autoconfigure.data.mongo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.ConnectionString;
|
|
|
|
import com.mongodb.ConnectionString;
|
|
|
|
|
|
|
|
import com.mongodb.reactivestreams.client.MongoCollection;
|
|
|
|
|
|
|
|
import com.mongodb.reactivestreams.client.gridfs.GridFSBucket;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
|
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
|
|
|
@ -68,20 +73,26 @@ class MongoReactiveDataAutoConfigurationTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void usesMongoConnectionDetailsIfAvailable() {
|
|
|
|
void usesMongoConnectionDetailsIfAvailable() {
|
|
|
|
this.contextRunner.withUserConfiguration(ConnectionDetailsConfiguration.class).run((context) -> {
|
|
|
|
this.contextRunner.withUserConfiguration(ConnectionDetailsConfiguration.class).run((context) -> {
|
|
|
|
assertThat(grisFsTemplateDatabaseName(context)).isEqualTo("grid-database-1");
|
|
|
|
assertThat(grisFsTemplateDatabaseName(context)).isEqualTo("grid-database-1");
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
assertThat(template).hasFieldOrPropertyWithValue("bucket", "connection-details-bucket");
|
|
|
|
GridFSBucket bucket = ((Mono<GridFSBucket>) ReflectionTestUtils.getField(template, "bucketSupplier"))
|
|
|
|
|
|
|
|
.block(Duration.ofSeconds(30));
|
|
|
|
|
|
|
|
assertThat(bucket.getBucketName()).isEqualTo("connection-details-bucket");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
void whenGridFsBucketIsConfiguredThenGridFsTemplateUsesIt() {
|
|
|
|
void whenGridFsBucketIsConfiguredThenGridFsTemplateUsesIt() {
|
|
|
|
this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.bucket:test-bucket").run((context) -> {
|
|
|
|
this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.bucket:test-bucket").run((context) -> {
|
|
|
|
assertThat(context).hasSingleBean(ReactiveGridFsTemplate.class);
|
|
|
|
assertThat(context).hasSingleBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
assertThat(template).hasFieldOrPropertyWithValue("bucket", "test-bucket");
|
|
|
|
GridFSBucket bucket = ((Mono<GridFSBucket>) ReflectionTestUtils.getField(template, "bucketSupplier"))
|
|
|
|
|
|
|
|
.block(Duration.ofSeconds(30));
|
|
|
|
|
|
|
|
assertThat(bucket.getBucketName()).isEqualTo("test-bucket");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -150,12 +161,14 @@ class MongoReactiveDataAutoConfigurationTests {
|
|
|
|
.run((context) -> assertThat(context).getFailure().hasMessageContaining("Database name must not be empty"));
|
|
|
|
.run((context) -> assertThat(context).getFailure().hasMessageContaining("Database name must not be empty"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
private String grisFsTemplateDatabaseName(AssertableApplicationContext context) {
|
|
|
|
private String grisFsTemplateDatabaseName(AssertableApplicationContext context) {
|
|
|
|
assertThat(context).hasSingleBean(ReactiveGridFsTemplate.class);
|
|
|
|
assertThat(context).hasSingleBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveGridFsTemplate template = context.getBean(ReactiveGridFsTemplate.class);
|
|
|
|
ReactiveMongoDatabaseFactory factory = (ReactiveMongoDatabaseFactory) ReflectionTestUtils.getField(template,
|
|
|
|
GridFSBucket bucket = ((Mono<GridFSBucket>) ReflectionTestUtils.getField(template, "bucketSupplier"))
|
|
|
|
"dbFactory");
|
|
|
|
.block(Duration.ofSeconds(30));
|
|
|
|
return factory.getMongoDatabase().block().getName();
|
|
|
|
MongoCollection<?> collection = (MongoCollection<?>) ReflectionTestUtils.getField(bucket, "filesCollection");
|
|
|
|
|
|
|
|
return collection.getNamespace().getDatabaseName();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|
@Configuration(proxyBeanMethods = false)
|
|
|
|