Java Code Examples for org.springframework.cloud.service.common.MysqlServiceInfo

The following examples show how to use org.springframework.cloud.service.common.MysqlServiceInfo. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Test
public void mysqlServiceCreation() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
						getMysqlServicePayload("mysql-1", hostname, port, username, password, name1),
						getMysqlServicePayload("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);
}
 
Example 2
@Test
public void mysqlServiceCreationWithLabelNoTags() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
						getMysqlServicePayloadWithLabelNoTags("mysql-1", hostname, port, username, password, name1),
						getMysqlServicePayloadWithLabelNoTags("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example 3
@Test
public void mysqlServiceCreationNoLabelNoTags() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadNoLabelNoTags("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadNoLabelNoTags("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example 4
@Test
public void mysqlServiceCreationNoLabelNoTagsWithSpecialChars() {
	String name = "database";
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";

	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadNoLabelNoTags("mysql", hostname, port, userWithSpecialChars, passwordWithSpecialChars, name)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, "mysql");

	assertServiceFoundOfType(info, MysqlServiceInfo.class);

	assertEquals(getJdbcUrl(hostname, port, name, userWithSpecialChars, passwordWithSpecialChars), 
			((RelationalServiceInfo)info).getJdbcUrl());

	assertUriBasedServiceInfoFields(info, MYSQL_SCHEME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, name);
}
 
Example 5
@Test
public void mysqlServiceCreationWithLabelNoUri() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
		.thenReturn(getServicesPayload(
				getMysqlServicePayloadWithLabelNoUri("mysql-1", hostname, port, username, password, name1),
				getMysqlServicePayloadWithLabelNoUri("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example 6
@Test
public void mysqlServiceCreationWithJdbcUrl() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrl("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadWithJdbcUrl("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, MYSQL_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, MYSQL_SCHEME, hostname, port, username, password, name2);
}
 
Example 7
@Test
public void mysqlServiceCreationWithJdbcUrlAndSpecialChars() {
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";
	String name = "database";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrl("mysql", hostname, port, userWithSpecialChars, passwordWithSpecialChars, name)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, "mysql");

	assertServiceFoundOfType(info, MysqlServiceInfo.class);

	assertEquals(getJdbcUrl(hostname, port, name, userWithSpecialChars, passwordWithSpecialChars),
			((RelationalServiceInfo)info).getJdbcUrl());

	assertUriBasedServiceInfoFields(info, MYSQL_SCHEME, hostname, port, userWithSpecialChars, passwordWithSpecialChars, name);
}
 
Example 8
@Test
public void mysqlServiceCreationWithJdbcUrlOnly() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrlOnly("mysql-1", hostname, port, username, password, name1),
					getMysqlServicePayloadWithJdbcUrlOnly("mysql-2", hostname, port, username, password, name2)));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info1 = getServiceInfo(serviceInfos, "mysql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "mysql-2");

	assertServiceFoundOfType(info1, MysqlServiceInfo.class);
	assertServiceFoundOfType(info2, MysqlServiceInfo.class);

	assertJdbcUrlEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcUrlEqual(info2, MYSQL_SCHEME, name2);

	assertUriBasedServiceInfoFields(info1, "jdbc", null, -1, null, null, null);
	assertUriBasedServiceInfoFields(info2, "jdbc", null, -1, null, null, null);

	assertJdbcShemeSpecificPartEqual(info1, MYSQL_SCHEME, name1);
	assertJdbcShemeSpecificPartEqual(info2, MYSQL_SCHEME, name2);
}
 
Example 9
@Test
public void mysqlServiceCreationWithJdbcUrlOnlyWithSpecialChars() {
	String name = "database";
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getMysqlServicePayloadWithJdbcUrlOnly("mysql", hostname, port, userWithSpecialChars, passwordWithSpecialChars, name)));
	
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();

	ServiceInfo info = getServiceInfo(serviceInfos, "mysql");

	assertServiceFoundOfType(info, MysqlServiceInfo.class);

	assertEquals(getJdbcUrl(hostname, port, name, userWithSpecialChars, passwordWithSpecialChars),
			((RelationalServiceInfo)info).getJdbcUrl());
}
 
Example 10
@Override
public MysqlServiceInfo createServiceInfo(Process process) {
	ActualLRPResponse actual = process.getFirstActual();
	String scheme = "jdbc:"+ MysqlServiceInfo.MYSQL_SCHEME;
	String address = actual.getAddress();
	int port = actual.getPorts()[0].getHostPort();
	String username = "root";
	String password = findRequiredEnvVar(process, "MYSQL_ROOT_PASSWORD");
	String path = findEnvVar(process, "MYSQL_DATABASE_NAME", "test");

	return new MysqlServiceInfo(actual.getInstanceGuid(), constructJdbcUrl(scheme, address, port, username, password, path));
}
 
Example 11
@Test
public void mysqlLatticeWorks() {
	LatticeConnector connector = createConnector();
	MysqlServiceInfo serviceInfo = findServiceInfo(connector, MysqlServiceInfo.class, "mysql-1");
	assertThat(serviceInfo.getJdbcUrl(),
			equalTo("jdbc:mysql://192.168.11.11:61003/test?user=root&password=password"));
}
 
Example 12
Source Project: spring-cloud-connectors   Source File: CloudTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void servicePropsTwoServicesOfTheSameLabel() {
	MysqlServiceInfo mysqlServiceInfo1 = createMysqlService("my-mysql1");
	MysqlServiceInfo mysqlServiceInfo2 = createMysqlService("my-mysql2");	
	CloudConnector stubCloudConnector = getTestCloudConnector(mysqlServiceInfo1, mysqlServiceInfo2);
	Cloud testCloud = new Cloud(stubCloudConnector, serviceCreators);
	
	Properties cloudProperties = testCloud.getCloudProperties();
	assertRelationalProps("cloud.services.my-mysql1", mysqlServiceInfo1, cloudProperties);
	assertRelationalProps("cloud.services.my-mysql2", mysqlServiceInfo2, cloudProperties);
	assertNull(cloudProperties.get("cloud.services.mysql.connection.host"));
}
 
Example 13
Source Project: spring-cloud-connectors   Source File: CloudTest.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 14
@Test
public void db2ServiceCreationWithNoUri() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getUserProvidedServicePayloadWithNoUri(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info = getServiceInfo(serviceInfos, SERVICE_NAME);
	assertNotNull(info);
	assertFalse(MysqlServiceInfo.class.isAssignableFrom(info.getClass()));  // service was not detected as MySQL
	assertNotNull(info);
}
 
Example 15
@Test
public void serviceInfosWithPostProcessedCredentials() {
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).
			thenReturn(getServicesPayload(readTestDataFile("test-credentials-post-processed.json")));
	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	assertNotNull(serviceInfos);
	assertEquals(1, serviceInfos.size());
	assertThat(serviceInfos.get(0), instanceOf(MysqlServiceInfo.class));
	assertEquals(((MysqlServiceInfo) serviceInfos.get(0)).getUri(), "MYSQL://USERNAME:[email protected]/DB");
}
 
Example 16
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "maria");
	assertNotNull(service);
	assertTrue(service instanceof MysqlServiceInfo);
	assertUriParameters((MysqlServiceInfo) service);
}
 
Example 17
@Test
public void mysqlServiceCreation() {
	Map<String, String> env = new HashMap<String, String>();
	String mysqlUrl = getRelationalServiceUrl("db");
	env.put("CLEARDB_DATABASE_URL", mysqlUrl);
	when(mockEnvironment.getEnv()).thenReturn(env);

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo serviceInfo = getServiceInfo(serviceInfos, "CLEARDB_DATABASE");
	assertNotNull(serviceInfo);
	assertTrue(serviceInfo instanceof MysqlServiceInfo);
	assertReleationServiceInfo((MysqlServiceInfo) serviceInfo, "db");
}
 
Example 18
protected MysqlServiceInfo createMysqlService(String id) {
	return new MysqlServiceInfo(id, "mysql://username:[email protected]:port/db");
}
 
Example 19
public MysqlServiceInfo getTestServiceInfo(String id) {
	return new MysqlServiceInfo(id, "jdbc:mysql://username:[email protected]:port/db");
}
 
Example 20
@Override
public MysqlServiceInfo createServiceInfo() {
	when(mockMysqlServiceInfo.getJdbcUrl()).thenReturn("jdbc:mysql://myuser:[email protected]:3306/database-123");
	
	return mockMysqlServiceInfo;
}
 
Example 21
@Override
public MysqlServiceInfo createService(String id) {
	return createMysqlService(id);
}
 
Example 22
public MysqlServiceInfoCreator() {
	// the literal in the tag is CloudFoundry-specific
	super(new Tags("mysql"), MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example 23
@Override
public MysqlServiceInfo createServiceInfo(String id, String url, String jdbcUrl) {
	return new MysqlServiceInfo(id, url, jdbcUrl);
}
 
Example 24
public MysqlServiceInfoCreator() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example 25
@Override
public MysqlServiceInfo createServiceInfo(String id, String uri) {
	return new MysqlServiceInfo(id, uri);
}
 
Example 26
public MysqlServiceInfoCreator() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example 27
@Override
public MysqlServiceInfo createServiceInfo(String id, String uri) {
	return new MysqlServiceInfo(HerokuUtil.computeServiceName(id), uri);
}
 
Example 28
public HerokuConnectorMysqlServiceTest() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}