本文整理汇总了Java中org.springframework.cloud.service.common.MongoServiceInfo类的典型用法代码示例。如果您正苦于以下问题:Java MongoServiceInfo类的具体用法?Java MongoServiceInfo怎么用?Java MongoServiceInfo使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoServiceInfo类属于org.springframework.cloud.service.common包,在下文中一共展示了MongoServiceInfo类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: cloudMongoCreationNoConfig
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@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"));
}
示例2: cloudMongoCreationWithMultipleHostsByUri
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void cloudMongoCreationWithMultipleHostsByUri() throws Exception {
String uri = String.format("%s://%s:%[email protected]%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());
}
示例3: getCollection
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private static DBCollection getCollection(MongoServiceInfo info) throws ToDoStoreException {
MongoClient client;
try {
client = new MongoClient(info.getHost(), info.getPort());
DB db = client.getDB(info.getDatabase());
boolean auth = db.authenticate(info.getUserName(), info.getPassword().toCharArray());
if(!auth) {
throw new ToDoStoreException("Could not authenticate to Mongo DB.");
}
return db.getCollection("todos");
} catch (Exception e) {
throw new ToDoStoreException("Error creating Mongo DB client.", e);
}
}
示例4: servicePropsOneServiceOfTheSameLabel
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@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);
}
示例5: servicePropsMongoMultipleHostsUriString
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void servicePropsMongoMultipleHostsUriString() {
String serviceId = "my-mongo-multiple-hosts-uri";
MongoServiceInfo mongoServiceInfo = createMongoServiceWithMultipleHostsByUri(serviceId);
CloudConnector stubCloudConnector = getTestCloudConnector(mongoServiceInfo);
Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);
Properties cloudProperties = testCloud.getCloudProperties();
assertMongoPropsWithMultipleHostsByUri("cloud.services.my-mongo-multiple-hosts-uri", mongoServiceInfo, cloudProperties);
assertMongoPropsWithMultipleHostsByUri("cloud.services.mongo", mongoServiceInfo, cloudProperties);
}
示例6: assertMongoPropsWithMultipleHostsByUri
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private void assertMongoPropsWithMultipleHostsByUri(String leadKey, MongoServiceInfo serviceInfo, Properties cloudProperties) {
assertEquals(serviceInfo.getId(), cloudProperties.get(leadKey + ".id"));
assertEquals(serviceInfo.getUri(), cloudProperties.get(leadKey + ".connection.uri"));
assertEquals(-1, cloudProperties.get(leadKey + ".connection.port"));
assertNull(cloudProperties.get(leadKey + ".connection.host"));
assertNull(cloudProperties.get(leadKey + ".connection.username"));
assertNull(cloudProperties.get(leadKey + ".connection.password"));
}
示例7: mongoServiceCreation
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void mongoServiceCreation() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getMongoServicePayload("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayload("mongo-2", hostname, port, username, password, "inventory-2", "db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:12,代码来源:CloudFoundryConnectorMongodbServiceTest.java
示例8: mongoServiceCreationNoLabelNoTags
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void mongoServiceCreationNoLabelNoTags() {
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
.thenReturn(getServicesPayload(
getMongoServicePayloadNoLabelNoTags("mongo-1", hostname, port, username, password, "inventory-1", "db"),
getMongoServicePayloadNoLabelNoTags("mongo-2", hostname, port, username, password, "inventory-2", "db")));
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
assertServiceFoundOfType(serviceInfos, "mongo-1", MongoServiceInfo.class);
assertServiceFoundOfType(serviceInfos, "mongo-2", MongoServiceInfo.class);
}
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:12,代码来源:CloudFoundryConnectorMongodbServiceTest.java
示例9: serviceOverride
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void serviceOverride() {
env.setSystemProperty("spring.cloud.candygram", "mongodb://youruser:[email protected]:4321/dbname");
List<ServiceInfo> services = connector.getServiceInfos();
ServiceInfo service = getServiceInfo(services, "candygram");
assertNotNull(service);
assertTrue(service instanceof MongoServiceInfo);
MongoServiceInfo mongo = (MongoServiceInfo) service;
assertEquals("youruser", mongo.getUserName());
assertEquals(4321, mongo.getPort());
}
示例10: serviceCreation
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@Test
public void serviceCreation() {
List<ServiceInfo> services = connector.getServiceInfos();
ServiceInfo service = getServiceInfo(services, "candygram");
assertNotNull(service);
assertTrue(service instanceof MongoServiceInfo);
assertUriParameters((MongoServiceInfo) service);
}
开发者ID:spring-cloud,项目名称:spring-cloud-connectors,代码行数:9,代码来源:LocalConfigConnectorMongoServiceTest.java
示例11: mongoServiceCreation
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
@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");
}
}
示例12: assertMongoServiceInfo
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected void assertMongoServiceInfo(MongoServiceInfo serviceInfo, String databaseName) {
assertEquals(hostname, serviceInfo.getHost());
assertEquals(port, serviceInfo.getPort());
assertEquals(username, serviceInfo.getUserName());
assertEquals(password, serviceInfo.getPassword());
assertEquals(databaseName, serviceInfo.getPath());
}
示例13: createMongoDbFactory
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
private SimpleMongoDbFactory createMongoDbFactory(MongoServiceInfo serviceInfo, MongoClientOptions.Builder mongoOptionsToUse) throws UnknownHostException {
MongoClientURI mongoClientURI = new MongoClientURI(serviceInfo.getUri(), mongoOptionsToUse);
MongoClient mongo = new MongoClient(mongoClientURI);
return new SimpleMongoDbFactory(mongo, mongoClientURI.getDatabase());
}
示例14: createMongoService
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected MongoServiceInfo createMongoService(String id) {
return new MongoServiceInfo(id, "10.20.30.40", 1234, "username", "password", "db");
}
示例15: createMongoServiceWithMultipleHostsByUri
import org.springframework.cloud.service.common.MongoServiceInfo; //导入依赖的package包/类
protected MongoServiceInfo createMongoServiceWithMultipleHostsByUri(String id) {
return new MongoServiceInfo(id, "mongo://username:[email protected],10.20.30.41,10.20.30.42:1234/db");
}