org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration Java Examples

The following examples show how to use org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MongoTracingAutoConfigurationTest.java    From java-spring-cloud with Apache License 2.0 5 votes vote down vote up
@Test
public void createsTracingPostProcessorWhenAutoConfigured() {
  final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
      .withPropertyValues("spring.data.mongodb.port=27017") // Otherwise a random embedded mongo port is used
      .withConfiguration(AutoConfigurations.of(
          MongoTracingAutoConfiguration.class,
          TracerAutoConfiguration.class,
          MongoAutoConfiguration.class,
          EmbeddedMongoAutoConfiguration.class
      ));

  contextRunner.run(context -> Assertions.assertThat(context).hasSingleBean(TracingMongoClientPostProcessor.class));
}
 
Example #2
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldDoNothingIfDisabled() {
    TestPropertyValues.of("mongeez.enabled:false").applyTo(this.context);
    registerAndRefresh(MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
    assumeThat(this.context.getBeanNamesForType(Mongo.class), not(emptyArray()));
    assertThat(this.context.getBeanNamesForType(Mongeez.class), emptyArray());
}
 
Example #3
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUseDatabaseFromMongoProperties() {
    String database = "foo";
    TestPropertyValues.of("spring.data.mongodb.database:" + database).applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
    Mongeez mongeez = this.context.getBean(Mongeez.class);
    Object mongeezDatabase = ReflectionTestUtils.getField(mongeez, "dbName");
    assertThat(mongeezDatabase.toString(), equalTo(database));
}
 
Example #4
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUseDatabaseOverrideFromMongeezProperties() {
    String mongoDatabase = "foo";
    String mongeezOverrideDatabase = "bar";
    TestPropertyValues.of("spring.data.mongodb.database:" + mongoDatabase)
        .and("mongeez.database:" + mongeezOverrideDatabase)
        .applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
    Mongeez mongeez = this.context.getBean(Mongeez.class);
    Object mongeezActualDatabase = ReflectionTestUtils.getField(mongeez, "dbName");
    assertThat(mongeezActualDatabase.toString(), equalTo(mongeezOverrideDatabase));
}
 
Example #5
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUseAuthenticationDatabaseFromMongoProperties() {
    String database = "foo";
    TestPropertyValues.of("spring.data.mongodb.authenticationDatabase:" + database)
        .and("mongeez.username:user")
        .and("mongeez.password:pass")
        .applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
    Mongeez mongeez = this.context.getBean(Mongeez.class);
    MongoAuth auth = (MongoAuth) ReflectionTestUtils.getField(mongeez, "auth");
    assertThat(auth.getAuthDb(), equalTo(database));
}
 
Example #6
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldUseAuthenticationDatabaseOverrideFromMongeezProperties() {
    String database = "foo";
    String mongeezOverrideDatabase = "bar";
    TestPropertyValues.of("spring.data.mongodb.authenticationDatabase:" + database)
        .and("mongeez.authenticationDatabase:" + mongeezOverrideDatabase)
        .and("mongeez.username:user")
        .and("mongeez.password:pass")
        .applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
    Mongeez mongeez = this.context.getBean(Mongeez.class);
    MongoAuth auth = (MongoAuth) ReflectionTestUtils.getField(mongeez, "auth");
    assertThat(auth.getAuthDb(), equalTo(mongeezOverrideDatabase));
}
 
Example #7
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 5 votes vote down vote up
@Test(expected = BeanCreationException.class)
public void shouldFailIfOnlyMongoCredentialsProvided() {
    String mongoUsername = "foo";
    String mongoPassword = "bar";
    TestPropertyValues.of("spring.data.mongodb.username:" + mongoUsername)
        .and("spring.data.mongodb.password:" + mongoPassword)
        .applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
}
 
Example #8
Source File: MongeezAutoConfigurationTests.java    From mongeez-spring-boot-starter with Apache License 2.0 4 votes vote down vote up
@Test(expected = BeanCreationException.class)
public void shouldFailIfLocationDoesNotExist() {
    TestPropertyValues.of("mongeez.location:does/not/exist").applyTo(this.context);
    registerAndRefresh(DoNotExecuteMongeezPostProcessor.class,
            MongoAutoConfiguration.class, MongeezAutoConfiguration.class);
}