Search in sources :

Example 71 with MongoClient

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

the class MongoClientFactoryTests method credentialsCanBeCustomized.

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

Example 72 with MongoClient

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

the class MongoClientFactoryTests method portCanBeCustomized.

@Test
public void portCanBeCustomized() {
    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.MongoClient) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Example 73 with MongoClient

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

the class MongoClientFactoryTests method databaseCanBeCustomized.

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

Example 74 with MongoClient

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

the class MongoClientFactoryTests method authenticationDatabaseCanBeCustomized.

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

Example 75 with MongoClient

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

the class MongoClientFactoryTests method hostCanBeCustomized.

@Test
public void hostCanBeCustomized() {
    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.MongoClient) ServerAddress(com.mongodb.ServerAddress) Test(org.junit.Test)

Aggregations

MongoClient (com.mongodb.MongoClient)126 Test (org.junit.Test)31 MongoClientURI (com.mongodb.MongoClientURI)29 Document (org.bson.Document)26 ServerAddress (com.mongodb.ServerAddress)21 MongoDatabase (com.mongodb.client.MongoDatabase)21 Before (org.junit.Before)20 BasicDBObject (com.mongodb.BasicDBObject)11 ArrayList (java.util.ArrayList)11 MongoCredential (com.mongodb.MongoCredential)9 MongoException (com.mongodb.MongoException)8 DB (com.mongodb.DB)7 DBCollection (com.mongodb.DBCollection)7 UnknownHostException (java.net.UnknownHostException)7 MongoTemplate (org.springframework.data.mongodb.core.MongoTemplate)7 DBObject (com.mongodb.DBObject)6 MongoClientOptions (com.mongodb.MongoClientOptions)6 IOException (java.io.IOException)5 List (java.util.List)5 MongoDbFactory (org.springframework.data.mongodb.MongoDbFactory)5