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;
|
package de.staropensource.sosengine.base.srctests;
|
||||||
|
|
||||||
import de.staropensource.sosengine.base.EngineConfiguration;
|
import de.staropensource.sosengine.base.EngineConfiguration;
|
||||||
|
import de.staropensource.sosengine.base.types.LogLevel;
|
||||||
import de.staropensource.sosengine.unittests.UnitLogger;
|
import de.staropensource.sosengine.unittests.UnitLogger;
|
||||||
import org.joor.Reflect;
|
import org.joor.Reflect;
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
@ -21,6 +20,10 @@ class EngineConfigurationTest {
|
||||||
* The unit logger for this instance.
|
* The unit logger for this instance.
|
||||||
*/
|
*/
|
||||||
private final UnitLogger logger = new UnitLogger(getClass());
|
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.
|
* Initializes the {@link EngineConfiguration} class before each test.
|
||||||
|
@ -46,42 +49,39 @@ class EngineConfigurationTest {
|
||||||
void testLoadConfiguration() {
|
void testLoadConfiguration() {
|
||||||
logger.testCall("testLoadConfiguration");
|
logger.testCall("testLoadConfiguration");
|
||||||
|
|
||||||
EngineConfiguration config = EngineConfiguration.getInstance();
|
Map<String, Object[]> settings = new HashMap<>();
|
||||||
String group = EngineConfiguration.getGroup();
|
|
||||||
String[] keys = new String[]{
|
|
||||||
"debug",
|
|
||||||
"debugShortcodeConverter",
|
|
||||||
"errorShortcodeConverter",
|
|
||||||
"loggerLevel",
|
|
||||||
"loggerTemplate"
|
|
||||||
};
|
|
||||||
Map<String, Object> defaultValues = 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
|
// Load default configuration
|
||||||
config.loadDefaultConfiguration();
|
EngineConfiguration.getInstance().loadDefaultConfiguration();
|
||||||
|
|
||||||
// Save default values
|
// Save default values
|
||||||
for (String setting : keys)
|
for (String setting : settings.keySet())
|
||||||
defaultValues.put(setting, config.getSetting(setting));
|
defaultValues.put(setting, EngineConfiguration.getInstance().getSetting(setting));
|
||||||
|
|
||||||
// Load custom configuration
|
// Load custom configuration
|
||||||
Properties properties = new Properties();
|
Properties properties = new Properties();
|
||||||
|
|
||||||
properties.setProperty(group + "debug", "true");
|
for (String setting : settings.keySet())
|
||||||
properties.setProperty(group + "debugShortcodeConverter", "true");
|
properties.setProperty(group + setting, (String) settings.get(setting)[0]);
|
||||||
properties.setProperty(group + "errorShortcodeConverter", "false");
|
|
||||||
properties.setProperty(group + "loggerLevel", "diagnostic");
|
|
||||||
properties.setProperty(group + "loggerTemplate", "%log_path% says: %message%");
|
|
||||||
|
|
||||||
config.loadConfiguration(properties);
|
EngineConfiguration.getInstance().loadConfiguration(properties);
|
||||||
|
|
||||||
// Compare custom values against default ones
|
// Compare custom values against default ones
|
||||||
for (String setting : keys) {
|
for (String setting : settings.keySet()) {
|
||||||
Object defaultValue = defaultValues.get(setting);
|
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);
|
assertNotEquals(defaultValue, customValue);
|
||||||
|
logger.diag("Comparing setting " + setting + "(equals expected value)");
|
||||||
|
assertEquals(settings.get(setting)[1], customValue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue