Skip to content

Commit

Permalink
Merge pull request #262 from Gaston-G/master
Browse files Browse the repository at this point in the history
Create sysconfig Environment Provider
  • Loading branch information
ar authored Aug 25, 2022
2 parents acbbf89 + 7943d77 commit 7168a1b
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.jpos.ee.SysConfigEnvironmentProvider
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));
}
}

0 comments on commit 7168a1b

Please # to comment.