#1283 - ENH: Support simplified test configuration (with docker setup typically via application-test.yml)

This commit is contained in:
Rob Bygrave
2018-02-27 18:28:03 +13:00
parent c8e199177c
commit 57b0190cd2
4 changed files with 39 additions and 2 deletions
@@ -0,0 +1,15 @@
package io.ebean.config;
/**
* Used to provide some automatic configuration early in the creation of an EbeanServer.
*/
public interface AutoConfigure {
/**
* Provide some configuration the ServerConfig prior to server creation.
* <p>
* Return true if the autoConfiguration applies to this ServerConfig.
*/
void configure(ServerConfig serverConfig);
}
@@ -2606,10 +2606,22 @@ public class ServerConfig {
public void loadFromProperties(Properties properties) {
// keep the properties used for configuration so that these are available for plugins
this.properties = properties;
autoConfiguration();
PropertiesWrapper p = new PropertiesWrapper("ebean", name, properties);
loadSettings(p);
}
/**
* Use a 'plugin' to provide automatic configuration. Intended for automatic testing
* configuration with Docker containers via ebean-test-config.
*/
private void autoConfiguration() {
Iterator<AutoConfigure> iterator = serviceLoad(AutoConfigure.class).iterator();
while (iterator.hasNext()) {
iterator.next().configure(this);
}
}
/**
* Deprecated - this does nothing now, we always try to read test configuration.
* <p>
@@ -55,4 +55,15 @@ public class PropertiesLoader {
return properties;
}
/**
* Set (override) a configuration property.
*
* This is expected to be only called by test configuration logic
* (ala automatic test configuration via ebean-test-config).
*/
public static synchronized void setProperty(String key, String value) {
load();
properties.setProperty(key, value);
}
}