private void assertVersionConfiguration(String configuredVersion, String expectedVersion) { this.context = new AnnotationConfigApplicationContext(); int mongoPort = SocketUtils.findAvailableTcpPort(); EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort); if (configuredVersion != null) { EnvironmentTestUtils.addEnvironment(this.context, "spring.mongodb.embedded.version=" + configuredVersion); } this.context.register(MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class); this.context.refresh(); MongoTemplate mongo = this.context.getBean(MongoTemplate.class); CommandResult buildInfo = mongo.executeCommand("{ buildInfo: 1 }"); assertThat(buildInfo.getString("version")).isEqualTo(expectedVersion); }
private void assertVersionConfiguration(String configuredVersion, String expectedVersion) { this.context = new AnnotationConfigApplicationContext(); int mongoPort = SocketUtils.findAvailableTcpPort(); EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.port=" + mongoPort); if (configuredVersion != null) { EnvironmentTestUtils.addEnvironment(this.context, "spring.mongodb.embedded.version=" + configuredVersion); } this.context.register(MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EmbeddedMongoAutoConfiguration.class); this.context.refresh(); MongoTemplate mongo = this.context.getBean(MongoTemplate.class); CommandResult buildInfo = mongo.executeCommand("{ buildInfo: 1 }"); assertThat(buildInfo.getString("version"), equalTo(expectedVersion)); }
@Test public void mongoHealthIndicator() { this.context.register(MongoAutoConfiguration.class, ManagementServerProperties.class, MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().getClass()) .isEqualTo(MongoHealthIndicator.class); }
@Test public void notMongoHealthIndicator() { this.context.register(MongoAutoConfiguration.class, ManagementServerProperties.class, MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.mongo.enabled:false", "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(1); assertThat(beans.values().iterator().next().getClass()) .isEqualTo(ApplicationHealthIndicator.class); }
@Test public void combinedHealthIndicator() { this.context.register(MongoAutoConfiguration.class, RedisAutoConfiguration.class, MongoDataAutoConfiguration.class, SolrAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertThat(beans).hasSize(4); }
@Test public void indicatorExists() { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); assertThat(this.context.getBeanNamesForType(MongoTemplate.class).length) .isEqualTo(1); MongoHealthIndicator healthIndicator = this.context .getBean(MongoHealthIndicator.class); assertThat(healthIndicator).isNotNull(); }
@Test public void mongoSessionStore() { load(Arrays.asList(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class), "spring.session.store-type=mongo", "spring.data.mongodb.port=0"); validateSessionRepository(MongoOperationsSessionRepository.class); }
@Test public void mongoSessionStoreWithCustomizations() { load(Arrays.asList(EmbeddedMongoAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class), "spring.session.store-type=mongo", "spring.data.mongodb.port=0", "spring.session.mongo.collection-name=foobar"); MongoOperationsSessionRepository repository = validateSessionRepository( MongoOperationsSessionRepository.class); assertThat(new DirectFieldAccessor(repository).getPropertyValue("collectionName")) .isEqualTo("foobar"); }
@Test public void mongoHealthIndicator() { this.context.register(MongoAutoConfiguration.class, ManagementServerProperties.class, MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); assertEquals(MongoHealthIndicator.class, beans.values().iterator().next().getClass()); }
@Test public void notMongoHealthIndicator() { this.context.register(MongoAutoConfiguration.class, ManagementServerProperties.class, MongoDataAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); EnvironmentTestUtils.addEnvironment(this.context, "management.health.mongo.enabled:false", "management.health.diskspace.enabled:false"); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(1, beans.size()); assertEquals(ApplicationHealthIndicator.class, beans.values().iterator().next().getClass()); }
@Test public void combinedHealthIndicator() { this.context.register(MongoAutoConfiguration.class, RedisAutoConfiguration.class, MongoDataAutoConfiguration.class, SolrAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); this.context.refresh(); Map<String, HealthIndicator> beans = this.context .getBeansOfType(HealthIndicator.class); assertEquals(4, beans.size()); }
@Test public void indicatorExists() { this.context = new AnnotationConfigApplicationContext( PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class, EndpointAutoConfiguration.class, HealthIndicatorAutoConfiguration.class); assertEquals(1, this.context.getBeanNamesForType(MongoTemplate.class).length); MongoHealthIndicator healthIndicator = this.context .getBean(MongoHealthIndicator.class); assertNotNull(healthIndicator); }