Search in sources :

Example 1 with MongoClientFactoryBean

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

the class MongoClientNamespaceTests method clientWithReplicaSet.

// DATAMONGO-2384
@Test
public void clientWithReplicaSet() {
    assertThat(ctx.containsBean("client-with-replica-set")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-replica-set", MongoClientFactoryBean.class);
    assertThat(getField(factoryBean, "host")).isNull();
    assertThat(getField(factoryBean, "port")).isNull();
    assertThat(getField(factoryBean, "connectionString")).isNull();
    assertThat(getField(factoryBean, "credential")).isNull();
    assertThat(getField(factoryBean, "replicaSet")).isEqualTo("rs0");
    assertThat(getField(factoryBean, "mongoClientSettings")).isNull();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) Test(org.junit.Test)

Example 2 with MongoClientFactoryBean

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

the class MongoClientNamespaceTests method clientWithServerVersion.

// GH-3820
@Test
public void clientWithServerVersion() {
    assertThat(ctx.containsBean("client-with-server-api-settings")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-server-api-settings", MongoClientFactoryBean.class);
    MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
    assertThat(settings.getServerApi()).isNotNull().satisfies(it -> {
        assertThat(it.getVersion()).isEqualTo(ServerApiVersion.V1);
    });
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 3 with MongoClientFactoryBean

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

the class MongoNamespaceTests method testMongoSingletonWithSslEnabledAndCustomSslSocketFactory.

// DATAMONGO-764
@Test
public void testMongoSingletonWithSslEnabledAndCustomSslSocketFactory() throws Exception {
    assertThat(ctx.containsBean("mongoSslWithCustomSslFactory")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSslWithCustomSslFactory");
    MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
    assertThat(options.getSslSettings().getContext().getSocketFactory() instanceof SSLSocketFactory).as("socketFactory should be a SSLSocketFactory").isTrue();
    assertThat(options.getSslSettings().getContext().getProvider().getName()).isEqualTo("SunJSSE");
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 4 with MongoClientFactoryBean

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

the class MongoNamespaceTests method testMongoClientSingletonWithSslEnabled.

// DATAMONGO-1490
@Test
public void testMongoClientSingletonWithSslEnabled() {
    assertThat(ctx.containsBean("mongoClientSsl")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClientSsl");
    MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
    assertThat(options.getSslSettings().getContext().getSocketFactory() instanceof SSLSocketFactory).as("socketFactory should be a SSLSocketFactory").isTrue();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) SSLSocketFactory(javax.net.ssl.SSLSocketFactory) Test(org.junit.Test)

Example 5 with MongoClientFactoryBean

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

the class MongoNamespaceTests method testMongoSingletonWithPropertyPlaceHolders.

@Test
public void testMongoSingletonWithPropertyPlaceHolders() {
    assertThat(ctx.containsBean("mongoClient")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoClient");
    String host = (String) getField(mfb, "host");
    Integer port = (Integer) getField(mfb, "port");
    assertThat(host).isEqualTo("127.0.0.1");
    assertThat(port).isEqualTo(new Integer(27017));
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)16 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)16 MongoClientSettings (com.mongodb.MongoClientSettings)10 ServerAddress (com.mongodb.ServerAddress)3 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)3 ConnectionString (com.mongodb.ConnectionString)1 ArrayList (java.util.ArrayList)1