diff --git a/pom.xml b/pom.xml index 3adeaabe1..e9647fab8 100644 --- a/pom.xml +++ b/pom.xml @@ -34,6 +34,10 @@ li.strolch li.strolch.model + + li.strolch + li.strolch.runtime + diff --git a/src/main/java/li/strolch/testbase/runtime/ComponentMock.java b/src/main/java/li/strolch/testbase/runtime/ComponentMock.java new file mode 100644 index 000000000..2696b7866 --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/ComponentMock.java @@ -0,0 +1,11 @@ +package li.strolch.testbase.runtime; + +import li.strolch.runtime.component.StrolchComponent; +import li.strolch.runtime.configuration.StrolchConfiguration; + +public interface ComponentMock { + + public StrolchComponent getComponent(); + + public void mock(StrolchConfiguration configuration); +} diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java new file mode 100644 index 000000000..2cdaf44eb --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -0,0 +1,64 @@ +package li.strolch.testbase.runtime; + +import java.io.File; +import java.text.MessageFormat; + +import li.strolch.runtime.configuration.RuntimeConfiguration; +import ch.eitchnet.utils.helper.FileHelper; + +public class RuntimeMock { + + private static final String TARGET = "target"; //$NON-NLS-1$ + + public static void mockRuntime(File rootPathF, File configSrc) { + + if (!rootPathF.getParentFile().getName().equals(TARGET)) { + String msg = "Mocking path must be in a maven target: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + throw new RuntimeException(msg); + } + + if (!configSrc.isDirectory() || !configSrc.canRead()) { + String msg = "Could not find config source in: {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, configSrc.getAbsolutePath()); + throw new RuntimeException(msg); + } + + if (rootPathF.exists()) { + if (!FileHelper.deleteFile(rootPathF, true)) { + String msg = "Failed to delete {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + throw new RuntimeException(msg); + } + } + + if (!rootPathF.mkdirs()) { + String msg = "Failed to create {0}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + throw new RuntimeException(msg); + } + + File configPathF = new File(rootPathF, RuntimeConfiguration.PATH_CONFIG); + configPathF.mkdir(); + + if (!FileHelper.copy(configSrc.listFiles(), configPathF, false)) { + String msg = "Failed to copy source configs from {0} to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, configSrc.getAbsolutePath(), configPathF.getAbsolutePath()); + throw new RuntimeException(msg); + } +// +// // initialize a runtime configuration +// Map runtimeConfigurationValues = new HashMap<>(); +// RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration("RuntimeMock", runtimeConfigurationValues, //$NON-NLS-1$ +// rootPathF); +// +// Map configurationByComponent = new HashMap<>(); +// StrolchConfiguration configuration = new StrolchConfiguration(runtimeConfiguration, configurationByComponent); +// +// // initialize the component configuration +// for (ComponentMock componentMock : runtimeMocks) { +// //configurationByComponent.put(key, value) +// componentMock.mock(configuration); +// } + } +}