-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #262 from Gaston-G/master
Create sysconfig Environment Provider
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
modules/sysconfig/src/main/java/org/jpos/ee/SysConfigEnvironmentProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jpos.ee; | ||
|
||
import org.jpos.core.EnvironmentProvider; | ||
import java.util.Objects; | ||
|
||
public class SysConfigEnvironmentProvider implements EnvironmentProvider { | ||
protected <T> T exec(DBAction<T> 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); | ||
} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
modules/sysconfig/src/main/resources/META-INF/services/org.jpos.core.EnvironmentProvider
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.jpos.ee.SysConfigEnvironmentProvider |
31 changes: 31 additions & 0 deletions
31
modules/sysconfig/src/test/java/org/jpos/ee/SysConfigEnvironmentProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> T exec(DBAction<T> 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)); | ||
} | ||
} |