use of com.mongodb.MongoClientOptions in project spring-boot by spring-projects.
the class MongoAutoConfigurationTests method optionsSslConfig.
@Test
public void optionsSslConfig() {
this.context = new AnnotationConfigApplicationContext();
EnvironmentTestUtils.addEnvironment(this.context, "spring.data.mongodb.uri:mongodb://localhost/test");
this.context.register(SslOptionsConfig.class, PropertyPlaceholderAutoConfiguration.class, MongoAutoConfiguration.class);
this.context.refresh();
MongoClient mongo = this.context.getBean(MongoClient.class);
MongoClientOptions options = mongo.getMongoClientOptions();
assertThat(options.isSslEnabled()).isTrue();
assertThat(options.getSocketFactory()).isSameAs(this.context.getBean("mySocketFactory"));
}
use of com.mongodb.MongoClientOptions in project spring-data-mongodb by spring-projects.
the class MongoOptionsFactoryBeanUnitTests method testSslConnection.
// DATAMONGO-764
@Test
public void testSslConnection() throws Exception {
MongoClientOptionsFactoryBean bean = new MongoClientOptionsFactoryBean();
bean.setSsl(true);
bean.afterPropertiesSet();
MongoClientOptions options = bean.getObject();
assertNotNull(options.getSocketFactory());
assertTrue(options.getSocketFactory() instanceof SSLSocketFactory);
}
use of com.mongodb.MongoClientOptions in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testMongoSingletonWithPropertyPlaceHolders.
@Test
@SuppressWarnings("deprecation")
public void testMongoSingletonWithPropertyPlaceHolders() throws Exception {
assertTrue(ctx.containsBean("mongoClient"));
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClient");
String host = (String) getField(mfb, "host");
Integer port = (Integer) getField(mfb, "port");
assertEquals("127.0.0.1", host);
assertEquals(new Integer(27017), port);
MongoClient mongo = mfb.getObject();
MongoClientOptions mongoOpts = mongo.getMongoClientOptions();
assertEquals(8, mongoOpts.getConnectionsPerHost());
assertEquals(1000, mongoOpts.getConnectTimeout());
assertEquals(1500, mongoOpts.getMaxWaitTime());
assertEquals(1500, mongoOpts.getSocketTimeout());
assertEquals(4, mongoOpts.getThreadsAllowedToBlockForConnectionMultiplier());
// TODO: check the damned defaults
// assertEquals("w", mongoOpts.getWriteConcern().getW());
// assertEquals(0, mongoOpts.getWriteConcern().getWtimeout());
// assertEquals(true, mongoOpts.getWriteConcern().fsync());
}
use of com.mongodb.MongoClientOptions in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testMongoClientSingletonWithSslEnabled.
// DATAMONGO-1490
@Test
public void testMongoClientSingletonWithSslEnabled() {
assertTrue(ctx.containsBean("mongoClientSsl"));
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClientSsl");
MongoClientOptions options = (MongoClientOptions) getField(mfb, "mongoClientOptions");
assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
}
use of com.mongodb.MongoClientOptions in project spring-data-mongodb by spring-projects.
the class MongoNamespaceTests method testMongoSingletonWithSslEnabledAndCustomSslSocketFactory.
// DATAMONGO-764
@Test
public void testMongoSingletonWithSslEnabledAndCustomSslSocketFactory() throws Exception {
assertTrue(ctx.containsBean("mongoSslWithCustomSslFactory"));
MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSslWithCustomSslFactory");
SSLSocketFactory customSslSocketFactory = ctx.getBean("customSslSocketFactory", SSLSocketFactory.class);
MongoClientOptions options = (MongoClientOptions) getField(mfb, "mongoClientOptions");
assertTrue("socketFactory should be a SSLSocketFactory", options.getSocketFactory() instanceof SSLSocketFactory);
assertSame(customSslSocketFactory, options.getSocketFactory());
}
Aggregations