use of org.springframework.data.mongodb.core.MongoTemplate in project spring-boot by spring-projects.
the class MongoDataAutoConfigurationTests method customConversions.
@Test
public void customConversions() throws Exception {
this.context = new AnnotationConfigApplicationContext();
this.context.register(CustomConversionsConfig.class);
this.context.register(PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class, MongoDataAutoConfiguration.class);
this.context.refresh();
MongoTemplate template = this.context.getBean(MongoTemplate.class);
assertThat(template.getConverter().getConversionService().canConvert(Mongo.class, Boolean.class)).isTrue();
}
use of org.springframework.data.mongodb.core.MongoTemplate in project spring-boot by spring-projects.
the class MongoHealthIndicatorTests method mongoIsUp.
@Test
public void mongoIsUp() throws Exception {
Document commandResult = mock(Document.class);
given(commandResult.getString("version")).willReturn("2.6.4");
MongoTemplate mongoTemplate = mock(MongoTemplate.class);
given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willReturn(commandResult);
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.UP);
assertThat(health.getDetails().get("version")).isEqualTo("2.6.4");
verify(commandResult).getString("version");
verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
}
use of org.springframework.data.mongodb.core.MongoTemplate in project spring-boot by spring-projects.
the class EmbeddedMongoAutoConfigurationTests method assertVersionConfiguration.
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);
Document buildInfo = mongo.executeCommand("{ buildInfo: 1 }");
assertThat(buildInfo.getString("version")).isEqualTo(expectedVersion);
}
use of org.springframework.data.mongodb.core.MongoTemplate in project spring-boot by spring-projects.
the class MongoHealthIndicatorTests method mongoIsDown.
@Test
public void mongoIsDown() throws Exception {
MongoTemplate mongoTemplate = mock(MongoTemplate.class);
given(mongoTemplate.executeCommand("{ buildInfo: 1 }")).willThrow(new MongoException("Connection failed"));
MongoHealthIndicator healthIndicator = new MongoHealthIndicator(mongoTemplate);
Health health = healthIndicator.health();
assertThat(health.getStatus()).isEqualTo(Status.DOWN);
assertThat((String) health.getDetails().get("error")).contains("Connection failed");
verify(mongoTemplate).executeCommand("{ buildInfo: 1 }");
}
Aggregations