Search in sources :

Example 11 with MongoClientFactoryBean

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

the class MongoClientNamespaceTests method clientWithConnectionPoolSettings.

// DATAMONGO-2384
@Test
public void clientWithConnectionPoolSettings() {
    assertThat(ctx.containsBean("client-with-connection-pool-settings")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-connection-pool-settings", MongoClientFactoryBean.class);
    MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
    assertThat(settings.getConnectionPoolSettings().getMaxConnectionLifeTime(TimeUnit.MILLISECONDS)).isEqualTo(10);
    assertThat(settings.getConnectionPoolSettings().getMinSize()).isEqualTo(10);
    assertThat(settings.getConnectionPoolSettings().getMaxSize()).isEqualTo(20);
    assertThat(settings.getConnectionPoolSettings().getMaintenanceFrequency(TimeUnit.MILLISECONDS)).isEqualTo(10);
    assertThat(settings.getConnectionPoolSettings().getMaintenanceInitialDelay(TimeUnit.MILLISECONDS)).isEqualTo(11);
    assertThat(settings.getConnectionPoolSettings().getMaxConnectionIdleTime(TimeUnit.MILLISECONDS)).isEqualTo(30);
    assertThat(settings.getConnectionPoolSettings().getMaxWaitTime(TimeUnit.MILLISECONDS)).isEqualTo(15);
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 12 with MongoClientFactoryBean

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

the class MongoClientNamespaceTests method clientWithUUidSettings.

// DATAMONGO-2427
@Test
public void clientWithUUidSettings() {
    assertThat(ctx.containsBean("client-with-uuid-settings")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-uuid-settings", MongoClientFactoryBean.class);
    MongoClientSettings settings = (MongoClientSettings) getField(factoryBean, "mongoClientSettings");
    assertThat(settings.getUuidRepresentation()).isEqualTo(UuidRepresentation.STANDARD);
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 13 with MongoClientFactoryBean

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

the class MongoClientNamespaceTests method clientWithConnectionString.

// DATAMONGO-2384
@Test
public void clientWithConnectionString() {
    assertThat(ctx.containsBean("client-with-connection-string")).isTrue();
    MongoClientFactoryBean factoryBean = ctx.getBean("&client-with-connection-string", MongoClientFactoryBean.class);
    assertThat(getField(factoryBean, "host")).isNull();
    assertThat(getField(factoryBean, "port")).isNull();
    assertThat(getField(factoryBean, "connectionString")).isEqualTo(new ConnectionString("mongodb://127.0.0.1:27017/?replicaSet=rs0"));
    assertThat(getField(factoryBean, "credential")).isNull();
    assertThat(getField(factoryBean, "replicaSet")).isNull();
    assertThat(getField(factoryBean, "mongoClientSettings")).isNull();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) ConnectionString(com.mongodb.ConnectionString) Test(org.junit.Test)

Example 14 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 {
    assertThat(ctx.containsBean("defaultMongo")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&defaultMongo");
    String host = (String) getField(mfb, "host");
    Integer port = (Integer) getField(mfb, "port");
    assertThat(host).isEqualTo("localhost");
    assertThat(port).isEqualTo(new Integer(27017));
    MongoClientSettings options = (MongoClientSettings) getField(mfb, "mongoClientSettings");
    assertThat(options).isNull();
}
Also used : MongoClientFactoryBean(org.springframework.data.mongodb.core.MongoClientFactoryBean) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.Test)

Example 15 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 {
    assertThat(ctx.containsBean("mongoSsl")).isTrue();
    MongoClientFactoryBean mfb = (MongoClientFactoryBean) ctx.getBean("&mongoSsl");
    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)

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