Adds more jdbc kinds
* db2, oracle, postgres, sqlserver Signed-off-by: Emily Casey <ecasey@pivotal.io>
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cnb.jdbc;
|
||||
|
||||
import org.springframework.cloud.cnb.core.CnbBinding;
|
||||
|
||||
public class DB2JdbcKind implements JdbcKind{
|
||||
|
||||
public static final String DB2_KIND = "db2";
|
||||
public static final String DB2_SCHEME = "db2";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(CnbBinding binding) {
|
||||
return binding.getKind().equals(DB2_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return DB2_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "com.ibm.db2.jcc.DB2Driver";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cnb.jdbc;
|
||||
|
||||
import org.springframework.cloud.cnb.core.CnbBinding;
|
||||
|
||||
public class OracleJdbcKind implements JdbcKind{
|
||||
|
||||
public static final String ORACLE_KIND = "oracle";
|
||||
public static final String ORACLE_SCHEME = "oracle";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(CnbBinding binding) {
|
||||
return binding.getKind().equals(ORACLE_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return ORACLE_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "oracle.jdbc.OracleDriver";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cnb.jdbc;
|
||||
|
||||
import org.springframework.cloud.cnb.core.CnbBinding;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class PostgresJdbcKind implements JdbcKind{
|
||||
|
||||
public static final List<String> POSTGRES_KINDS = Arrays.asList("postgres", "postgresql");
|
||||
public static final String POSTGRES_SCHEME = "postgres";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(CnbBinding binding) {
|
||||
return POSTGRES_KINDS.contains(binding.getKind());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return POSTGRES_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "org.postgresql.Driver";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cnb.jdbc;
|
||||
|
||||
import org.springframework.cloud.cnb.core.CnbBinding;
|
||||
|
||||
public class SqlServerJdbcKind implements JdbcKind{
|
||||
|
||||
public static final String SQLSERVER_KIND = "sqlserver";
|
||||
public static final String SQLSERVER_SCHEME = "sqlserver";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(CnbBinding binding) {
|
||||
return binding.getKind().equals(SQLSERVER_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return SQLSERVER_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
}
|
||||
}
|
||||
@@ -1 +1,5 @@
|
||||
org.springframework.cloud.cnb.jdbc.MysqlJdbcKind
|
||||
org.springframework.cloud.cnb.jdbc.MysqlJdbcKind
|
||||
org.springframework.cloud.cnb.jdbc.DB2JdbcKind
|
||||
org.springframework.cloud.cnb.jdbc.OracleJdbcKind
|
||||
org.springframework.cloud.cnb.jdbc.PostgresJdbcKind
|
||||
org.springframework.cloud.cnb.jdbc.SqlServerJdbcKind
|
||||
@@ -28,18 +28,73 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
public class JdbcUrlCreatorTest {
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator() {
|
||||
Map<String,String> mysqlMetadata = new HashMap<String,String>();
|
||||
mysqlMetadata.put("kind", "mysql");
|
||||
Map<String,String> mysqlSecret = new HashMap<String,String>();
|
||||
mysqlSecret.put("hostname", "10.0.4.35");
|
||||
mysqlSecret.put("port", "3306");
|
||||
mysqlSecret.put("db", "some-db");
|
||||
mysqlSecret.put("username", "some-username");
|
||||
mysqlSecret.put("password", "some-password");
|
||||
CnbBinding mysqlBinding = new CnbBinding(mysqlMetadata, mysqlSecret);
|
||||
public void testJdbcUrlCreator_mysql() {
|
||||
CnbBinding mysqlBinding = bindingWithKind("mysql");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(mysqlBinding);
|
||||
String url = jdbcUrlCreator.getJdbcUrl();
|
||||
assertThat(url).isEqualTo("jdbc:mysql://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl()).
|
||||
isEqualTo("jdbc:mysql://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator_db2() {
|
||||
CnbBinding db2Binding = bindingWithKind("db2");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(db2Binding);
|
||||
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl()).
|
||||
isEqualTo("jdbc:db2://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getDriverClassName()).
|
||||
isEqualTo("com.ibm.db2.jcc.DB2Driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator_oracle() {
|
||||
CnbBinding oracleBinding = bindingWithKind("oracle");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(oracleBinding);
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl())
|
||||
.isEqualTo("jdbc:oracle://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getDriverClassName()).
|
||||
isEqualTo("oracle.jdbc.OracleDriver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator_postgres() {
|
||||
CnbBinding oracleBinding = bindingWithKind("postgres");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(oracleBinding);
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl())
|
||||
.isEqualTo("jdbc:postgres://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getDriverClassName()).
|
||||
isEqualTo("org.postgresql.Driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator_postgresql() {
|
||||
CnbBinding oracleBinding = bindingWithKind("postgresql");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(oracleBinding);
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl())
|
||||
.isEqualTo("jdbc:postgres://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getDriverClassName()).
|
||||
isEqualTo("org.postgresql.Driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcUrlCreator_sqlserver() {
|
||||
CnbBinding oracleBinding = bindingWithKind("sqlserver");
|
||||
JdbcUrlCreator jdbcUrlCreator = new JdbcUrlCreator(oracleBinding);
|
||||
assertThat(jdbcUrlCreator.getJdbcUrl())
|
||||
.isEqualTo("jdbc:sqlserver://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcUrlCreator.getDriverClassName()).
|
||||
isEqualTo("com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
}
|
||||
|
||||
public CnbBinding bindingWithKind(String kind) {
|
||||
Map<String, String> metadata = new HashMap<String, String>();
|
||||
metadata.put("kind", kind);
|
||||
Map<String, String> secret = new HashMap<String, String>();
|
||||
secret.put("hostname", "10.0.4.35");
|
||||
secret.put("port", "3306");
|
||||
secret.put("db", "some-db");
|
||||
secret.put("username", "some-username");
|
||||
secret.put("password", "some-password");
|
||||
return new CnbBinding(metadata, secret);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user