-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
250 additions
and
0 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
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
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
20 changes: 20 additions & 0 deletions
20
...e/src/main/java/org/fugerit/java/simple/config/microprofile/ConfigParamsMicroprofile.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,20 @@ | ||
package org.fugerit.java.simple.config.microprofile; | ||
|
||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.fugerit.java.simple.config.ConfigParams; | ||
|
||
import java.util.Optional; | ||
|
||
public class ConfigParamsMicroprofile implements ConfigParams { | ||
|
||
|
||
@Override | ||
public String getValue(String name) { | ||
return ConfigProvider.getConfig().getValue( name, String.class ); | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
return ConfigProvider.getConfig().getOptionalValue( name, String.class ); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
...t/java/test/org/fugerit/java/simple/config/microprofile/TestConfigParamsMicroprofile.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,98 @@ | ||
package test.org.fugerit.java.simple.config.microprofile; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.config.ConfigValue; | ||
import org.eclipse.microprofile.config.spi.ConfigBuilder; | ||
import org.eclipse.microprofile.config.spi.ConfigProviderResolver; | ||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.eclipse.microprofile.config.spi.Converter; | ||
import org.fugerit.java.simple.config.ConfigParams; | ||
import org.fugerit.java.simple.config.ConfigParamsDefault; | ||
import org.fugerit.java.simple.config.microprofile.ConfigParamsMicroprofile; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
class TestConfigParamsMicroprofile { | ||
|
||
@Test | ||
void testConfigParamsMicroprofile() throws IOException { | ||
Properties configProperties = new Properties(); | ||
try (InputStream is = new FileInputStream( "src/test/resources/testconfig.properties" ) ) { | ||
configProperties.load( is ); | ||
} | ||
ConfigParamsDefault configHelper = new ConfigParamsDefault( configProperties ); | ||
ConfigProviderResolver.setInstance(new ConfigProviderResolver() { | ||
@Override | ||
public Config getConfig() { | ||
return new Config() { | ||
@Override | ||
public <T> T getValue(String s, Class<T> aClass) { | ||
if ( aClass == String.class ) { | ||
return (T) configHelper.getValue( s ); | ||
} else { | ||
return null; | ||
} | ||
} | ||
@Override | ||
public ConfigValue getConfigValue(String s) { | ||
return null; | ||
} | ||
@Override | ||
public <T> Optional<T> getOptionalValue(String s, Class<T> aClass) { | ||
if ( aClass == String.class ) { | ||
return (Optional<T>) configHelper.getOptionalValue( s ); | ||
} else { | ||
return null; | ||
} | ||
} | ||
@Override | ||
public Iterable<String> getPropertyNames() { | ||
return null; | ||
} | ||
@Override | ||
public Iterable<ConfigSource> getConfigSources() { | ||
return null; | ||
} | ||
@Override | ||
public <T> Optional<Converter<T>> getConverter(Class<T> aClass) { | ||
return Optional.empty(); | ||
} | ||
@Override | ||
public <T> T unwrap(Class<T> aClass) { | ||
return null; | ||
} | ||
}; | ||
} | ||
@Override | ||
public Config getConfig(ClassLoader classLoader) { | ||
return null; | ||
} | ||
@Override | ||
public ConfigBuilder getBuilder() { | ||
return null; | ||
} | ||
@Override | ||
public void registerConfig(Config config, ClassLoader classLoader) { | ||
} | ||
@Override | ||
public void releaseConfig(Config config) { | ||
} | ||
}); | ||
// actual testing | ||
ConfigParams config = new ConfigParamsMicroprofile(); | ||
String value1 = config.getValue( "testconfig.param1" ); | ||
Assertions.assertEquals( "value1", value1 ); | ||
Optional<String> value2 = config.getOptionalValue( "testconfig.param2" ); | ||
Assertions.assertEquals( "value2", value2.get() ); | ||
Optional<String> valueX = config.getOptionalValue( "testconfig.paramX" ); | ||
Assertions.assertFalse( valueX.isPresent() ); | ||
} | ||
|
||
} |
1 change: 1 addition & 0 deletions
1
simple-config-microprofile/src/test/resources/simplelogger.properties
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.slf4j.simpleLogger.defaultLogLevel=debug |
4 changes: 4 additions & 0 deletions
4
simple-config-microprofile/src/test/resources/testconfig.properties
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,4 @@ | ||
# config params default test params | ||
testconfig.param1=value1 | ||
testconfig.param2=value2 | ||
testconfig.param3=value3 |
11 changes: 11 additions & 0 deletions
11
simple-config/src/main/java/org/fugerit/java/simple/config/ConfigParams.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,11 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import java.util.Optional; | ||
|
||
public interface ConfigParams { | ||
|
||
String getValue( String name ); | ||
|
||
Optional<String> getOptionalValue( String name ); | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
simple-config/src/main/java/org/fugerit/java/simple/config/ConfigParamsDefault.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,42 @@ | ||
package org.fugerit.java.simple.config; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
@Slf4j | ||
public class ConfigParamsDefault implements ConfigParams { | ||
|
||
private String configNamespace; | ||
|
||
private Properties configProperties; | ||
|
||
public ConfigParamsDefault(String configNamespace, Properties configProperties) { | ||
this.configNamespace = configNamespace; | ||
this.configProperties = configProperties; | ||
} | ||
|
||
public ConfigParamsDefault(Properties configProperties) { | ||
this( "", configProperties ); | ||
} | ||
|
||
@Override | ||
public String getValue(String name) { | ||
String key = this.configNamespace+name; | ||
String value = this.configProperties.getProperty( this.configNamespace+name ); | ||
log.debug( "key : {}, value : {}", key, value ); | ||
return value; | ||
} | ||
|
||
@Override | ||
public Optional<String> getOptionalValue(String name) { | ||
String value = this.getValue( name ); | ||
if ( value == null ) { | ||
return Optional.empty(); | ||
} else { | ||
return Optional.of( value ); | ||
} | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
simple-config/src/test/java/teat/org/fugerit/java/simple/config/TestConfigParamsDefault.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 teat.org.fugerit.java.simple.config; | ||
|
||
import org.fugerit.java.simple.config.ConfigParamsDefault; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.FileInputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Optional; | ||
import java.util.Properties; | ||
|
||
class TestConfigParamsDefault { | ||
|
||
@Test | ||
void testConfigParams() throws IOException { | ||
try (InputStream is = new FileInputStream( "src/test/resources/testconfig.properties" ) ) { | ||
Properties configProperties = new Properties(); | ||
configProperties.load( is ); | ||
ConfigParamsDefault config = new ConfigParamsDefault( configProperties ); | ||
String value1 = config.getValue( "testconfig.param1" ); | ||
Assertions.assertEquals( "value1", value1 ); | ||
Optional<String> value2 = config.getOptionalValue( "testconfig.param2" ); | ||
Assertions.assertEquals( "value2", value2.get() ); | ||
Optional<String> valueX = config.getOptionalValue( "testconfig.paramX" ); | ||
Assertions.assertFalse( valueX.isPresent() ); | ||
} | ||
} | ||
|
||
} | ||
|
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.slf4j.simpleLogger.defaultLogLevel=debug |
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,4 @@ | ||
# config params default test params | ||
testconfig.param1=value1 | ||
testconfig.param2=value2 | ||
testconfig.param3=value3 |