diff --git a/core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java b/core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java new file mode 100644 index 0000000..13e0f49 --- /dev/null +++ b/core/src/main/java/org/springframework/cloud/service/common/OracleServiceInfo.java @@ -0,0 +1,19 @@ +package org.springframework.cloud.service.common; + +import org.springframework.cloud.service.ServiceInfo; + +@ServiceInfo.ServiceLabel("oracle") +public class OracleServiceInfo extends RelationalServiceInfo { + + public OracleServiceInfo(String id, String url) { + super(id, url, "oracle"); + } + + @Override + public String getJdbcUrl() { + return String.format("jdbc:%s:thin:%s/%s@%s:%d/%s", + jdbcUrlDatabaseType, getUserName(), getPassword(), + getHost(), getPort(), getPath()); + } + +} diff --git a/core/src/main/java/org/springframework/cloud/service/common/RelationalServiceInfo.java b/core/src/main/java/org/springframework/cloud/service/common/RelationalServiceInfo.java index 7985aad..9da3ba9 100644 --- a/core/src/main/java/org/springframework/cloud/service/common/RelationalServiceInfo.java +++ b/core/src/main/java/org/springframework/cloud/service/common/RelationalServiceInfo.java @@ -9,13 +9,13 @@ import org.springframework.cloud.service.UriBasedServiceInfo; */ public abstract class RelationalServiceInfo extends UriBasedServiceInfo { - private String jdbcUrlDatabaseType; + protected String jdbcUrlDatabaseType; - public RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType) { + public RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType) { super(id, uriString); this.jdbcUrlDatabaseType = jdbcUrlDatabaseType; } - + @ServiceProperty(category="connection") public String getJdbcUrl() { return String.format("jdbc:%s://%s:%d/%s?user=%s&password=%s", diff --git a/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/OracleDataSourceCreator.java b/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/OracleDataSourceCreator.java new file mode 100644 index 0000000..3fc4ac2 --- /dev/null +++ b/spring-service-connector/src/main/java/org/springframework/cloud/service/relational/OracleDataSourceCreator.java @@ -0,0 +1,13 @@ +package org.springframework.cloud.service.relational; + +import org.springframework.cloud.service.common.OracleServiceInfo; + +public class OracleDataSourceCreator extends DataSourceCreator { + + private static final String[] DRIVERS = new String[]{"oracle.jdbc.OracleDriver"}; + private static final String VALIDATION_QUERY = "SELECT 'Y' from dual"; + + public OracleDataSourceCreator() { + super("spring-cloud.oracle.driver", DRIVERS, VALIDATION_QUERY); + } +} diff --git a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleDataSourceFactoryTest.java b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleDataSourceFactoryTest.java new file mode 100644 index 0000000..5ca98a7 --- /dev/null +++ b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleDataSourceFactoryTest.java @@ -0,0 +1,9 @@ +package org.springframework.cloud.service.relational; + +import org.springframework.cloud.service.common.OracleServiceInfo; + +public class OracleDataSourceFactoryTest extends AbstractDataSourceFactoryTest { + public OracleServiceInfo getTestServiceInfo(String id) { + return new OracleServiceInfo(id, "oracle://username:pass@host:port/db"); + } +} diff --git a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleServiceCreatorTest.java b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleServiceCreatorTest.java new file mode 100644 index 0000000..0b83d9d --- /dev/null +++ b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/OracleServiceCreatorTest.java @@ -0,0 +1,41 @@ +package org.springframework.cloud.service.relational; + +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.springframework.cloud.service.common.OracleServiceInfo; + +public class OracleServiceCreatorTest extends AbstractDataSourceCreatorTest { + @Mock private OracleServiceInfo mockOracleServiceInfo; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + // set a dummy JDBC driver since we can't include a real Oracle driver in the project due to licensing restrictions + System.setProperty("spring-cloud.oracle.driver", "com.example.Driver"); + } + + @Override + public OracleServiceInfo createServiceInfo() { + when(mockOracleServiceInfo.getJdbcUrl()).thenReturn("oracle://myuser:mypassword@10.20.30.40:5432/database-123"); + + return mockOracleServiceInfo; + } + + @Override + public String getDriverName() { + return "com.example.Driver"; + } + + @Override + public OracleDataSourceCreator getCreator() { + return new OracleDataSourceCreator(); + } + + @Override + public String getValidationQueryStart() { + return "SELECT 'Y' from dual"; + } +} diff --git a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PostgresqlServiceCreatorTest.java b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PostgresqlServiceCreatorTest.java index 4b94fef..951681e 100644 --- a/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PostgresqlServiceCreatorTest.java +++ b/spring-service-connector/src/test/java/org/springframework/cloud/service/relational/PostgresqlServiceCreatorTest.java @@ -8,7 +8,7 @@ import org.mockito.MockitoAnnotations; import org.springframework.cloud.service.common.PostgresqlServiceInfo; /** - * + * * @author Ramnivas Laddad * */