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

The following examples show how to use org.springframework.cloud.service.common.MysqlServiceInfo. 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
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #2
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #3
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #4
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #5
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #7
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #8
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #9
Source File: CloudFoundryConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 6 votes vote down vote up
@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 #10
Source File: HerokuConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@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 #11
Source File: MysqlServiceInfoCreator.java    From spring-cloud-lattice with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: LocalConfigConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "maria");
	assertNotNull(service);
	assertTrue(service instanceof MysqlServiceInfo);
	assertUriParameters((MysqlServiceInfo) service);
}
 
Example #13
Source File: CloudFoundryConnectorApplicationTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@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 #14
Source File: CloudFoundryConnectorDB2ServiceTest.java    From spring-cloud-connectors with Apache License 2.0 5 votes vote down vote up
@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
Source File: CloudTest.java    From spring-cloud-connectors with 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 #16
Source File: CloudTest.java    From spring-cloud-connectors with 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 #17
Source File: MysqlServiceInfoCreatorTests.java    From spring-cloud-lattice with Apache License 2.0 5 votes vote down vote up
@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 #18
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public MysqlServiceInfo createServiceInfo(String id, String url, String jdbcUrl) {
	return new MysqlServiceInfo(id, url, jdbcUrl);
}
 
Example #19
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public MysqlServiceInfoCreator() {
	// the literal in the tag is CloudFoundry-specific
	super(new Tags("mysql"), MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example #20
Source File: DataSourceJavaConfigMysqlTest.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public MysqlServiceInfo createService(String id) {
	return createMysqlService(id);
}
 
Example #21
Source File: MysqlServiceCreatorTest.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public MysqlServiceInfo createServiceInfo() {
	when(mockMysqlServiceInfo.getJdbcUrl()).thenReturn("jdbc:mysql://myuser:[email protected]:3306/database-123");
	
	return mockMysqlServiceInfo;
}
 
Example #22
Source File: MysqlDataSourceFactoryTest.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public MysqlServiceInfo getTestServiceInfo(String id) {
	return new MysqlServiceInfo(id, "jdbc:mysql://username:pass@host:port/db");
}
 
Example #23
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public MysqlServiceInfoCreator() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example #24
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public MysqlServiceInfo createServiceInfo(String id, String uri) {
	return new MysqlServiceInfo(id, uri);
}
 
Example #25
Source File: StubCloudConnectorTest.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
protected MysqlServiceInfo createMysqlService(String id) {
	return new MysqlServiceInfo(id, "mysql://username:pass@host:port/db");
}
 
Example #26
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public MysqlServiceInfoCreator() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}
 
Example #27
Source File: MysqlServiceInfoCreator.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
@Override
public MysqlServiceInfo createServiceInfo(String id, String uri) {
	return new MysqlServiceInfo(HerokuUtil.computeServiceName(id), uri);
}
 
Example #28
Source File: HerokuConnectorMysqlServiceTest.java    From spring-cloud-connectors with Apache License 2.0 4 votes vote down vote up
public HerokuConnectorMysqlServiceTest() {
	super(MysqlServiceInfo.MYSQL_SCHEME);
}