use of org.springframework.data.mongodb.MongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoServiceConnectorCreatorTest method cloudMongoCreationWithMultipleHostsByUri.
@Test
public void cloudMongoCreationWithMultipleHostsByUri() throws Exception {
String uri = String.format("%s://%s:%s@%s:%s/%s", MONGODB_SCHEME, TEST_USERNAME, TEST_PASSWORD, StringUtils.arrayToDelimitedString(TEST_HOSTS, ","), TEST_PORT, TEST_DB);
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", uri);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertNotNull(mongoDbFactory);
MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
assertNotNull(mongo);
List<ServerAddress> addresses = extractServerAddresses(mongo);
assertEquals(3, addresses.size());
MongoCredential credentials = mongo.getCredentialsList().get(0);
assertEquals(TEST_USERNAME, credentials.getUserName());
assertNotNull(credentials.getPassword());
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(TEST_DB, ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
ServerAddress address1 = addresses.get(0);
assertEquals(TEST_HOST, address1.getHost());
assertEquals(TEST_PORT_DEFAULT, address1.getPort());
ServerAddress address2 = addresses.get(1);
assertEquals(TEST_HOST_1, address2.getHost());
assertEquals(TEST_PORT_DEFAULT, address2.getPort());
ServerAddress address3 = addresses.get(2);
assertEquals(TEST_HOST_2, address3.getHost());
assertEquals(TEST_PORT, address3.getPort());
}
use of org.springframework.data.mongodb.MongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryXmlConfigTest method withConfigAllOptionsSpecifiedWriteConcernSafe.
@Test
public void withConfigAllOptionsSpecifiedWriteConcernSafe() {
ApplicationContext testContext = getTestApplicationContext("cloud-mongo-with-config.xml", createService("my-service"));
MongoDbFactory connector = testContext.getBean("service-maxWait200-connectionPerHost50-WriteConcernSafe", getConnectorType());
MongoDbFactoryCloudConfigTestHelper.assertConfigProperties(connector, "safe", 50, 200);
}
use of org.springframework.data.mongodb.MongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryXmlConfigTest method withConfigAllOptionsSpecifiedWriteConcernNone.
@Test
public void withConfigAllOptionsSpecifiedWriteConcernNone() {
ApplicationContext testContext = getTestApplicationContext("cloud-mongo-with-config.xml", createService("my-service"));
MongoDbFactory connector = testContext.getBean("service-connectionPerHost50-maxWait200-WriteConcernNone", getConnectorType());
MongoDbFactoryCloudConfigTestHelper.assertConfigProperties(connector, "none", 50, 200);
}
use of org.springframework.data.mongodb.MongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoDbFactoryXmlConfigTest method withConfigOnlyMaxWaitSpecified.
@Test
public void withConfigOnlyMaxWaitSpecified() {
ApplicationContext testContext = getTestApplicationContext("cloud-mongo-with-config.xml", createService("my-service"));
MongoDbFactory connector = testContext.getBean("service-maxWait200-connectionPerHostUnspecified-WriteConcernUnspecified", getConnectorType());
MongoDbFactoryCloudConfigTestHelper.assertConfigProperties(connector, null, null, 200);
}
use of org.springframework.data.mongodb.MongoDbFactory in project spring-cloud-connectors by spring-cloud.
the class MongoServiceConnectorCreatorTest method cloudMongoCreationNoConfig.
@Test
public void cloudMongoCreationNoConfig() throws Exception {
MongoServiceInfo serviceInfo = new MongoServiceInfo("id", TEST_HOST, TEST_PORT, TEST_USERNAME, TEST_PASSWORD, TEST_DB);
MongoDbFactory mongoDbFactory = testCreator.create(serviceInfo, null);
assertNotNull(mongoDbFactory);
MongoClient mongo = (MongoClient) ReflectionTestUtils.getField(mongoDbFactory, "mongo");
assertNotNull(mongo);
MongoCredential credentials = mongo.getCredentialsList().get(0);
List<ServerAddress> addresses = extractServerAddresses(mongo);
assertEquals(1, addresses.size());
ServerAddress address = addresses.get(0);
assertEquals(serviceInfo.getHost(), address.getHost());
assertEquals(serviceInfo.getPort(), address.getPort());
assertEquals(serviceInfo.getUserName(), credentials.getUserName());
assertNotNull(credentials.getPassword());
// Don't do connector.getDatabase().getName() as that will try to initiate the connection
assertEquals(serviceInfo.getDatabase(), ReflectionTestUtils.getField(mongoDbFactory, "databaseName"));
}
Aggregations