Search in sources :

Example 6 with MongoClient

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

the class ReactiveMongoClientFactoryTests method uriIsIgnoredInEmbeddedMode.

@Test
public void uriIsIgnoredInEmbeddedMode() throws UnknownHostException {
    MongoProperties properties = new MongoProperties();
    properties.setUri("mongodb://mongo.example.com:1234/mydb");
    this.environment.setProperty("local.mongo.port", "4000");
    MongoClient client = createMongoClient(properties, this.environment);
    List<ServerAddress> allAddresses = extractServerAddresses(client);
    assertThat(allAddresses).hasSize(1);
    assertServerAddress(allAddresses.get(0), "localhost", 4000);
}
Also used : MongoClient(com.mongodb.reactivestreams.client.MongoClient) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 7 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 8 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 9 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 10 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)10 Test (org.junit.Test)10 ServerAddress (com.mongodb.ServerAddress)4 MongoCredential (com.mongodb.MongoCredential)1 MongoClientSettings (com.mongodb.async.client.MongoClientSettings)1 Set (java.util.Set)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1