mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1246 - Support use of application.yml and application-test.yml ... (as alternative to ebean.properties, test-ebean.properties)
This commit is contained in:
@@ -12,7 +12,7 @@ public class PropertiesWrapperTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetServerName() throws Exception {
|
||||
public void testGetServerName() {
|
||||
|
||||
PropertiesWrapper pw = new PropertiesWrapper(null, "myserver", new Properties());
|
||||
assertEquals("myserver", pw.getServerName());
|
||||
@@ -35,23 +35,20 @@ public class PropertiesWrapperTest {
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("someBasic", " hello ");
|
||||
properties.put("someInt", " 42 ");
|
||||
properties.put("someInt", "42");
|
||||
properties.put("noTrimReqr", "jim");
|
||||
properties.put("includeSpaces", " jim bob ");
|
||||
|
||||
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", properties);
|
||||
assertEquals("hello", pw.get("someBasic"));
|
||||
assertEquals(" hello ", pw.get("someBasic"));
|
||||
assertEquals(42, pw.getInt("someInt", 1));
|
||||
assertNull(pw.get("doesNotExist", null));
|
||||
assertEquals("jim", pw.get("noTrimReqr"));
|
||||
assertEquals("jim bob", pw.get("includeSpaces"));
|
||||
assertEquals(" jim bob ", pw.get("includeSpaces"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetProperties() throws Exception {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
String tmpDir = System.getProperty("java.io.tmpdir");
|
||||
public void testGetProperties() {
|
||||
|
||||
Properties properties = new Properties();
|
||||
properties.put("someBasic", "hello");
|
||||
@@ -64,28 +61,12 @@ public class PropertiesWrapperTest {
|
||||
|
||||
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"));
|
||||
|
||||
Properties properties1 = pw.asPropertiesLowerCase();
|
||||
assertEquals("hello", properties1.getProperty("somebasic"));
|
||||
assertEquals("42", properties1.getProperty("someint"));
|
||||
assertEquals(home + "/hello", properties1.get("somepath"));
|
||||
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", properties1.get("somesystemprop"));
|
||||
|
||||
|
||||
pw = new PropertiesWrapper(properties);
|
||||
|
||||
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"));
|
||||
|
||||
properties1 = pw.asPropertiesLowerCase();
|
||||
assertEquals("hello", properties1.getProperty("somebasic"));
|
||||
assertEquals("42", properties1.getProperty("someint"));
|
||||
assertEquals(home + "/hello", properties1.get("somepath"));
|
||||
assertEquals(tmpDir, "/aaa/" + tmpDir + "/bbb", properties1.get("somesystemprop"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PropertyMapTest {
|
||||
|
||||
@Test
|
||||
public void testDefaultProperties() throws Exception {
|
||||
|
||||
PropertyMap.defaultProperties();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEval() throws Exception {
|
||||
|
||||
String home = System.getenv("HOME");
|
||||
PropertyMap map = new PropertyMap();
|
||||
assertEquals(home, map.eval("${HOME}"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package io.ebean.config.properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class LoaderTest {
|
||||
|
||||
@Test
|
||||
public void load() {
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadProperties("test-properties/application.properties", Loader.Source.RESOURCE);
|
||||
loader.loadYaml("test-properties/application.yml", Loader.Source.RESOURCE);
|
||||
|
||||
loader.loadProperties("test-properties/one.properties", Loader.Source.RESOURCE);
|
||||
loader.loadYaml("test-properties/foo.yml", Loader.Source.RESOURCE);
|
||||
|
||||
Properties properties = loader.eval();
|
||||
|
||||
assertEquals("fromProperties", properties.getProperty("app.fromProperties"));
|
||||
assertEquals("Two", properties.getProperty("app.two"));
|
||||
|
||||
assertEquals("bart", properties.getProperty("eval.withDefault"));
|
||||
assertEquals("/home/rob/after", properties.getProperty("eval.home"));
|
||||
assertEquals("rob", properties.getProperty("eval.name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadWithExtensionCheck() {
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadWithExtensionCheck("test-dummy.properties");
|
||||
loader.loadWithExtensionCheck("test-dummy.yml");
|
||||
|
||||
Properties properties = loader.eval();
|
||||
assertThat(properties.getProperty("dummy.yml.foo")).isEqualTo("bar");
|
||||
assertThat(properties.getProperty("dummy.properties.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void loadYaml() {
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadYaml("test-properties/foo.yml", Loader.Source.RESOURCE);
|
||||
Properties properties = loader.eval();
|
||||
|
||||
assertThat(properties.getProperty("ebean.oracle.password")).isEqualTo("someDefault");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadProperties() {
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadProperties("test-properties/one.properties", Loader.Source.RESOURCE);
|
||||
Properties properties = loader.eval();
|
||||
|
||||
assertThat(properties.getProperty("hello")).isEqualTo("there");
|
||||
assertThat(properties.getProperty("name")).isEqualTo("Rob");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package io.ebean.config.properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
public class PropertyEvalTest {
|
||||
|
||||
@Test
|
||||
public void eval_null() {
|
||||
assertNull(PropertyEval.eval(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eval_empty() {
|
||||
assertEquals("", PropertyEval.eval(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eval_noExpressions() {
|
||||
assertEquals("basic", PropertyEval.eval("basic"));
|
||||
assertEquals("{basic}", PropertyEval.eval("{basic}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eval_singleExpression() {
|
||||
System.setProperty("foo", "Hello");
|
||||
assertEquals("Hello", PropertyEval.eval("${foo}"));
|
||||
assertEquals("preHello", PropertyEval.eval("pre${foo}"));
|
||||
assertEquals("HelloPost", PropertyEval.eval("${foo}Post"));
|
||||
assertEquals("beforeHelloAfter", PropertyEval.eval("before${foo}After"));
|
||||
System.clearProperty("foo");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eval_singleExpression_withDefault() {
|
||||
|
||||
System.setProperty("foo", "Hello");
|
||||
assertEquals("Hello", PropertyEval.eval("${foo:bart}"));
|
||||
assertEquals("beforeHelloAfter", PropertyEval.eval("before${foo:bart}After"));
|
||||
assertEquals("preHello", PropertyEval.eval("pre${foo:bart}"));
|
||||
assertEquals("HelloPost", PropertyEval.eval("${foo:bart}Post"));
|
||||
|
||||
System.clearProperty("foo");
|
||||
assertEquals("bart", PropertyEval.eval("${foo:bart}"));
|
||||
assertEquals("before-bart-after", PropertyEval.eval("before-${foo:bart}-after"));
|
||||
assertEquals("pre-bart", PropertyEval.eval("pre-${foo:bart}"));
|
||||
assertEquals("bart-post", PropertyEval.eval("${foo:bart}-post"));
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void eval_multiExpression_withDefault() {
|
||||
|
||||
assertEquals("num1num2", PropertyEval.eval("${one:num1}${two:num2}"));
|
||||
assertEquals("num1-num2", PropertyEval.eval("${one:num1}-${two:num2}"));
|
||||
assertEquals("num1abnum2", PropertyEval.eval("${one:num1}ab${two:num2}"));
|
||||
assertEquals("anum1bcnum2d", PropertyEval.eval("a${one:num1}bc${two:num2}d"));
|
||||
|
||||
System.setProperty("one", "first");
|
||||
System.setProperty("two", "second");
|
||||
|
||||
assertEquals("firstsecond", PropertyEval.eval("${one:num1}${two:num2}"));
|
||||
assertEquals("first-second", PropertyEval.eval("${one:num1}-${two:num2}"));
|
||||
assertEquals("pre-first-second-post", PropertyEval.eval("pre-${one:num1}-${two:num2}-post"));
|
||||
assertEquals("AfirstBCsecondD", PropertyEval.eval("A${one:num1}BC${two:num2}D"));
|
||||
|
||||
|
||||
System.clearProperty("one");
|
||||
System.clearProperty("two");
|
||||
}
|
||||
}
|
||||
@@ -5,14 +5,14 @@ import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.config.PropertyMap;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
import org.tests.model.basic.UTMaster;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import org.avaje.datasource.DataSourceConfig;
|
||||
import org.avaje.datasource.DataSourcePool;
|
||||
import org.avaje.datasource.pool.ConnectionPool;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
import org.tests.model.basic.UTMaster;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -27,7 +27,7 @@ public class TestAutoCommitDataSource extends BaseTestCase {
|
||||
@Test
|
||||
public void test() throws SQLException {
|
||||
|
||||
Properties properties = PropertyMap.defaultProperties();
|
||||
Properties properties = PropertiesLoader.load();
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(properties, "h2autocommit");//"pg"
|
||||
|
||||
@@ -5,14 +5,14 @@ import io.ebean.EbeanServer;
|
||||
import io.ebean.EbeanServerFactory;
|
||||
import io.ebean.Query;
|
||||
import io.ebean.Transaction;
|
||||
import io.ebean.config.PropertyMap;
|
||||
import io.ebean.config.ServerConfig;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
import org.tests.model.basic.UTMaster;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import org.avaje.datasource.DataSourceConfig;
|
||||
import org.avaje.datasource.DataSourcePool;
|
||||
import org.avaje.datasource.pool.ConnectionPool;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.UTDetail;
|
||||
import org.tests.model.basic.UTMaster;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
@@ -27,7 +27,7 @@ public class TestExplicitTransactionMode extends BaseTestCase {
|
||||
@Test
|
||||
public void test() throws SQLException {
|
||||
|
||||
Properties properties = PropertyMap.defaultProperties();
|
||||
Properties properties = PropertiesLoader.load();
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(properties, "h2autocommit");//"h2autocommit","pg"
|
||||
|
||||
Reference in New Issue
Block a user