use of org.springframework.cloud.service.common.MongoServiceInfo in project jhipster-sample-app-mongodb by jhipster.
the class CloudDatabaseConfiguration method mongobee.
@Bean
public Mongobee mongobee(MongoDbFactory mongoDbFactory, MongoTemplate mongoTemplate, Cloud cloud) {
log.debug("Configuring Cloud Mongobee");
List<ServiceInfo> matchingServiceInfos = cloud.getServiceInfos(MongoDbFactory.class);
if (matchingServiceInfos.size() != 1) {
throw new CloudException("No unique service matching MongoDbFactory found. Expected 1, found " + matchingServiceInfos.size());
}
MongoServiceInfo info = (MongoServiceInfo) matchingServiceInfos.get(0);
Mongobee mongobee = new Mongobee(info.getUri());
mongobee.setDbName(mongoDbFactory.getDb().getName());
mongobee.setMongoTemplate(mongoTemplate);
// package to scan for migrations
mongobee.setChangeLogsScanPackage("io.github.jhipster.sample.config.dbmigrations");
mongobee.setEnabled(true);
return mongobee;
}
use of org.springframework.cloud.service.common.MongoServiceInfo in project spring-cloud-connectors by spring-cloud.
the class HerokuConnectorMongoServiceTest method mongoServiceCreation.
@Test
public void mongoServiceCreation() {
for (String mongoEnv : new String[] { "MONGOLAB_URI", "MONGOHQ_URL", "MONGOSOUP_URL" }) {
Map<String, String> env = new HashMap<String, String>();
String mongoUrl = getMongoServiceUrl("db");
env.put(mongoEnv, mongoUrl);
when(mockEnvironment.getEnv()).thenReturn(env);
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
ServiceInfo serviceInfo = getServiceInfo(serviceInfos, mongoEnv.substring(0, mongoEnv.length() - 4));
assertNotNull(serviceInfo);
assertTrue(serviceInfo instanceof MongoServiceInfo);
assertMongoServiceInfo((MongoServiceInfo) serviceInfo, "db");
}
}
use of org.springframework.cloud.service.common.MongoServiceInfo 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 mongoClient = getMongoClientField(mongoDbFactory);
List<ServerAddress> addresses = extractServerAddresses(mongoClient);
assertEquals(3, addresses.size());
MongoCredential credentials = mongoClient.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.cloud.service.common.MongoServiceInfo in project spring-cloud-connectors by spring-cloud.
the class CloudTest method servicePropsOneServiceOfTheSameLabel.
@Test
public void servicePropsOneServiceOfTheSameLabel() {
MysqlServiceInfo mysqlServiceInfo = createMysqlService("my-mysql");
MongoServiceInfo mongoServiceInfo = createMongoService("my-mongo");
CloudConnector stubCloudConnector = getTestCloudConnector(mysqlServiceInfo, mongoServiceInfo);
Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);
Properties cloudProperties = testCloud.getCloudProperties();
assertRelationalProps("cloud.services.my-mysql", mysqlServiceInfo, cloudProperties);
assertMongoProps("cloud.services.my-mongo", mongoServiceInfo, cloudProperties);
assertRelationalProps("cloud.services.mysql", mysqlServiceInfo, cloudProperties);
assertMongoProps("cloud.services.mongo", mongoServiceInfo, cloudProperties);
}
use of org.springframework.cloud.service.common.MongoServiceInfo 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 mongoClient = getMongoClientField(mongoDbFactory);
MongoCredential credentials = mongoClient.getCredentialsList().get(0);
List<ServerAddress> addresses = extractServerAddresses(mongoClient);
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