Feat/#309 read config from arbitrary directories#386
Conversation
… and adding a couple test cases to the CentralizedManagement class
- trim the default value - Added tests for type cast - Added test for exclusion injection - Since the mergeMap is merge the map in place, I deleted the return
… into fix/config-gaps # Conflicts: # config/src/test/java/com/networknt/config/TestCentralizedManagement.java # config/src/test/resources/config/config.yml
| } | ||
| if (isBoolean(str)) { | ||
| return str.equals("true") || str.equals("True") || str.equals("TRUE") ? true : false; | ||
| } |
There was a problem hiding this comment.
Can be simplified to just return str.equals("true") || str.equals("True") || str.equals("TRUE"); right?
There was a problem hiding this comment.
or
return str.toLowerCase().equals("true");
There was a problem hiding this comment.
Yes, I will simplify it. @miklish The reason why I didn't use toLowerCase() is to uniform with yaml rules, ie "tRue", "trUe", etc. should not be recognized as boolean. Do you think it makes sense?
There was a problem hiding this comment.
It simply depends on how strict you want your parsing to be in this instance.
There was a problem hiding this comment.
@jiachen1120 Agreed, we shouldn't use toLowerCase.
Actually, if you want to be even closer to the yaml boolean spec, we would use these:
y|Y|yes|Yes|YES|n|N|no|No|NO
|true|True|TRUE|false|False|FALSE
|on|On|ON|off|Off|OFF
There was a problem hiding this comment.
Sure, I will improve it to be more strict.
There was a problem hiding this comment.
And I will modify the light-doc as well.
Related issue: #309
Related RFC: https://github.com/networknt/light-rfcs/blob/master/light-4j/0012-flexible-config-directory.md
Three new overloaded methods provided, in this PR, the path can only be the path relative to light-4j-config-dir.
public abstract Map<String, Object> getJsonMapConfig(String configName, String path);
public abstract Map<String, Object> getJsonMapConfigNoCache(String configName, String path);
public abstract Object getJsonObjectConfig(String configName, Class clazz, String path);
Extended ConfigDefaultTest to included the test for these methods. The ConfigDefaultTest could not work properly before if build the whole light-4j project entirely. Since the config is a singleton and shared by all classes, the instance of config would already exist before running ConfigDefaultTest. If we set the light-4j-config-dir directly, it cannot be injected into config instance. So the config in ConfigDefaultTest would still be the classpath one. So now I use reflection to inject field in the test.
Look forward to your review!