Guards Should Use Environment

Previously all of the guard behavior was triggered by the contents of
environment variables.  In a Spring Boot application, looking at the
environment isn't the only way to get configuration.  This change updates the
guards to use the Environment for configuration retrieval.

[resolves #30]

Signed-off-by: Ben Hale <bhale@vmware.com>
This commit is contained in:
Ben Hale
2020-05-11 14:24:41 -07:00
parent 3ba8b42ce4
commit a33dcf034b
23 changed files with 194 additions and 174 deletions

View File

@@ -26,7 +26,6 @@
<properties>
<java.version>1.8</java.version>
<jsr305.version>3.0.2</jsr305.version>
<junit-pioneer.version>0.6.0</junit-pioneer.version>
<spring-boot.version>2.2.7.RELEASE</spring-boot.version>
<!-- Plugins -->
@@ -65,12 +64,6 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>${junit-pioneer.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mariadb.jdbc</groupId>
<artifactId>mariadb-java-client</artifactId>

View File

@@ -23,7 +23,6 @@ import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.boot.env.EnvironmentPostProcessor;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.support.SpringFactoriesLoader;
@@ -66,7 +65,6 @@ public final class BindingSpecificEnvironmentPostProcessor implements Environmen
this.bindings = new Bindings();
this.processors = SpringFactoriesLoader.
loadFactories(BindingsPropertiesProcessor.class, getClass().getClassLoader());
AnnotationAwareOrderComparator.sort(this.processors);
}
BindingSpecificEnvironmentPostProcessor(Bindings bindings, BindingsPropertiesProcessor... processors) {
@@ -76,7 +74,7 @@ public final class BindingSpecificEnvironmentPostProcessor implements Environmen
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
if (!isGlobalEnabled()) {
if (!isGlobalEnabled(environment)) {
return;
}
@@ -86,7 +84,7 @@ public final class BindingSpecificEnvironmentPostProcessor implements Environmen
}
Map<String, Object> properties = new HashMap<>();
processors.forEach(processor -> processor.process(bindings, properties));
processors.forEach(processor -> processor.process(environment, bindings, properties));
if (properties.isEmpty()) {
log.debug("No properties set from CNB Bindings. Skipping PropertySource creation.");
return;

View File

@@ -17,6 +17,7 @@
package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -30,9 +31,10 @@ public interface BindingsPropertiesProcessor {
/**
* Transform the currently accumulated {@link Bindings}-related properties.
*
* @param bindings the {@code Bindings} exposed to the application.
* @param properties the currently accumulated properties.
* @param environment the {@link Environment} that the processor is executing with.
* @param bindings the {@code Bindings} exposed to the application.
* @param properties the currently accumulated properties.
*/
void process(Bindings bindings, Map<String, Object> properties);
void process(Environment environment, Bindings bindings, Map<String, Object> properties);
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -35,8 +36,8 @@ public final class CassandraBindingsPropertiesProcessor implements BindingsPrope
public static final String KIND = "Cassandra";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -36,8 +37,8 @@ public final class Db2BindingsPropertiesProcessor implements BindingsPropertiesP
public static final String KIND = "DB2";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -16,17 +16,18 @@
package org.springframework.cloud.bindings.boot;
import org.springframework.core.env.Environment;
final class Guards {
static boolean isGlobalEnabled() {
String value = System.getProperty("org.springframework.cloud.bindings.boot.enable", "false");
return Boolean.parseBoolean(value);
static boolean isGlobalEnabled(Environment environment) {
return environment.getProperty("org.springframework.cloud.bindings.boot.enable", Boolean.class, false);
}
static boolean isKindEnabled(String kind) {
String property = String.format("org.springframework.cloud.bindings.boot.%s.enable", kind.toLowerCase());
String value = System.getProperty(property, "true");
return Boolean.parseBoolean(value);
static boolean isKindEnabled(Environment environment, String kind) {
return environment.getProperty(
String.format("org.springframework.cloud.bindings.boot.%s.enable", kind.toLowerCase()),
Boolean.class, true);
}
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -34,8 +35,8 @@ public final class MongoDbBindingsPropertiesProcessor implements BindingsPropert
public static final String KIND = "MongoDB";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -36,8 +37,8 @@ public final class MySqlBindingsPropertiesProcessor implements BindingsPropertie
public static final String KIND = "MySQL";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -36,8 +37,8 @@ public final class OracleBindingsPropertiesProcessor implements BindingsProperti
public static final String KIND = "Oracle";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -36,8 +37,8 @@ public final class PostgreSqlBindingsPropertiesProcessor implements BindingsProp
public static final String KIND = "PostgreSQL";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -34,8 +35,8 @@ public final class RedisBindingsPropertiesProcessor implements BindingsPropertie
public static final String KIND = "Redis";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -18,6 +18,7 @@ package org.springframework.cloud.bindings.boot;
import org.springframework.cloud.bindings.Binding;
import org.springframework.cloud.bindings.Bindings;
import org.springframework.core.env.Environment;
import java.util.Map;
@@ -36,8 +37,8 @@ public final class SqlServerBindingsPropertiesProcessor implements BindingsPrope
public static final String KIND = "SQLServer";
@Override
public void process(Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(KIND)) {
public void process(Environment environment, Bindings bindings, Map<String, Object> properties) {
if (!isKindEnabled(environment, KIND)) {
return;
}

View File

@@ -17,10 +17,7 @@
package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ClearSystemProperty;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.cloud.bindings.Binding;
@@ -37,58 +34,52 @@ final class BindingFlattenedEnvironmentPostProcessorTest {
private final SpringApplication application = new SpringApplication();
private final MockEnvironment environment = new MockEnvironment();
private final MockEnvironment environment = new MockEnvironment()
.withProperty("org.springframework.cloud.bindings.boot.enable", "true");
@Test
@DisplayName("is disabled by default")
@ClearSystemProperty(key = "org.springframework.cloud.bindings.boot.enable")
void disabledByDefault() {
new BindingFlattenedEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
)
).postProcessEnvironment(environment, application);
).postProcessEnvironment(new MockEnvironment(), application);
assertThat(environment.getPropertySources()).hasSize(1);
}
@Nested
@DisplayName("when enabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.enable", value = "true")
final class Enabled {
@Test
@DisplayName("does not create PropertySource if no bindings")
void noBindings() {
new BindingFlattenedEnvironmentPostProcessor(new Bindings()).postProcessEnvironment(environment, application);
@Test
@DisplayName("does not create PropertySource if no bindings")
void noBindings() {
new BindingFlattenedEnvironmentPostProcessor(new Bindings()).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(1);
}
assertThat(environment.getPropertySources()).hasSize(1);
}
@Test
@DisplayName("creates PropertySource with properties")
void containsProperties() {
new BindingFlattenedEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("test-metadata-key", "test-metadata-value"),
Collections.singletonMap("test-secret-key", "test-secret-value"))
)
).postProcessEnvironment(environment, application);
@Test
@DisplayName("creates PropertySource with properties")
void containsProperties() {
new BindingFlattenedEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.singletonMap("test-metadata-key", "test-metadata-value"),
Collections.singletonMap("test-secret-key", "test-secret-value"))
)
).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getProperty("cnb.bindings.test-name.metadata.test-metadata-key")).isEqualTo("test-metadata-value");
assertThat(environment.getProperty("cnb.bindings.test-name.secret.test-secret-key")).isEqualTo("test-secret-value");
}
@Test
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingFlattenedEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
}
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getProperty("cnb.bindings.test-name.metadata.test-metadata-key")).isEqualTo("test-metadata-value");
assertThat(environment.getProperty("cnb.bindings.test-name.secret.test-secret-key")).isEqualTo("test-secret-value");
}
@Test
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingFlattenedEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
}
}

View File

@@ -17,10 +17,7 @@
package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.ClearSystemProperty;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.context.config.ConfigFileApplicationListener;
import org.springframework.cloud.bindings.Binding;
@@ -37,77 +34,71 @@ final class BindingSpecificEnvironmentPostProcessorTest {
private final SpringApplication application = new SpringApplication();
private final MockEnvironment environment = new MockEnvironment();
private final MockEnvironment environment = new MockEnvironment()
.withProperty("org.springframework.cloud.bindings.boot.enable", "true");
@Test
@DisplayName("is disabled by default")
@ClearSystemProperty(key = "org.springframework.cloud.bindings.boot.enable")
void disabledByDefault() {
new BindingSpecificEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
),
(environment, properties) -> properties.put("test-key", "test-value")
(environment, bindings, properties) -> properties.put("test-key", "test-value")
).postProcessEnvironment(new MockEnvironment(), application);
assertThat(environment.getPropertySources()).hasSize(1);
}
@Test
@DisplayName("does not create PropertySource if no bindings")
void noBindings() {
new BindingSpecificEnvironmentPostProcessor(new Bindings()).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(1);
}
@Test
@DisplayName("does not create PropertySource if no properties")
void noProperties() {
new BindingSpecificEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
)
).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(1);
}
@Nested
@DisplayName("when enabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.enable", value = "true")
final class Enabled {
@Test
@DisplayName("creates PropertySource with properties")
void containsProperties() {
new BindingSpecificEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
),
(environment, bindings, properties) -> properties.put("test-key", "test-value")
).postProcessEnvironment(environment, application);
@Test
@DisplayName("does not create PropertySource if no bindings")
void noBindings() {
new BindingSpecificEnvironmentPostProcessor(new Bindings()).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getProperty("test-key")).isEqualTo("test-value");
}
assertThat(environment.getPropertySources()).hasSize(1);
}
@Test
@DisplayName("does not create PropertySource if no properties")
void noProperties() {
new BindingSpecificEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
)
).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(1);
}
@Test
@DisplayName("creates PropertySource with properties")
void containsProperties() {
new BindingSpecificEnvironmentPostProcessor(
new Bindings(
new Binding("test-name", Paths.get("test-path"),
Collections.emptyMap(), Collections.emptyMap())
),
(environment, properties) -> properties.put("test-key", "test-value")
).postProcessEnvironment(environment, application);
assertThat(environment.getPropertySources()).hasSize(2);
assertThat(environment.getProperty("test-key")).isEqualTo("test-value");
}
@Test
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingSpecificEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
}
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(8);
}
@Test
@DisplayName("has order before ConfigFileApplicationListener")
void order() {
assertThat(new BindingSpecificEnvironmentPostProcessor(new Bindings()).getOrder())
.isLessThan(ConfigFileApplicationListener.DEFAULT_ORDER);
}
@Test
@DisplayName("included implementations are registered")
void includedImplementations() {
assertThat(new BindingSpecificEnvironmentPostProcessor().processors).hasSize(8);
}
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -48,12 +48,14 @@ final class CassandraBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new CassandraBindingsPropertiesProcessor().process(bindings, properties);
new CassandraBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.data.cassandra.cluster-name", "test-cluster-name")
.containsEntry("spring.data.cassandra.compression", "test-compression")
@@ -67,9 +69,11 @@ final class CassandraBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.cassandra.enable", value = "false")
void disabled() {
new CassandraBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.cassandra.enable", "false");
new CassandraBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -45,12 +45,14 @@ final class Db2BindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new Db2BindingsPropertiesProcessor().process(bindings, properties);
new Db2BindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.ibm.db2.jcc.DB2Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -60,9 +62,11 @@ final class Db2BindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.db2.enable", value = "false")
void disabled() {
new Db2BindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.db2.enable", "false");
new Db2BindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -19,7 +19,7 @@ package org.springframework.cloud.bindings.boot;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.mock.env.MockEnvironment;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.cloud.bindings.boot.Guards.isGlobalEnabled;
@@ -32,24 +32,26 @@ final class GuardsTest {
@DisplayName("Global Guard")
final class GlobalGuard {
private final MockEnvironment environment = new MockEnvironment();
@Test
@DisplayName("returns false if unset")
void unset() {
assertThat(isGlobalEnabled()).isFalse();
assertThat(isGlobalEnabled(environment)).isFalse();
}
@Test
@DisplayName("returns the set value of true")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.enable", value = "true")
void setTrue() {
assertThat(isGlobalEnabled()).isTrue();
environment.setProperty("org.springframework.cloud.bindings.boot.enable", "true");
assertThat(isGlobalEnabled(environment)).isTrue();
}
@Test
@DisplayName("returns the set value of false")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.enable", value = "false")
void setFalse() {
assertThat(isGlobalEnabled()).isFalse();
environment.setProperty("org.springframework.cloud.bindings.boot.enable", "false");
assertThat(isGlobalEnabled(environment)).isFalse();
}
}
@@ -58,24 +60,26 @@ final class GuardsTest {
@DisplayName("Kind Guard")
final class KindGuard {
private final MockEnvironment environment = new MockEnvironment();
@Test
@DisplayName("returns true if unset")
void unset() {
assertThat(isKindEnabled("Test")).isTrue();
assertThat(isKindEnabled(environment, "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();
environment.setProperty("org.springframework.cloud.bindings.boot.test.enable", "true");
assertThat(isKindEnabled(environment, "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();
environment.setProperty("org.springframework.cloud.bindings.boot.test.enable", "false");
assertThat(isKindEnabled(environment, "Test")).isFalse();
}
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -41,21 +41,25 @@ final class MongoDbBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new MongoDbBindingsPropertiesProcessor().process(bindings, properties);
new MongoDbBindingsPropertiesProcessor().process(environment, 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);
environment.setProperty("org.springframework.cloud.bindings.boot.mongodb.enable", "false");
new MongoDbBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -45,12 +45,14 @@ final class MySqlBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new MySqlBindingsPropertiesProcessor().process(bindings, properties);
new MySqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.mariadb.jdbc.Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -60,9 +62,11 @@ final class MySqlBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.mysql.enable", value = "false")
void disabled() {
new MySqlBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.mysql.enable", "false");
new MySqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -45,12 +45,14 @@ final class OracleBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new OracleBindingsPropertiesProcessor().process(bindings, properties);
new OracleBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "oracle.jdbc.OracleDriver")
.containsEntry("spring.datasource.password", "test-password")
@@ -60,9 +62,11 @@ final class OracleBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.oracle.enable", value = "false")
void disabled() {
new OracleBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.oracle.enable", "false");
new OracleBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -45,12 +45,14 @@ final class PostgreSqlBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new PostgreSqlBindingsPropertiesProcessor().process(bindings, properties);
new PostgreSqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "org.postgresql.Driver")
.containsEntry("spring.datasource.password", "test-password")
@@ -60,9 +62,11 @@ final class PostgreSqlBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.postgresql.enable", value = "false")
void disabled() {
new PostgreSqlBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.postgresql.enable", "false");
new PostgreSqlBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -43,12 +43,14 @@ final class RedisBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new RedisBindingsPropertiesProcessor().process(bindings, properties);
new RedisBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.redis.host", "test-host")
.containsEntry("spring.redis.password", "test-password")
@@ -57,9 +59,11 @@ final class RedisBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.redis.enable", value = "false")
void disabled() {
new RedisBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.redis.enable", "false");
new RedisBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}

View File

@@ -18,10 +18,10 @@ 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;
import org.springframework.mock.env.MockEnvironment;
import java.nio.file.Paths;
import java.util.Collections;
@@ -45,12 +45,14 @@ final class SqlServerBindingsPropertiesProcessorTest {
)
);
private final MockEnvironment environment = new MockEnvironment();
private final HashMap<String, Object> properties = new HashMap<>();
@Test
@DisplayName("contributes properties")
void test() {
new SqlServerBindingsPropertiesProcessor().process(bindings, properties);
new SqlServerBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties)
.containsEntry("spring.datasource.driver-class-name", "com.microsoft.sqlserver.jdbc.SQLServerDriver")
.containsEntry("spring.datasource.password", "test-password")
@@ -60,9 +62,11 @@ final class SqlServerBindingsPropertiesProcessorTest {
@Test
@DisplayName("can be disabled")
@SetSystemProperty(key = "org.springframework.cloud.bindings.boot.sqlserver.enable", value = "false")
void disabled() {
new SqlServerBindingsPropertiesProcessor().process(bindings, properties);
environment.setProperty("org.springframework.cloud.bindings.boot.sqlserver.enable", "false");
new SqlServerBindingsPropertiesProcessor().process(environment, bindings, properties);
assertThat(properties).isEmpty();
}