DataSource BindingsPropertiesProcessors
Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.Binding;
|
||||
|
||||
public class DB2JdbcKind implements JdbcKind{
|
||||
|
||||
public static final String DB2_KIND = "db2";
|
||||
public static final String DB2_SCHEME = "db2";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(Binding binding) {
|
||||
return binding.getKind().equals(DB2_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return DB2_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "com.ibm.db2.jcc.DB2Driver";
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
/*
|
||||
* 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.Binding;
|
||||
|
||||
public class MysqlJdbcKind implements JdbcKind{
|
||||
|
||||
public static final String MYSQL_KIND = "mysql";
|
||||
public static final String MYSQL_SCHEME = "mysql";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(Binding binding) {
|
||||
return binding.getKind().equals(MYSQL_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return MYSQL_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
String driverClassNameToUse = null;
|
||||
try {
|
||||
driverClassNameToUse = "org.mariadb.jdbc.Driver";
|
||||
Class.forName(driverClassNameToUse, false, getClass().getClassLoader());
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
driverClassNameToUse = "com.mysql.cj.jdbc.Driver";
|
||||
Class.forName(driverClassNameToUse, false, getClass().getClassLoader());
|
||||
} catch (ClassNotFoundException e2) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return driverClassNameToUse;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.Binding;
|
||||
|
||||
public class OracleJdbcKind implements JdbcKind{
|
||||
|
||||
public static final String ORACLE_KIND = "oracle";
|
||||
public static final String ORACLE_SCHEME = "oracle";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(Binding binding) {
|
||||
return binding.getKind().equals(ORACLE_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return ORACLE_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "oracle.jdbc.OracleDriver";
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* 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 java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.cloud.cnb.Binding;
|
||||
|
||||
|
||||
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(Binding binding) {
|
||||
return POSTGRES_KINDS.contains(binding.getKind());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return POSTGRES_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "org.postgresql.Driver";
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
/*
|
||||
* 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.Binding;
|
||||
|
||||
public class SqlServerJdbcKind implements JdbcKind{
|
||||
|
||||
public static final String SQLSERVER_KIND = "sqlserver";
|
||||
public static final String SQLSERVER_SCHEME = "sqlserver";
|
||||
|
||||
@Override
|
||||
public boolean forBinding(Binding binding) {
|
||||
return binding.getKind().equals(SQLSERVER_KIND);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getScheme() {
|
||||
return SQLSERVER_SCHEME;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDriverClassName() {
|
||||
return "com.microsoft.sqlserver.jdbc.SQLServerDriver";
|
||||
}
|
||||
}
|
||||
@@ -42,18 +42,6 @@ public class JdbcBindingTest {
|
||||
isEqualTo("jdbc:mysql://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcBinding_db2() {
|
||||
Binding db2Binding = bindingWithKind("db2");
|
||||
assertThat(JdbcBinding.isJDCBBinding(db2Binding)).isTrue();
|
||||
JdbcBinding jdbcBinding = new JdbcBinding(db2Binding);
|
||||
|
||||
assertThat(jdbcBinding.getJdbcUrl()).
|
||||
isEqualTo("jdbc:db2://10.0.4.35:3306/some-db?user=some-username&password=some-password");
|
||||
assertThat(jdbcBinding.getDriverClassName()).
|
||||
isEqualTo("com.ibm.db2.jcc.DB2Driver");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJdbcBinding_oracle() {
|
||||
Binding oracleBinding = bindingWithKind("oracle");
|
||||
|
||||
@@ -42,6 +42,16 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mariadb.jdbc</groupId>
|
||||
<artifactId>mariadb-java-client</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
@@ -53,11 +63,6 @@
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@@ -103,7 +103,7 @@ public final class Bindings {
|
||||
*/
|
||||
public @Nullable Binding findBinding(@NotNull String name) {
|
||||
for (Binding binding : bindings) {
|
||||
if (binding.getName().equals(name)) {
|
||||
if (binding.getName().equalsIgnoreCase(name)) {
|
||||
return binding;
|
||||
}
|
||||
}
|
||||
@@ -133,8 +133,8 @@ public final class Bindings {
|
||||
List<Binding> filtered = new ArrayList<>();
|
||||
|
||||
for (Binding binding : bindings) {
|
||||
if ((kind == null || binding.getKind().equals(kind)) &&
|
||||
(provider == null) || binding.getProvider().equals(provider)) {
|
||||
if ((kind == null || binding.getKind().equalsIgnoreCase(kind)) &&
|
||||
(provider == null) || binding.getProvider().equalsIgnoreCase(provider)) {
|
||||
|
||||
filtered.add(binding);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ public final class CassandraBindingsPropertiesProcessor implements BindingsPrope
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "cassandra";
|
||||
public static final String KIND = "Cassandra";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class Db2BindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "DB2";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
Map<String, String> secret = binding.getSecret();
|
||||
|
||||
properties.put("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver");
|
||||
properties.put("spring.datasource.password", secret.get("password"));
|
||||
properties.put("spring.datasource.url", String.format("jdbc:db2://%s:%s/%s?user=%s&password=%s",
|
||||
secret.get("host"), secret.get("port"), secret.get("db"), secret.get("username"),
|
||||
secret.get("password")));
|
||||
properties.put("spring.datasource.username", secret.get("username"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public final class MongoDbBindingsPropertiesProcessor implements BindingsPropert
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "mongodb";
|
||||
public static final String KIND = "MongoDB";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NonNull Map<String, Object> properties) {
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class MySqlBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "MySQL";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
Map<String, String> secret = binding.getSecret();
|
||||
|
||||
try {
|
||||
Class.forName("org.mariadb.jdbc.Driver", false, getClass().getClassLoader());
|
||||
properties.put("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver");
|
||||
} catch (ClassNotFoundException e) {
|
||||
try {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver", false, getClass().getClassLoader());
|
||||
properties.put("spring.datasource.driver-class-name", "com.mysql.cj.jdbc.Driver");
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
properties.put("spring.datasource.password", secret.get("password"));
|
||||
properties.put("spring.datasource.url", String.format("jdbc:mysql://%s:%s/%s?user=%s&password=%s",
|
||||
secret.get("host"), secret.get("port"), secret.get("db"), secret.get("username"),
|
||||
secret.get("password")));
|
||||
properties.put("spring.datasource.username", secret.get("username"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class OracleBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "Oracle";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
Map<String, String> secret = binding.getSecret();
|
||||
|
||||
properties.put("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver");
|
||||
properties.put("spring.datasource.password", secret.get("password"));
|
||||
properties.put("spring.datasource.url", String.format("jdbc:oracle://%s:%s/%s?user=%s&password=%s",
|
||||
secret.get("host"), secret.get("port"), secret.get("db"), secret.get("username"),
|
||||
secret.get("password")));
|
||||
properties.put("spring.datasource.username", secret.get("username"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class PostgreSqlBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "PostgreSQL";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
Map<String, String> secret = binding.getSecret();
|
||||
|
||||
properties.put("spring.datasource.driver-class-name", "org.postgresql.Driver");
|
||||
properties.put("spring.datasource.password", secret.get("password"));
|
||||
properties.put("spring.datasource.url", String.format("jdbc:postgres://%s:%s/%s?user=%s&password=%s",
|
||||
secret.get("host"), secret.get("port"), secret.get("db"), secret.get("username"),
|
||||
secret.get("password")));
|
||||
properties.put("spring.datasource.username", secret.get("username"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public final class RedisBindingsPropertiesProcessor implements BindingsPropertie
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "redis";
|
||||
public static final String KIND = "Redis";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.lang.NonNull;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* An implementation of {@link BindingsPropertiesProcessor} that detects {@link Binding}s of kind: {@value KIND}.
|
||||
*/
|
||||
public final class SqlServerBindingsPropertiesProcessor implements BindingsPropertiesProcessor {
|
||||
|
||||
/**
|
||||
* The {@link Binding} kind that this processor is interested in: {@value}.
|
||||
**/
|
||||
public static final String KIND = "SQLServer";
|
||||
|
||||
@Override
|
||||
public void process(@NonNull Bindings bindings, @NotNull Map<String, Object> properties) {
|
||||
bindings.filterBindings(KIND).forEach(binding -> {
|
||||
Map<String, String> secret = binding.getSecret();
|
||||
|
||||
properties.put("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver");
|
||||
properties.put("spring.datasource.password", secret.get("password"));
|
||||
properties.put("spring.datasource.url", String.format("jdbc:sqlserver://%s:%s/%s?user=%s&password=%s",
|
||||
secret.get("host"), secret.get("port"), secret.get("db"), secret.get("username"),
|
||||
secret.get("password")));
|
||||
properties.put("spring.datasource.username", secret.get("username"));
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,5 +3,10 @@ org.springframework.boot.env.EnvironmentPostProcessor=\
|
||||
# Included implementations
|
||||
org.springframework.cloud.bindings.BindingsPropertiesProcessor=\
|
||||
org.springframework.cloud.bindings.CassandraBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.Db2BindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.MongoDbBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.RedisBindingsPropertiesProcessor
|
||||
org.springframework.cloud.bindings.MySqlBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.OracleBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.PostgreSqlBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.RedisBindingsPropertiesProcessor, \
|
||||
org.springframework.cloud.bindings.SqlServerBindingsPropertiesProcessor
|
||||
|
||||
@@ -117,7 +117,7 @@ final class BindingsEnvironmentPostProcessorTest {
|
||||
@Test
|
||||
@DisplayName("included implementations are registered")
|
||||
void includedImplementations() {
|
||||
assertThat(new BindingsEnvironmentPostProcessor().processors).hasSize(3);
|
||||
assertThat(new BindingsEnvironmentPostProcessor().processors).hasSize(8);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.Db2BindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("DB2 BindingsPropertiesProcessor")
|
||||
final class Db2BindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new Db2BindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:db2://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.MySqlBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("MySQL BindingsPropertiesProcessor")
|
||||
final class MySqlBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new MySqlBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url", "jdbc:mysql://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.OracleBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("Oracle BindingsPropertiesProcessor")
|
||||
final class OracleBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new OracleBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:oracle://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.PostgreSqlBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("PostgreSQL BindingsPropertiesProcessor")
|
||||
final class PostgreSqlBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new PostgreSqlBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "org.postgresql.Driver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:postgres://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright 2020 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.bindings;
|
||||
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.cloud.bindings.SqlServerBindingsPropertiesProcessor.KIND;
|
||||
|
||||
@DisplayName("SQLServer BindingsPropertiesProcessor")
|
||||
final class SqlServerBindingsPropertiesProcessorTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("contributes properties")
|
||||
void test() {
|
||||
HashMap<String, Object> properties = new HashMap<>();
|
||||
|
||||
new SqlServerBindingsPropertiesProcessor().process(new Bindings(
|
||||
new Binding("test-name", Paths.get("test-path"),
|
||||
Collections.singletonMap("kind", KIND),
|
||||
new FluentMap()
|
||||
.withEntry("db", "test-db")
|
||||
.withEntry("host", "test-host")
|
||||
.withEntry("password", "test-password")
|
||||
.withEntry("port", "test-port")
|
||||
.withEntry("username", "test-username")
|
||||
)
|
||||
), properties);
|
||||
|
||||
assertThat(properties)
|
||||
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
|
||||
.containsEntry("spring.datasource.password", "test-password")
|
||||
.containsEntry("spring.datasource.url",
|
||||
"jdbc:sqlserver://test-host:test-port/test-db?user=test-username&password=test-password")
|
||||
.containsEntry("spring.datasource.username", "test-username");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user