support for DB2 in cloud properties
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
package org.springframework.cloud.cloudfoundry;
|
||||
|
||||
import org.springframework.cloud.service.common.DB2ServiceInfo;
|
||||
|
||||
public class DB2ServiceInfoCreator extends RelationalServiceInfoCreator<DB2ServiceInfo> {
|
||||
public DB2ServiceInfoCreator() {
|
||||
super(new Tags(), DB2ServiceInfo.DB2_SCHEME);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DB2ServiceInfo createServiceInfo(String id, String url) {
|
||||
return new DB2ServiceInfo(id, url);
|
||||
}
|
||||
}
|
||||
@@ -6,3 +6,4 @@ org.springframework.cloud.cloudfoundry.AmqpServiceInfoCreator
|
||||
org.springframework.cloud.cloudfoundry.MonitoringServiceInfoCreator
|
||||
org.springframework.cloud.cloudfoundry.SmtpServiceInfoCreator
|
||||
org.springframework.cloud.cloudfoundry.OracleServiceInfoCreator
|
||||
org.springframework.cloud.cloudfoundry.DB2ServiceInfoCreator
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package org.springframework.cloud.cloudfoundry;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.cloud.service.BaseServiceInfo;
|
||||
import org.springframework.cloud.service.ServiceInfo;
|
||||
import org.springframework.cloud.service.common.MysqlServiceInfo;
|
||||
import org.springframework.cloud.service.common.DB2ServiceInfo;
|
||||
import org.springframework.cloud.service.common.RelationalServiceInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class CloudFoundryConnectorDB2ServiceTest extends AbstractUserProvidedServiceInfoCreatorTest {
|
||||
|
||||
private static final String INSTANCE_NAME = "database";
|
||||
private static final String DB2_SCHEME = "db2:";
|
||||
private static final String SERVICE_NAME = "db2-ups";
|
||||
|
||||
@Test
|
||||
public void db2ServiceCreation() {
|
||||
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
|
||||
.thenReturn(getServicesPayload(
|
||||
getUserProvidedServicePayload(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME, DB2_SCHEME)));
|
||||
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
|
||||
|
||||
DB2ServiceInfo info = (DB2ServiceInfo) getServiceInfo(serviceInfos, SERVICE_NAME);
|
||||
assertServiceFoundOfType(info, DB2ServiceInfo.class);
|
||||
assertEquals(getDB2JdbcUrl(INSTANCE_NAME), info.getJdbcUrl());
|
||||
}
|
||||
|
||||
@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();
|
||||
|
||||
BaseServiceInfo info = (BaseServiceInfo) getServiceInfo(serviceInfos, SERVICE_NAME);
|
||||
assertFalse(MysqlServiceInfo.class.isAssignableFrom(info.getClass())); // service was not detected as MySQL
|
||||
assertNotNull(info);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dServiceCreationWithJdbcUrl() {
|
||||
when(mockEnvironment.getEnvValue("VCAP_SERVICES"))
|
||||
.thenReturn(getServicesPayload(
|
||||
getDB2ServicePayloadWithJdbcurl(SERVICE_NAME, hostname, port, username, password, INSTANCE_NAME, DB2_SCHEME)));
|
||||
List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos();
|
||||
|
||||
DB2ServiceInfo info = (DB2ServiceInfo) getServiceInfo(serviceInfos, SERVICE_NAME);
|
||||
assertServiceFoundOfType(info, DB2ServiceInfo.class);
|
||||
assertEquals(RelationalServiceInfo.JDBC_PREFIX + "db2:rawjdbcurl", info.getJdbcUrl());
|
||||
}
|
||||
|
||||
protected String getDB2ServicePayloadWithJdbcurl(String serviceName, String hostname, int port,
|
||||
String user, String password, String name, String scheme) {
|
||||
String payload = getRelationalPayload("test-db2-info-jdbc-url.json", serviceName,
|
||||
hostname, port, user, password, name);
|
||||
return payload.replace("$scheme", scheme);
|
||||
}
|
||||
|
||||
private String getDB2JdbcUrl(String name) {
|
||||
return "jdbc:db2://" + hostname + ":" + port + "/" + name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "$serviceName",
|
||||
"credentials": {
|
||||
"jdbcUrl": "jdbc:db2:rawjdbcurl",
|
||||
"uri": "db2://$user:$password@$hostname:$port/$name"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.springframework.cloud.service.common;
|
||||
|
||||
import org.springframework.cloud.service.ServiceInfo;
|
||||
|
||||
@ServiceInfo.ServiceLabel("db2")
|
||||
public class DB2ServiceInfo extends RelationalServiceInfo {
|
||||
|
||||
private static final String JDBC_URL_TYPE = "db2";
|
||||
|
||||
public static final String DB2_SCHEME = JDBC_URL_TYPE;
|
||||
|
||||
public DB2ServiceInfo(String id, String url) {
|
||||
super(id, url, JDBC_URL_TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getJdbcUrl() {
|
||||
if (getUriInfo().getUriString().startsWith(JDBC_PREFIX)) {
|
||||
return getUriInfo().getUriString();
|
||||
}
|
||||
|
||||
return String.format("jdbc:%s://%s:%d/%s",
|
||||
jdbcUrlDatabaseType,
|
||||
getHost(), getPort(), getPath());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user