Search in sources :

Example 21 with MongoClient

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

the class ReactiveQuerydslMongoPredicateExecutorTests method cleanDb.

@BeforeClass
public static void cleanDb() {
    MongoClient client = MongoTestUtils.reactiveClient();
    MongoTestUtils.createOrReplaceCollectionNow("reactive", "person", client);
    MongoTestUtils.createOrReplaceCollectionNow("reactive", "user", client);
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) BeforeClass(org.junit.BeforeClass)

Example 22 with MongoClient

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

the class ReactiveMongoClientFactoryTests method portCanBeCustomized.

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

Example 23 with MongoClient

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

the class ReactiveMongoClientFactoryTests method uriCanBeCustomized.

@Test
public void uriCanBeCustomized() throws UnknownHostException {
    MongoProperties properties = new MongoProperties();
    properties.setUri("mongodb://user:secret@mongo1.example.com:12345," + "mongo2.example.com:23456/test");
    MongoClient client = createMongoClient(properties);
    List<ServerAddress> allAddresses = extractServerAddresses(client);
    assertThat(allAddresses).hasSize(2);
    assertServerAddress(allAddresses.get(0), "mongo1.example.com", 12345);
    assertServerAddress(allAddresses.get(1), "mongo2.example.com", 23456);
    List<MongoCredential> credentialsList = extractMongoCredentials(client);
    assertThat(credentialsList).hasSize(1);
    assertMongoCredential(credentialsList.get(0), "user", "secret", "test");
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) MongoCredential(com.mongodb.MongoCredential) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 24 with MongoClient

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

the class ReactiveMongoClientFactoryTests method credentialsCanBeCustomized.

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

Example 25 with MongoClient

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

the class ReactiveMongoRepositoriesAutoConfigurationTests method testDefaultRepositoryConfiguration.

@Test
public void testDefaultRepositoryConfiguration() throws Exception {
    prepareApplicationContext(TestConfiguration.class);
    assertThat(this.context.getBean(ReactiveCityRepository.class)).isNotNull();
    MongoClient client = this.context.getBean(MongoClient.class);
    assertThat(client).isInstanceOf(MongoClient.class);
    MongoMappingContext mappingContext = this.context.getBean(MongoMappingContext.class);
    @SuppressWarnings("unchecked") Set<? extends Class<?>> entities = (Set<? extends Class<?>>) ReflectionTestUtils.getField(mappingContext, "initialEntitySet");
    assertThat(entities).hasSize(1);
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) Set(java.util.Set) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) Test(org.junit.Test)

Aggregations

MongoClient (com.mongodb.reactivestreams.client.MongoClient)29 MongoClientSettings (com.mongodb.MongoClientSettings)10 Test (org.junit.Test)10 ServerAddress (com.mongodb.ServerAddress)8 InsertOneResult (com.mongodb.client.result.InsertOneResult)7 Document (org.bson.Document)7 OperationSubscriber (reactivestreams.helpers.SubscriberHelpers.OperationSubscriber)7 MongoClients (com.mongodb.reactivestreams.client.MongoClients)6 ConnectionString (com.mongodb.ConnectionString)5 MongoDatabase (com.mongodb.reactivestreams.client.MongoDatabase)5 CodecRegistry (org.bson.codecs.configuration.CodecRegistry)5 ClusterSettings (com.mongodb.connection.ClusterSettings)4 SecureRandom (java.security.SecureRandom)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 CodecRegistries.fromProviders (org.bson.codecs.configuration.CodecRegistries.fromProviders)4 CodecRegistries.fromRegistries (org.bson.codecs.configuration.CodecRegistries.fromRegistries)4 PojoCodecProvider (org.bson.codecs.pojo.PojoCodecProvider)4 ClientEncryptionSettings (com.mongodb.ClientEncryptionSettings)3 MongoCredential (com.mongodb.MongoCredential)3