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

The following examples show how to use org.springframework.cloud.service.common.PostgresqlServiceInfo. 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 postgresqlServiceCreation() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getPostgresqlServicePayload("postgresql-1", hostname, port, username, password, name1),
					getPostgresqlServicePayload("postgresql-2", hostname, port, username, password, name2)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "postgresql-2");

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

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

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, POSTGRES_SCHEME, hostname, port, username, password, name2);
}
 
Example 2
@Test
public void postgresqlWithSpecialCharsServiceCreation() {
	String userWithSpecialChars = "u%u:u+";
	String passwordWithSpecialChars = "p%p:p+";

	String name1 = "database-1";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES")).thenReturn(
			getServicesPayload(getPostgresqlServicePayload("postgresql-1", hostname,
					port, userWithSpecialChars, passwordWithSpecialChars, name1)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");

	assertServiceFoundOfType(info1, PostgresqlServiceInfo.class);

	assertEquals(getJdbcUrl(hostname, port, userWithSpecialChars,
			passwordWithSpecialChars, name1),
			((RelationalServiceInfo) info1).getJdbcUrl());

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port,
			userWithSpecialChars, passwordWithSpecialChars, name1);
}
 
Example 3
@Test
public void postgresqlServiceCreationNoLabelNoTags() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getPostgresqlServicePayloadNoLabelNoTags("postgresql-1", hostname, port, username, password, name1),
					getPostgresqlServicePayloadNoLabelNoTags("postgresql-2", hostname, port, username, password, name2)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "postgresql-2");

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

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

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, POSTGRES_SCHEME, hostname, port, username, password, name2);
}
 
Example 4
@Test
public void postgresqlServiceCreationWithJdbcUrl() {
	String name1 = "database-1";
	String name2 = "database-2";
	when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
			.thenReturn(getServicesPayload(
					getPostgresqlServicePayloadWithJdbcUrl("postgresql-1", hostname, port, username, password, name1),
					getPostgresqlServicePayloadWithJdbcUrl("postgresql-2", hostname, port, username, password, name2)));

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo info1 = getServiceInfo(serviceInfos, "postgresql-1");
	ServiceInfo info2 = getServiceInfo(serviceInfos, "postgresql-2");

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

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

	assertUriBasedServiceInfoFields(info1, POSTGRES_SCHEME, hostname, port, username, password, name1);
	assertUriBasedServiceInfoFields(info2, POSTGRES_SCHEME, hostname, port, username, password, name2);
}
 
Example 5
@Override
public PostgresqlServiceInfo createServiceInfo(Map<String, Object> serviceData) {
    String id = getId(serviceData);

    Map<String, Object> credentials = getCredentials(serviceData);
    String uri = getUriFromCredentials(credentials);

    String cert64 = getRootCaFromCredentials(credentials);
    if (cert64 != null && uri.contains("sslmode")) {
        if (!uri.contains("sslfactory")) {
            try {
                StringBasedTrustManager.getTrustManager().addCert(Base64.getDecoder().decode(cert64));
                if (!uri.contains("?")) {
                    uri += "?sslfactory=" + StringBasedSSLSocketFactory.class.getCanonicalName();
                } else {
                    uri += "&sslfactory=" + StringBasedSSLSocketFactory.class.getCanonicalName();
                }
            } catch (Exception e) {
                LOG.log(Level.SEVERE, "Unable to add certificate to trust manager", e);
            }
        } else {
            LOG.log(Level.WARNING,
                    "sslfactory already present in postgresql, not adding custom handler. Expect truststore issues.");
        }
    }

    return new PostgresqlServiceInfo(id, uri);
}
 
Example 6
@Test
public void serviceCreation() {
	List<ServiceInfo> services = connector.getServiceInfos();
	ServiceInfo service = getServiceInfo(services, "ingres");
	assertNotNull(service);
	assertTrue(service instanceof PostgresqlServiceInfo);
	assertUriParameters((PostgresqlServiceInfo) service);
}
 
Example 7
private void assertPostgresServiceCreated(String envVarName, String serviceInstanceName) {
	Map<String, String> env = new HashMap<String, String>();
	String postgresUrl = getRelationalServiceUrl("db");
	env.put(envVarName, postgresUrl);
	when(mockEnvironment.getEnv()).thenReturn(env);

	List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
	ServiceInfo serviceInfo = getServiceInfo(serviceInfos, serviceInstanceName);
	assertNotNull(serviceInfo);
	assertTrue(serviceInfo instanceof PostgresqlServiceInfo);
	assertReleationServiceInfo((PostgresqlServiceInfo) serviceInfo, "db");
}
 
Example 8
protected PostgresqlServiceInfo createPostgresqlService(String id) {
	return new PostgresqlServiceInfo(id, "postgres://username:[email protected]:port/db");
}
 
Example 9
public PostgresqlServiceInfo getTestServiceInfo(String id) {
	return new PostgresqlServiceInfo(id, "jdbc:postgres://username:[email protected]:port/db");
}
 
Example 10
@Override
public PostgresqlServiceInfo createServiceInfo() {
	when(mockPostgresqlServiceInfo.getJdbcUrl()).thenReturn("jdbc:postgresql://myuser:[email protected]:5432/database-123");
	
	return mockPostgresqlServiceInfo;
}
 
Example 11
@Override
public PostgresqlServiceInfo createService(String id) {
	return createPostgresqlService(id);
}
 
Example 12
@Override
public PostgresqlServiceInfo createServiceInfo(String id, String url, String jdbcUrl) {
	return new PostgresqlServiceInfo(id, url, jdbcUrl);
}
 
Example 13
public PostgresqlServiceInfoCreator() {
	super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}
 
Example 14
@Override
public PostgresqlServiceInfo createServiceInfo(String id, String uri) {
	return new PostgresqlServiceInfo(id, uri);
}
 
Example 15
public PostgresqlServiceInfoCreator() {
	super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}
 
Example 16
@Override
public PostgresqlServiceInfo createServiceInfo(String id, String uri) {
	return new PostgresqlServiceInfo(HerokuUtil.computeServiceName(id), uri);
}
 
Example 17
public HerokuConnectorPostgresqlServiceTest() {
	super(PostgresqlServiceInfo.POSTGRES_SCHEME);
}