mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Refactor to use avaje config (#1894)
* Move to use Avaje Config for properties loading
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package io.ebean.config;
|
||||
|
||||
import io.avaje.config.Config;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Properties;
|
||||
@@ -11,7 +11,6 @@ import static org.junit.Assert.assertNull;
|
||||
|
||||
public class PropertiesWrapperTest {
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetServerName() {
|
||||
|
||||
@@ -61,7 +60,7 @@ public class PropertiesWrapperTest {
|
||||
properties.put("somePath", "${HOME}/hello");
|
||||
properties.put("someSystemProp", "/aaa/${java.io.tmpdir}/bbb");
|
||||
|
||||
Properties evalCopy = PropertiesLoader.eval(properties);
|
||||
Properties evalCopy = Config.asConfiguration().eval(properties);
|
||||
PropertiesWrapper pw = new PropertiesWrapper("pref", "myserver", evalCopy, null);
|
||||
|
||||
assertEquals(42, pw.getInt("someInt", 99));
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
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() {
|
||||
|
||||
String userName = System.getProperty("user.name");
|
||||
String userHome = System.getProperty("user.home");
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadProperties("test-properties/application.properties", Loader.Source.RESOURCE);
|
||||
loader.loadYaml("test-properties/application.yaml", 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(userName, properties.getProperty("eval.name"));
|
||||
assertEquals(userHome + "/after", properties.getProperty("eval.home"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void loadWithExtensionCheck() {
|
||||
|
||||
Loader loader = new Loader();
|
||||
loader.loadWithExtensionCheck("test-dummy.properties");
|
||||
loader.loadWithExtensionCheck("test-dummy.yml");
|
||||
loader.loadWithExtensionCheck("test-dummy2.yaml");
|
||||
|
||||
Properties properties = loader.eval();
|
||||
assertThat(properties.getProperty("dummy.yaml.bar")).isEqualTo("baz");
|
||||
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");
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
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_emptyPlaceholder() {
|
||||
assertEquals("${}", PropertyEval.eval("${}"));
|
||||
}
|
||||
|
||||
@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");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.avaje.config.Config;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.DatabaseFactory;
|
||||
@@ -8,7 +9,6 @@ import io.ebean.Transaction;
|
||||
import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import io.ebean.datasource.DataSourcePool;
|
||||
import io.ebean.datasource.pool.ConnectionPool;
|
||||
@@ -30,7 +30,7 @@ public class TestAutoCommitDataSource extends BaseTestCase {
|
||||
@Test
|
||||
public void test() throws SQLException {
|
||||
|
||||
Properties properties = PropertiesLoader.load();
|
||||
Properties properties = Config.asProperties();
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(properties, "h2autocommit");//"pg"
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.tests.transaction;
|
||||
|
||||
import io.avaje.config.Config;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
@@ -10,7 +11,6 @@ import io.ebean.annotation.ForPlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.config.DatabaseConfig;
|
||||
import io.ebean.config.JsonConfig;
|
||||
import io.ebean.config.properties.PropertiesLoader;
|
||||
import io.ebean.datasource.DataSourceConfig;
|
||||
import io.ebean.datasource.DataSourcePool;
|
||||
import io.ebean.datasource.pool.ConnectionPool;
|
||||
@@ -35,7 +35,7 @@ public class TestExplicitTransactionMode extends BaseTestCase {
|
||||
@Test
|
||||
public void test() throws SQLException {
|
||||
|
||||
Properties properties = PropertiesLoader.load();
|
||||
Properties properties = Config.asProperties();
|
||||
|
||||
DataSourceConfig dsConfig = new DataSourceConfig();
|
||||
dsConfig.loadSettings(properties, "h2autocommit2");
|
||||
|
||||
Reference in New Issue
Block a user