Search in sources :

Example 6 with MongoClientFactoryBean

use of org.springframework.data.mongodb.core.MongoClientFactoryBean in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoSingleton.

@Test
public void testMongoSingleton() throws Exception {
    assertTrue(ctx.containsBean("noAttrMongo"));
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&noAttrMongo");
    assertNull(getField(mfb, "host"));
    assertNull(getField(mfb, "port"));
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) Test(org.junit.Test)

Example 7 with MongoClientFactoryBean

use of org.springframework.data.mongodb.core.MongoClientFactoryBean in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoSingletonWithSslEnabled.

// DATAMONGO-764
@Test
public void testMongoSingletonWithSslEnabled() throws Exception {
    assertTrue(ctx.containsBean("mongoSsl"));
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSsl");
    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 8 with MongoClientFactoryBean

use of org.springframework.data.mongodb.core.MongoClientFactoryBean in project spring-data-mongodb by spring-projects.

the class MongoNamespaceTests method testMongoSingletonWithAttributes.

@Test
public void testMongoSingletonWithAttributes() throws Exception {
    assertTrue(ctx.containsBean("defaultMongo"));
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&defaultMongo");
    String host = (String) getField(mfb, "host");
    Integer port = (Integer) getField(mfb, "port");
    assertEquals("localhost", host);
    assertEquals(new Integer(27017), port);
    MongoClientOptions options = (MongoClientOptions) getField(mfb, "mongoClientOptions");
    assertFalse("By default socketFactory should not 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)

Aggregations

Test (org.junit.Test)8 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)8 MongoClientOptions (com.mongodb.MongoClientOptions)5 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)4 ServerAddress (com.mongodb.ServerAddress)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 MongoClient (com.mongodb.MongoClient)1