Per-kind Disabling

Previously, auto-configuration of all kinds of bindings were either enabled or
disabled en-mass.  This level of granularity wasn't really appropriate in
practice as it many use-cases could be served with some bindings but not
others.  This change updates each auto-configuration to watch for a particular
key to be disabled.

[resolves #29]

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 09:36:54 -07:00
parent 09332e92ff
commit de2422fdf5
20 changed files with 331 additions and 119 deletions

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,22 +33,23 @@ import static org.springframework.cloud.bindings.boot.CassandraBindingsPropertie
@DisplayName("Cassandra BindingsPropertiesProcessor")
final class CassandraBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("node_ips", "test-node-ips")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
HashMap<String, Object> properties = new HashMap<>();
new CassandraBindingsPropertiesProcessor().process(new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("node_ips", "test-node-ips")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new CassandraBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.data.cassandra.contact-points", "test-node-ips")
.containsEntry("spring.data.cassandra.password", "test-password")
@@ -55,4 +57,12 @@ final class CassandraBindingsPropertiesProcessorTest {
.containsEntry("spring.data.cassandra.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.cassandra.enable", value = "false")
void disabled() {
new CassandraBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,23 +33,24 @@ import static org.springframework.cloud.bindings.boot.Db2BindingsPropertiesProce
@DisplayName("DB2 BindingsPropertiesProcessor")
final class Db2BindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@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("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new Db2BindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -56,4 +58,12 @@ final class Db2BindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.db2.enable", value = "false")
void disabled() {
new Db2BindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -0,0 +1,49 @@
/*
* 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.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bindings.boot.KindGuard.isKindEnabled;
@DisplayName("Kind Guard")
final class KindGuardTest {
@Test
@DisplayName("returns true if unset")
void unset() {
assertThat(isKindEnabled("Test")).isTrue();
}
@Test
@DisplayName("returns the set value of true")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.test.enable", value = "true")
void setTrue() {
assertThat(isKindEnabled("Test")).isTrue();
}
@Test
@DisplayName("returns the set value of false")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.test.enable", value = "false")
void setFalse() {
assertThat(isKindEnabled("Test")).isFalse();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,21 +33,30 @@ import static org.springframework.cloud.bindings.boot.MongoDbBindingsPropertiesP
@DisplayName("MongoDB BindingsPropertiesProcessor")
final class MongoDbBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("uri", "test-uri")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
HashMap<String, Object> properties = new HashMap<>();
new MongoDbBindingsPropertiesProcessor().process(new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("uri", "test-uri")
)
), properties);
new MongoDbBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.mongodb.uri", "test-uri");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.mongodb.enable", value = "false")
void disabled() {
new MongoDbBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,23 +33,24 @@ import static org.springframework.cloud.bindings.boot.MySqlBindingsPropertiesPro
@DisplayName("MySQL BindingsPropertiesProcessor")
final class MySqlBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@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("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new MySqlBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -56,4 +58,12 @@ final class MySqlBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.mysql.enable", value = "false")
void disabled() {
new MySqlBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,23 +33,24 @@ import static org.springframework.cloud.bindings.boot.OracleBindingsPropertiesPr
@DisplayName("Oracle BindingsPropertiesProcessor")
final class OracleBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@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("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new OracleBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
.containsEntry("spring.datasource.password", "test-password")
@@ -56,4 +58,12 @@ final class OracleBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.oracle.enable", value = "false")
void disabled() {
new OracleBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,23 +33,24 @@ import static org.springframework.cloud.bindings.boot.PostgreSqlBindingsProperti
@DisplayName("PostgreSQL BindingsPropertiesProcessor")
final class PostgreSqlBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@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("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new PostgreSqlBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.postgresql.Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -56,4 +58,12 @@ final class PostgreSqlBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.postgresql.enable", value = "false")
void disabled() {
new PostgreSqlBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,25 +33,34 @@ import static org.springframework.cloud.bindings.boot.RedisBindingsPropertiesPro
@DisplayName("Redis BindingsPropertiesProcessor")
final class RedisBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
HashMap<String, Object> properties = new HashMap<>();
new RedisBindingsPropertiesProcessor().process(new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
)
), properties);
new RedisBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.redis.host", "test-host")
.containsEntry("spring.redis.password", "test-password")
.containsEntry("spring.redis.port", "test-port");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.redis.enable", value = "false")
void disabled() {
new RedisBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.cloud.bindings.FluentMap;
@@ -32,23 +33,24 @@ import static org.springframework.cloud.bindings.boot.SqlServerBindingsPropertie
@DisplayName("SQLServer BindingsPropertiesProcessor")
final class SqlServerBindingsPropertiesProcessorTest {
private final Bindings bindings = new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("kind", KIND),
new FluentMap()
.withEntry("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
);
private final HashMap<String, Object> properties = new HashMap<>();
@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("database", "test-database")
.withEntry("host", "test-host")
.withEntry("password", "test-password")
.withEntry("port", "test-port")
.withEntry("username", "test-username")
)
), properties);
new SqlServerBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
.containsEntry("spring.datasource.password", "test-password")
@@ -56,4 +58,12 @@ final class SqlServerBindingsPropertiesProcessorTest {
.containsEntry("spring.datasource.username", "test-username");
}
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.sqlserver.enable", value = "false")
void disabled() {
new SqlServerBindingsPropertiesProcessor().process(bindings, properties);
assertThat(properties).isEmpty();
}
}