#1338 - Regression since 11.12.1 - resolve expressions in Properties given to serverConfig.loadFromProperties()

This commit is contained in:
Rob Bygrave committed 2018-03-07 16:43:42 +13:00
1 parent 47e8d27212
commit baa7242939
4 files changed
+53 -5

No files matched your search

@@ -1,6 +1,7 @@
package io.ebean.config;
import io.ebean.annotation.Platform;
import io.ebean.config.properties.PropertiesLoader;
import org.junit.Test;
import java.util.Properties;
@@ -50,6 +51,9 @@ public class PropertiesWrapperTest {
@Test
public void testGetProperties() {
String home = System.getenv("HOME");
String tmpDir = System.getProperty("java.io.tmpdir");
Properties properties = new Properties();
properties.put("someBasic", "hello");
properties.put("someInt", "42");
@@ -57,16 +61,20 @@ public class PropertiesWrapperTest {
properties.put("somePath", "${HOME}/hello");
properties.put("someSystemProp", "/aaa/${java.io.tmpdir}/bbb");
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", properties);
Properties evalCopy = PropertiesLoader.eval(properties);
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", evalCopy);
assertEquals(42, pw.getInt("someInt", 99));
assertEquals(Double.valueOf(5.5D), (Double.valueOf(pw.getDouble("someDouble", 99.9D))));
assertEquals(home + "/hello", pw.get("somePath", null));
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", pw.get("someSystemProp"));
pw = new PropertiesWrapper(properties);
pw = new PropertiesWrapper(evalCopy);
assertEquals(42, pw.getInt("someInt", 99));
assertEquals(Double.valueOf(5.5D), (Double.valueOf(pw.getDouble("someDouble", 99.9D))));
assertEquals(home + "/hello", pw.get("somePath", null));
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", pw.get("someSystemProp"));
}
}
@@ -7,6 +7,7 @@ import org.junit.Test;
import java.util.Properties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
@@ -24,6 +25,21 @@ public class ServerConfigTest {
assertNotNull(serverConfig.getProperties());
}
@Test
public void evalPropertiesInput() {
String home = System.getenv("HOME");
Properties props = new Properties();
props.setProperty("ddl.initSql", "${HOME}/initSql");
ServerConfig serverConfig = new ServerConfig();
serverConfig.loadFromProperties(props);
String ddlInitSql = serverConfig.getDdlInitSql();
assertThat(ddlInitSql).isEqualTo(home+"/initSql");
}
@Test
public void testLoadWithProperties() {