Search in sources :

Example 1 with GridFsTemplate

use of org.springframework.data.mongodb.gridfs.GridFsTemplate 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");
    });
}
Also used : MongoDatabaseFactory(org.springframework.data.mongodb.MongoDatabaseFactory) GridFsTemplate(org.springframework.data.mongodb.gridfs.GridFsTemplate) Test(org.junit.jupiter.api.Test)

Example 2 with GridFsTemplate

use of org.springframework.data.mongodb.gridfs.GridFsTemplate in project spring-boot by spring-projects.

the class MongoDataAutoConfigurationTests method whenGridFsBucketIsConfiguredThenGridFsTemplateIsAutoConfiguredAndUsesIt.

@Test
void whenGridFsBucketIsConfiguredThenGridFsTemplateIsAutoConfiguredAndUsesIt() {
    this.contextRunner.withPropertyValues("spring.data.mongodb.gridfs.bucket:test-bucket").run((context) -> {
        assertThat(context).hasSingleBean(GridFsTemplate.class);
        GridFsTemplate template = context.getBean(GridFsTemplate.class);
        assertThat(template).hasFieldOrPropertyWithValue("bucket", "test-bucket");
    });
}
Also used : GridFsTemplate(org.springframework.data.mongodb.gridfs.GridFsTemplate) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 GridFsTemplate (org.springframework.data.mongodb.gridfs.GridFsTemplate)2 MongoDatabaseFactory (org.springframework.data.mongodb.MongoDatabaseFactory)1