Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create sysconfig Environment Provider #262

Merged
merged 2 commits into from
Aug 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
}
}