diff --git a/ebean-api/src/main/java/io/ebean/config/ContainerConfig.java b/ebean-api/src/main/java/io/ebean/config/ContainerConfig.java index 20c05c27d..78ef262db 100644 --- a/ebean-api/src/main/java/io/ebean/config/ContainerConfig.java +++ b/ebean-api/src/main/java/io/ebean/config/ContainerConfig.java @@ -1,8 +1,5 @@ package io.ebean.config; -import io.avaje.config.Config; -import io.avaje.config.Configuration; - import java.util.Properties; /** @@ -19,16 +16,6 @@ public class ContainerConfig { private String podName; private int port; private Properties properties; - private Configuration configuration; - - public ContainerConfig() { - this.configuration = Config.asConfiguration(); - this.active = configuration.getBool("ebean.cluster.active", active); - this.serviceName = configuration.getNullable("ebean.cluster.serviceName", serviceName); - this.namespace = configuration.getNullable("ebean.cluster.namespace", namespace); - this.podName = configuration.getNullable("ebean.cluster.podName", podName); - this.port = configuration.getInt("ebean.cluster.port", 0); - } /** * Return the service name. @@ -104,7 +91,7 @@ public class ContainerConfig { * Return the deployment properties. */ public Properties getProperties() { - return properties != null ? properties : configuration.asProperties(); + return properties; } /** @@ -114,4 +101,25 @@ public class ContainerConfig { this.properties = properties; } + /** + * Load the settings from properties. + */ + public void loadFromProperties(Properties properties) { + this.properties = properties; + this.active = getProperty(properties, "ebean.cluster.active", active); + this.serviceName = properties.getProperty("ebean.cluster.serviceName", serviceName); + this.namespace = properties.getProperty("ebean.cluster.namespace", namespace); + this.podName = properties.getProperty("ebean.cluster.podName", podName); + String portParam = properties.getProperty("ebean.cluster.port"); + if (portParam != null) { + this.port = Integer.parseInt(portParam); + } + } + + /** + * Return the boolean property setting. + */ + protected boolean getProperty(Properties properties, String key, boolean defaultValue) { + return "true".equalsIgnoreCase(properties.getProperty(key, Boolean.toString(defaultValue))); + } } diff --git a/ebean-test/src/test/java/io/ebean/xtest/config/ContainerConfigTest.java b/ebean-test/src/test/java/io/ebean/xtest/config/ContainerConfigTest.java index 6fba07abe..4f2f95e22 100644 --- a/ebean-test/src/test/java/io/ebean/xtest/config/ContainerConfigTest.java +++ b/ebean-test/src/test/java/io/ebean/xtest/config/ContainerConfigTest.java @@ -12,12 +12,20 @@ class ContainerConfigTest { @Test void loadFromProperties() { - ContainerConfig containerConfig = new ContainerConfig(); + Properties p = new Properties(); + p.setProperty("ebean.cluster.active", "true"); + p.setProperty("ebean.cluster.serviceName", "a"); + p.setProperty("ebean.cluster.namespace", "b"); + p.setProperty("ebean.cluster.podName", "c"); + p.setProperty("ebean.cluster.port", "42"); - assertThat(containerConfig.isActive()).isFalse(); - assertThat(containerConfig.getServiceName()).isNull(); - assertThat(containerConfig.getNamespace()).isNull(); - assertThat(containerConfig.getPodName()).isNull(); - assertThat(containerConfig.getPort()).isEqualTo(0); + ContainerConfig containerConfig = new ContainerConfig(); + containerConfig.loadFromProperties(p); + + assertThat(containerConfig.isActive()).isTrue(); + assertThat(containerConfig.getServiceName()).isEqualTo("a"); + assertThat(containerConfig.getNamespace()).isEqualTo("b"); + assertThat(containerConfig.getPodName()).isEqualTo("c"); + assertThat(containerConfig.getPort()).isEqualTo(42); } }