Search in sources :

Example 6 with ConnectionString

use of com.mongodb.ConnectionString in project mongo-java-driver by mongodb.

the class ConnectionStringTest method testValidOptions.

private void testValidOptions() {
    ConnectionString connectionString = null;
    try {
        connectionString = new ConnectionString(input);
    } catch (Throwable t) {
        assertTrue(String.format("Connection string '%s' should not have throw an exception: %s", input, t.toString()), false);
    }
    for (Map.Entry<String, BsonValue> option : definition.getDocument("options").entrySet()) {
        if (option.getKey().equals("authmechanism")) {
            String expected = option.getValue().asString().getValue();
            String actual = connectionString.getCredentialList().get(0).getAuthenticationMechanism().getMechanismName();
            assertEquals(expected, actual);
        } else if (option.getKey().equals("replicaset")) {
            String expected = option.getValue().asString().getValue();
            assertEquals(expected, connectionString.getRequiredReplicaSetName());
        } else if (option.getKey().equals("wtimeoutms")) {
            int expected = option.getValue().asInt32().getValue();
            assertEquals(expected, connectionString.getWriteConcern().getWTimeout(TimeUnit.MILLISECONDS).intValue());
        } else {
            assertTrue(String.format("Unsupported option '%s' in '%s'", option.getKey(), input), false);
        }
    }
}
Also used : ConnectionString(com.mongodb.ConnectionString) ConnectionString(com.mongodb.ConnectionString) Map(java.util.Map) BsonValue(org.bson.BsonValue)

Aggregations

ConnectionString (com.mongodb.ConnectionString)6 MongoCredential (com.mongodb.MongoCredential)2 AuthenticationMechanism (com.mongodb.AuthenticationMechanism)1 ServerAddress (com.mongodb.ServerAddress)1 Builder (com.mongodb.async.client.MongoClientSettings.Builder)1 ClusterSettings (com.mongodb.connection.ClusterSettings)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 BsonValue (org.bson.BsonValue)1