-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#29 : API: Loaders system:properties and system:env
- Loading branch information
Showing
6 changed files
with
114 additions
and
3 deletions.
There are no files selected for viewing
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
19 changes: 19 additions & 0 deletions
19
core/src/main/java/net/cactusthorn/config/core/loader/SystemEnvLoader.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,19 @@ | ||
package net.cactusthorn.config.core.loader; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public class SystemEnvLoader implements Loader { | ||
|
||
private static final String SCHEME = "system"; | ||
private static final String PART = "env"; | ||
|
||
@Override public boolean accept(URI uri) { | ||
return uri.isOpaque() && SCHEME.equals(uri.getScheme()) && uri.getSchemeSpecificPart().equals(PART); | ||
} | ||
|
||
public Map<String, String> load(URI uri, ClassLoader classLoader) { | ||
return System.getenv(); | ||
} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
core/src/main/java/net/cactusthorn/config/core/loader/SystemPropertiesLoader.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,19 @@ | ||
package net.cactusthorn.config.core.loader; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
public class SystemPropertiesLoader implements Loader { | ||
|
||
private static final String SCHEME = "system"; | ||
private static final String PART = "properties"; | ||
|
||
@Override public boolean accept(URI uri) { | ||
return uri.isOpaque() && SCHEME.equals(uri.getScheme()) && uri.getSchemeSpecificPart().equals(PART); | ||
} | ||
|
||
@Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Map<String, String> load(URI uri, ClassLoader classLoader) { | ||
return (Map) System.getProperties(); | ||
} | ||
|
||
} |
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
36 changes: 36 additions & 0 deletions
36
core/src/test/java/net/cactusthorn/config/core/loader/SystemEnvLoaderTest.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,36 @@ | ||
package net.cactusthorn.config.core.loader; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SystemEnvLoaderTest { | ||
|
||
private static final Loader CPP = new SystemEnvLoader(); | ||
private static final ClassLoader CL = SystemEnvLoaderTest.class.getClassLoader(); | ||
private static final URI SEURI = URI.create("system:env"); | ||
|
||
@Test public void acceptSimple() { | ||
assertTrue(CPP.accept(SEURI)); | ||
} | ||
|
||
@Test public void notAcceptNotOpaque() { | ||
assertFalse(CPP.accept(URI.create("classpath://a.properties#ISO-8859-1"))); | ||
} | ||
|
||
@Test public void notAcceptNotSystem() { | ||
assertFalse(CPP.accept(URI.create("classpath:a.properties"))); | ||
} | ||
|
||
@Test public void notAcceptNotProperties() { | ||
assertFalse(CPP.accept(URI.create("system:properties"))); | ||
} | ||
|
||
@Test public void load() { | ||
Map<String, String> values = CPP.load(SEURI, CL); | ||
assertFalse(values.isEmpty()); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
core/src/test/java/net/cactusthorn/config/core/loader/SystemPropertiesLoaderTest.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,37 @@ | ||
package net.cactusthorn.config.core.loader; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import java.net.URI; | ||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class SystemPropertiesLoaderTest { | ||
|
||
private static final Loader CPP = new SystemPropertiesLoader(); | ||
private static final ClassLoader CL = SystemPropertiesLoaderTest.class.getClassLoader(); | ||
private static final URI SPURI = URI.create("system:properties"); | ||
|
||
@Test public void acceptSimple() { | ||
assertTrue(CPP.accept(SPURI)); | ||
} | ||
|
||
@Test public void notAcceptNotOpaque() { | ||
assertFalse(CPP.accept(URI.create("classpath://a.properties#ISO-8859-1"))); | ||
} | ||
|
||
@Test public void notAcceptNotSystem() { | ||
assertFalse(CPP.accept(URI.create("classpath:a.properties"))); | ||
} | ||
|
||
@Test public void notAcceptNotProperties() { | ||
assertFalse(CPP.accept(URI.create("system:abc"))); | ||
} | ||
|
||
@Test public void load() { | ||
System.setProperty("TEST", "TESTVALUE"); | ||
Map<String, String> values = CPP.load(SPURI, CL); | ||
assertEquals("TESTVALUE", values.get("TEST")); | ||
} | ||
} |