forked from StarOpenSource/Engine
Make EngineConfiguration test better
This commit is contained in:
parent
9f646db94a
commit
47c962738b
1 changed files with 24 additions and 24 deletions
|
@ -1,13 +1,12 @@
|
|||
package de.staropensource.sosengine.base.srctests;
|
||||
|
||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||
import de.staropensource.sosengine.base.types.LogLevel;
|
||||
import de.staropensource.sosengine.unittests.UnitLogger;
|
||||
import org.joor.Reflect;
|
||||
import org.junit.jupiter.api.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
|
@ -21,6 +20,10 @@ class EngineConfigurationTest {
|
|||
* The unit logger for this instance.
|
||||
*/
|
||||
private final UnitLogger logger = new UnitLogger(getClass());
|
||||
/**
|
||||
* The property group for the base engine.
|
||||
*/
|
||||
private final String group = EngineConfiguration.getGroup();
|
||||
|
||||
/**
|
||||
* Initializes the {@link EngineConfiguration} class before each test.
|
||||
|
@ -46,42 +49,39 @@ class EngineConfigurationTest {
|
|||
void testLoadConfiguration() {
|
||||
logger.testCall("testLoadConfiguration");
|
||||
|
||||
EngineConfiguration config = EngineConfiguration.getInstance();
|
||||
String group = EngineConfiguration.getGroup();
|
||||
String[] keys = new String[]{
|
||||
"debug",
|
||||
"debugShortcodeConverter",
|
||||
"errorShortcodeConverter",
|
||||
"loggerLevel",
|
||||
"loggerTemplate"
|
||||
};
|
||||
Map<String, Object[]> settings = new HashMap<>();
|
||||
Map<String, Object> defaultValues = new HashMap<>();
|
||||
|
||||
settings.put("debug", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("debugShortcodeConverter", new Object[]{ "true", Boolean.TRUE });
|
||||
settings.put("errorShortcodeConverter", new Object[]{ "false", Boolean.FALSE });
|
||||
settings.put("loggerLevel", new Object[]{ "verbose", LogLevel.VERBOSE });
|
||||
settings.put("loggerTemplate", new Object[]{ "%log_path% says: %message%", "%log_path% says: %message%" });
|
||||
|
||||
// Load default configuration
|
||||
config.loadDefaultConfiguration();
|
||||
EngineConfiguration.getInstance().loadDefaultConfiguration();
|
||||
|
||||
// Save default values
|
||||
for (String setting : keys)
|
||||
defaultValues.put(setting, config.getSetting(setting));
|
||||
for (String setting : settings.keySet())
|
||||
defaultValues.put(setting, EngineConfiguration.getInstance().getSetting(setting));
|
||||
|
||||
// Load custom configuration
|
||||
Properties properties = new Properties();
|
||||
|
||||
properties.setProperty(group + "debug", "true");
|
||||
properties.setProperty(group + "debugShortcodeConverter", "true");
|
||||
properties.setProperty(group + "errorShortcodeConverter", "false");
|
||||
properties.setProperty(group + "loggerLevel", "diagnostic");
|
||||
properties.setProperty(group + "loggerTemplate", "%log_path% says: %message%");
|
||||
for (String setting : settings.keySet())
|
||||
properties.setProperty(group + setting, (String) settings.get(setting)[0]);
|
||||
|
||||
config.loadConfiguration(properties);
|
||||
EngineConfiguration.getInstance().loadConfiguration(properties);
|
||||
|
||||
// Compare custom values against default ones
|
||||
for (String setting : keys) {
|
||||
for (String setting : settings.keySet()) {
|
||||
Object defaultValue = defaultValues.get(setting);
|
||||
Object customValue = config.getSetting(setting);
|
||||
Object customValue = EngineConfiguration.getInstance().getSetting(setting);
|
||||
|
||||
logger.diag("Comparing setting " + setting);
|
||||
logger.diag("Comparing setting " + setting + "(not equals defaultValue)");
|
||||
assertNotEquals(defaultValue, customValue);
|
||||
logger.diag("Comparing setting " + setting + "(equals expected value)");
|
||||
assertEquals(settings.get(setting)[1], customValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue