diff --git a/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigEnvironmentProvider.java b/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigEnvironmentProvider.java new file mode 100644 index 0000000000..267c43935e --- /dev/null +++ b/modules/sysconfig/src/main/java/org/jpos/ee/SysConfigEnvironmentProvider.java @@ -0,0 +1,28 @@ +package org.jpos.ee; + +import org.jpos.core.EnvironmentProvider; +import java.util.Objects; + +public class SysConfigEnvironmentProvider implements EnvironmentProvider { + protected T exec(DBAction action) throws Exception { + return org.jpos.ee.DB.exec(action); + } + + public String prefix() { + return "sys::"; + } + + @Override + public String get(String config) { + Objects.requireNonNull(config); + + try { + return exec(db -> { + SysConfigManager scm = new SysConfigManager(db); + return scm.get(config); + }); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } +} diff --git a/modules/sysconfig/src/main/resources/META-INF/services/org.jpos.core.EnvironmentProvider b/modules/sysconfig/src/main/resources/META-INF/services/org.jpos.core.EnvironmentProvider new file mode 100644 index 0000000000..092325cd04 --- /dev/null +++ b/modules/sysconfig/src/main/resources/META-INF/services/org.jpos.core.EnvironmentProvider @@ -0,0 +1 @@ +org.jpos.ee.SysConfigEnvironmentProvider \ No newline at end of file diff --git a/modules/sysconfig/src/test/java/org/jpos/ee/SysConfigEnvironmentProviderTest.java b/modules/sysconfig/src/test/java/org/jpos/ee/SysConfigEnvironmentProviderTest.java new file mode 100644 index 0000000000..1f18900af9 --- /dev/null +++ b/modules/sysconfig/src/test/java/org/jpos/ee/SysConfigEnvironmentProviderTest.java @@ -0,0 +1,31 @@ +package org.jpos.ee; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; + +public class SysConfigEnvironmentProviderTest { + + @SuppressWarnings("unchecked") + SysConfigEnvironmentProvider getProvider() { + return new SysConfigEnvironmentProvider() { + @Override + protected T exec(DBAction action) throws Exception { + return (T) "someValue"; + } + }; + } + + @Test + void testGetValue() { + SysConfigEnvironmentProvider p = getProvider(); + String value = p.get("someKey"); + assertEquals("someValue", value); + } + + @Test + void testKeyIsNull() { + assertThrows(NullPointerException.class, () -> getProvider().get(null)); + } +}