Merge pull request #3357 from ebean-orm/feature/avaje-config-dependency-ContainerConfig

Modify ContainerConfig to remove the avaje-config dependency
This commit is contained in:
Rob Bygrave
2024-03-07 20:23:36 +13:00
committed by GitHub
2 changed files with 36 additions and 20 deletions
@@ -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)));
}
}
@@ -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);
}
}