Search in sources :

Example 1 with MongoClientOptions

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"));
}
Also used : MongoClient(com.mongodb.MongoClient) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MongoClientOptions(com.mongodb.MongoClientOptions) Test(org.junit.Test)

Example 2 with MongoClientOptions

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);
}
Also used : MongoClientOptions(com.mongodb.MongoClientOptions) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 3 with MongoClientOptions

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());
}
Also used : MongoClient(com.mongodb.MongoClient) MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientOptions(com.mongodb.MongoClientOptions) Test(org.junit.Test)

Example 4 with MongoClientOptions

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);
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientOptions(com.mongodb.MongoClientOptions) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 5 with MongoClientOptions

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());
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientOptions(com.mongodb.MongoClientOptions) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Aggregations

MongoClientOptions (com.mongodb.MongoClientOptions)18 MongoClient (com.mongodb.MongoClient)10 Test (org.junit.Test)8 ServerAddress (com.mongodb.ServerAddress)5 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)5 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)5 MongoCredential (com.mongodb.MongoCredential)3 UnknownHostException (java.net.UnknownHostException)2 Document (org.bson.Document)2 DB (com.mongodb.DB)1 MongoClientURI (com.mongodb.MongoClientURI)1 WriteConcern (com.mongodb.WriteConcern)1 MongoDatabase (com.mongodb.client.MongoDatabase)1 GridFS (com.mongodb.gridfs.GridFS)1 ArrayList (java.util.ArrayList)1 SneakyThrows (lombok.SneakyThrows)1 MongoDB (org.apache.jmeter.protocol.mongodb.mongo.MongoDB)1 Authentication (org.cubeengine.module.bigdata.MongoDBConfiguration.Authentication)1 BeforeClass (org.junit.BeforeClass)1 Statement (org.junit.runners.model.Statement)1