Commit 324e5ce9 authored by NicolaiO's avatar NicolaiO 🐼

Merge branch '4-add-optional-impl-field-to-moduli-config' into 'master'

Resolve "Add optional impl field to moduli config"

Closes #4

See merge request !7
parents 9b13ca7c 5834f2b8
Pipeline #2516 passed with stage
in 1 minute and 34 seconds
......@@ -124,13 +124,21 @@ public class Moduli
// --- load modules into modulesList ---
for (int i = 0; i <= config.getMaxIndex("module"); i++)
{
Class<? extends AModule> id = (Class<? extends AModule>) Class
.forName(implsPath + config.getString(moduleMessage(i, "[@id]")));
// --- create implementation- and properties-class ---
Class<? extends AModule> clazz = (Class<? extends AModule>) Class
.forName(implsPath + config.getString(moduleMessage(i, "implementation")));
Class<? extends AModule> clazz;
final String implementationKey = moduleMessage(i, ".implementation");
if (config.containsKey(implementationKey))
{
clazz = (Class<? extends AModule>) Class.forName(implsPath + config.getString(implementationKey));
} else
{
clazz = id;
}
// --- get properties from configuration and put it into a object[] ---
SubnodeConfiguration moduleConfig = config.configurationAt(moduleMessage(i, "properties"));
SubnodeConfiguration moduleConfig = config.configurationAt(moduleMessage(i, ".properties"));
Constructor<?> clazzConstructor = clazz.getConstructor();
......@@ -141,7 +149,7 @@ public class Moduli
module.setSubnodeConfiguration(moduleConfig);
// --- set id ---
module.setId(clazz);
module.setId(id);
// --- check if module is unique ---
if (modules.containsKey(module.getId()))
......@@ -150,7 +158,7 @@ public class Moduli
}
// --- set dependency-list ---
List<String> rawDependencyList = Arrays.asList(config.getStringArray(moduleMessage(i, "dependency")));
List<String> rawDependencyList = Arrays.asList(config.getStringArray(moduleMessage(i, ".dependency")));
List<Class<? extends AModule>> dependencyList = new ArrayList<>();
for (String dependency : rawDependencyList)
{
......@@ -159,7 +167,7 @@ public class Moduli
module.setDependencies(dependencyList);
modules.put(clazz, module);
modules.put(id, module);
log.trace("Module created: " + module);
}
......@@ -395,6 +403,6 @@ public class Moduli
private String moduleMessage(int moduleNumber, String property)
{
return "module(" + moduleNumber + ")." + property;
return "module(" + moduleNumber + ")" + property;
}
}
......@@ -5,8 +5,6 @@
package edu.tigers.moduli;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.Before;
......@@ -41,7 +39,7 @@ public class ModuliTest
@Test
public void testModuliCycle() throws Exception
{
assertEquals(ModulesState.NOT_LOADED, moduli.getModulesState().get());
assertThat(moduli.getModulesState().get()).isEqualTo(ModulesState.NOT_LOADED);
moduli.loadModulesSafe(MODULE_CONFIG_PATH + "test_config.xml");
assertThat(moduli.getModulesState().get()).isEqualTo(ModulesState.RESOLVED);
......@@ -60,15 +58,15 @@ public class ModuliTest
{
moduli.loadModulesSafe(MODULE_CONFIG_PATH + "test_config.xml");
TestModule module = moduli.getModule(TestModule.class);
assertTrue(module.isConstructed());
assertThat(module.isConstructed()).isTrue();
moduli.startModules();
assertTrue(module.isInitialized());
assertTrue(module.isStarted());
assertThat(module.isInitialized()).isTrue();
assertThat(module.isStarted()).isTrue();
moduli.stopModules();
assertTrue(module.isStopped());
assertTrue(module.isDeinitialized());
assertThat(module.isStopped()).isTrue();
assertThat(module.isDeinitialized()).isTrue();
}
......
/*
* Copyright (c) 2009 - 2017, DHBW Mannheim - TIGERs Mannheim
*/
package edu.tigers.moduli.modules;
import edu.tigers.moduli.exceptions.InitModuleException;
import edu.tigers.moduli.exceptions.StartModuleException;
public class ConcreteTestModule extends TestModule
{
private boolean isConstructed = false;
private boolean isInitialized = false;
private boolean isStarted = false;
private boolean isStopped = false;
private boolean isDeinitialized = false;
public ConcreteTestModule()
{
this.isConstructed = true;
}
@Override
public void initModule() throws InitModuleException
{
isInitialized = true;
}
@Override
public void startModule() throws StartModuleException
{
isStarted = true;
}
@Override
public void stopModule()
{
isStopped = true;
}
@Override
public void deinitModule()
{
isDeinitialized = true;
}
@Override
public boolean isConstructed()
{
return isConstructed;
}
@Override
public boolean isInitialized()
{
return isInitialized;
}
@Override
public boolean isStarted()
{
return isStarted;
}
@Override
public boolean isStopped()
{
return isStopped;
}
@Override
public boolean isDeinitialized()
{
return isDeinitialized;
}
}
......@@ -5,79 +5,21 @@
package edu.tigers.moduli.modules;
import edu.tigers.moduli.AModule;
import edu.tigers.moduli.exceptions.InitModuleException;
import edu.tigers.moduli.exceptions.StartModuleException;
public class TestModule extends AModule
public abstract class TestModule extends AModule
{
private boolean isConstructed = false;
private boolean isInitialized = false;
private boolean isStarted = false;
private boolean isStopped = false;
private boolean isDeinitialized = false;
public abstract boolean isConstructed();
public TestModule()
{
this.isConstructed = true;
}
public abstract boolean isInitialized();
@Override
public void initModule() throws InitModuleException
{
isInitialized = true;
}
public abstract boolean isStarted();
@Override
public void startModule() throws StartModuleException
{
isStarted = true;
}
public abstract boolean isStopped();
@Override
public void stopModule()
{
isStopped = true;
}
@Override
public void deinitModule()
{
isDeinitialized = true;
}
public boolean isConstructed()
{
return isConstructed;
}
public boolean isInitialized()
{
return isInitialized;
}
public boolean isStarted()
{
return isStarted;
}
public boolean isStopped()
{
return isStopped;
}
public boolean isDeinitialized()
{
return isDeinitialized;
}
public abstract boolean isDeinitialized();
}
......@@ -7,14 +7,13 @@
<environment>MODULI</environment>
</globalConfiguration>
<module id="testModule">
<implementation>edu.tigers.moduli.modules.TestModule</implementation>
<module id="edu.tigers.moduli.modules.TestModule">
<implementation>edu.tigers.moduli.modules.ConcreteTestModule</implementation>
<properties></properties>
</module>
<module id="configuredModule">
<implementation>edu.tigers.moduli.modules.ConfiguredTestModule</implementation>
<module id="edu.tigers.moduli.modules.ConfiguredTestModule">
<properties>
<testProperty>exists</testProperty>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment