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);
}
}
}
Aggregations