Search in sources :

Example 1 with MongoClient

use of com.mongodb.reactivestreams.client.MongoClient in project spring-boot by spring-projects.

the class ReactiveMongoRepositoriesAutoConfigurationTests method testNoRepositoryConfiguration.

@Test
public void testNoRepositoryConfiguration() throws Exception {
    prepareApplicationContext(EmptyConfiguration.class);
    MongoClient client = this.context.getBean(MongoClient.class);
    assertThat(client).isInstanceOf(MongoClient.class);
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) Test(org.junit.Test)

Example 2 with MongoClient

use of com.mongodb.reactivestreams.client.MongoClient in project spring-boot by spring-projects.

the class ReactiveMongoAutoConfigurationTests 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, ReactiveMongoAutoConfiguration.class);
    this.context.refresh();
    MongoClient mongo = this.context.getBean(MongoClient.class);
    MongoClientSettings settings = mongo.getSettings();
    assertThat(settings.getApplicationName()).isEqualTo("test-config");
    assertThat(settings.getStreamFactoryFactory()).isSameAs(this.context.getBean("myStreamFactoryFactory"));
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) MongoClientSettings(com.mongodb.async.client.MongoClientSettings) Test(org.junit.Test)

Example 3 with MongoClient

use of com.mongodb.reactivestreams.client.MongoClient in project spring-boot by spring-projects.

the class ReactiveMongoClientFactoryTests method authenticationDatabaseCanBeCustomized.

@Test
public void authenticationDatabaseCanBeCustomized() throws UnknownHostException {
    MongoProperties properties = new MongoProperties();
    properties.setAuthenticationDatabase("foo");
    properties.setUsername("user");
    properties.setPassword("secret".toCharArray());
    MongoClient client = createMongoClient(properties);
    assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", "foo");
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) Test(org.junit.Test)

Example 4 with MongoClient

use of com.mongodb.reactivestreams.client.MongoClient in project spring-boot by spring-projects.

the class ReactiveMongoClientFactoryTests method databaseCanBeCustomized.

@Test
public void databaseCanBeCustomized() throws UnknownHostException {
    MongoProperties properties = new MongoProperties();
    properties.setDatabase("foo");
    properties.setUsername("user");
    properties.setPassword("secret".toCharArray());
    MongoClient client = createMongoClient(properties);
    assertMongoCredential(extractMongoCredentials(client).get(0), "user", "secret", "foo");
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) Test(org.junit.Test)

Example 5 with MongoClient

use of com.mongodb.reactivestreams.client.MongoClient in project spring-boot by spring-projects.

the class ReactiveMongoClientFactoryTests method hostCanBeCustomized.

@Test
public void hostCanBeCustomized() throws UnknownHostException {
    MongoProperties properties = new MongoProperties();
    properties.setHost("mongo.example.com");
    MongoClient client = createMongoClient(properties);
    List<ServerAddress> allAddresses = extractServerAddresses(client);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "mongo.example.com", 27017);
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Aggregations

MongoClient (com.mongodb.reactivestreams.client.MongoClient)20 Test (org.junit.Test)10 InsertOneResult (com.mongodb.client.result.InsertOneResult)7 Document (org.bson.Document)7 OperationSubscriber (reactivestreams.helpers.SubscriberHelpers.OperationSubscriber)7 MongoClientSettings (com.mongodb.MongoClientSettings)6 ServerAddress (com.mongodb.ServerAddress)4 SecureRandom (java.security.SecureRandom)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)3 ConnectionString (com.mongodb.ConnectionString)3 MongoNamespace (com.mongodb.MongoNamespace)3 DataKeyOptions (com.mongodb.client.model.vault.DataKeyOptions)3 MongoDatabase (com.mongodb.reactivestreams.client.MongoDatabase)3 BsonBinary (org.bson.BsonBinary)3 BsonString (org.bson.BsonString)3 PrintDocumentSubscriber (reactivestreams.helpers.SubscriberHelpers.PrintDocumentSubscriber)3 AutoEncryptionSettings (com.mongodb.AutoEncryptionSettings)2 IndexOptions (com.mongodb.client.model.IndexOptions)2