Search in sources :

Example 36 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-boot by spring-projects.

the class MongoPropertiesClientSettingsBuilderCustomizerTests method replicaSetCanBeCustomized.

@Test
void replicaSetCanBeCustomized() {
    this.properties.setReplicaSetName("test");
    MongoClientSettings settings = customizeSettings();
    assertThat(settings.getClusterSettings().getRequiredReplicaSetName()).isEqualTo("test");
}
Also used : MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.jupiter.api.Test)

Example 37 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-boot by spring-projects.

the class MongoPropertiesClientSettingsBuilderCustomizerTests method onlyUriSetShouldUseThat.

@Test
void onlyUriSetShouldUseThat() {
    this.properties.setUri("mongodb://mongo1.example.com:12345");
    MongoClientSettings settings = customizeSettings();
    List<ServerAddress> allAddresses = getAllAddresses(settings);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345);
}
Also used : ServerAddress(com.mongodb.ServerAddress) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.jupiter.api.Test)

Example 38 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-boot by spring-projects.

the class MongoPropertiesClientSettingsBuilderCustomizerTests method uriCanBeCustomized.

@Test
void uriCanBeCustomized() {
    this.properties.setUri("mongodb://user:secret@mongo1.example.com:12345,mongo2.example.com:23456/test");
    MongoClientSettings settings = customizeSettings();
    List<ServerAddress> allAddresses = getAllAddresses(settings);
    assertThat(allAddresses).hasSize(2);
    assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345);
    assertServerAddress(allAddresses.get(1), "mongo2.example.com", 23456);
    assertMongoCredential(settings.getCredential(), "user", "secret", "test");
}
Also used : ServerAddress(com.mongodb.ServerAddress) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.jupiter.api.Test)

Example 39 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-boot by spring-projects.

the class MongoPropertiesClientSettingsBuilderCustomizerTests method uriIsIgnoredInEmbeddedMode.

@Test
void uriIsIgnoredInEmbeddedMode() {
    this.properties.setUri("mongodb://mongo.example.com:1234/mydb");
    this.environment.setProperty("local.mongo.port", "4000");
    MongoClientSettings settings = customizeSettings();
    List<ServerAddress> allAddresses = getAllAddresses(settings);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "localhost", 4000);
}
Also used : ServerAddress(com.mongodb.ServerAddress) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.jupiter.api.Test)

Example 40 with MongoClientSettings

use of com.mongodb.MongoClientSettings in project spring-boot by spring-projects.

the class MongoPropertiesClientSettingsBuilderCustomizerTests method onlyHostAndPortSetShouldUseThat.

@Test
void onlyHostAndPortSetShouldUseThat() {
    this.properties.setHost("localhost");
    this.properties.setPort(27017);
    MongoClientSettings settings = customizeSettings();
    List<ServerAddress> allAddresses = getAllAddresses(settings);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "localhost", 27017);
}
Also used : ServerAddress(com.mongodb.ServerAddress) MongoClientSettings(com.mongodb.MongoClientSettings) Test(org.junit.jupiter.api.Test)

Aggregations

MongoClientSettings (com.mongodb.MongoClientSettings)75 Test (org.junit.jupiter.api.Test)24 BsonString (org.bson.BsonString)21 Map (java.util.Map)20 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 Document (org.bson.Document)19 BsonDocument (org.bson.BsonDocument)18 ServerAddress (com.mongodb.ServerAddress)17 AutoEncryptionSettings (com.mongodb.AutoEncryptionSettings)14 Before (org.junit.Before)14 MongoNamespace (com.mongodb.MongoNamespace)13 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)12 ConnectionString (com.mongodb.ConnectionString)12 MongoClientFactoryBean (org.springframework.data.mongodb.core.MongoClientFactoryBean)10 Block (com.mongodb.Block)8 Fixture.getMongoClientSettingsBuilder (com.mongodb.client.Fixture.getMongoClientSettingsBuilder)8 SecureRandom (java.security.SecureRandom)8 TimeUnit (java.util.concurrent.TimeUnit)8 ClusterFixture.isServerlessTest (com.mongodb.ClusterFixture.isServerlessTest)7