diff --git a/src/test/java/li/strolch/runtime/test/component/ComponentContainerTest.java b/src/test/java/li/strolch/runtime/test/component/ComponentContainerTest.java index cf7b9deef..cef901d81 100644 --- a/src/test/java/li/strolch/runtime/test/component/ComponentContainerTest.java +++ b/src/test/java/li/strolch/runtime/test/component/ComponentContainerTest.java @@ -19,10 +19,12 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import java.io.File; +import java.text.MessageFormat; import li.strolch.model.Resource; import li.strolch.runtime.agent.ComponentContainer; import li.strolch.runtime.agent.StrolchAgent; +import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.test.component.model.PersistenceHandlerTest; import li.strolch.runtime.test.component.model.ServiceHandlerTest; import li.strolch.runtime.test.component.model.ServiceResultTest; @@ -31,6 +33,8 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.eitchnet.utils.helper.FileHelper; + @SuppressWarnings("nls") public class ComponentContainerTest { @@ -38,13 +42,18 @@ public class ComponentContainerTest { public static final String PATH_TRANSIENT_CONTAINER = "src/test/resources/transienttest"; public static final String PATH_EMPTY_CONTAINER = "src/test/resources/emptytest"; + public static final String PATH_REALM_RUNTIME = "target/realmtest/"; //$NON-NLS-1$ + public static final String PATH_TRANSIENT_RUNTIME = "target/transienttest/"; //$NON-NLS-1$ + public static final String PATH_EMPTY_RUNTIME = "target/emptytest/"; //$NON-NLS-1$ + private static final Logger logger = LoggerFactory.getLogger(ComponentContainerTest.class); + private static final String TARGET = "target"; //$NON-NLS-1$ @Test public void shouldStartEmptyContainer() { try { - StrolchAgent agent = startContainer(PATH_EMPTY_CONTAINER); + StrolchAgent agent = startContainer(PATH_EMPTY_RUNTIME, PATH_EMPTY_CONTAINER); testContainer(agent); destroyContainer(agent); } catch (Exception e) { @@ -57,7 +66,7 @@ public class ComponentContainerTest { public void shouldStartTransientContainer() { try { - StrolchAgent agent = startContainer(PATH_TRANSIENT_CONTAINER); + StrolchAgent agent = startContainer(PATH_TRANSIENT_RUNTIME, PATH_TRANSIENT_CONTAINER); testContainer(agent); destroyContainer(agent); } catch (Exception e) { @@ -70,7 +79,7 @@ public class ComponentContainerTest { public void shouldStartRealmTestContainer() { try { - StrolchAgent agent = startContainer(PATH_REALM_CONTAINER); + StrolchAgent agent = startContainer(PATH_REALM_RUNTIME, PATH_REALM_CONTAINER); testContainer(agent); destroyContainer(agent); } catch (Exception e) { @@ -79,11 +88,6 @@ public class ComponentContainerTest { } } - public static StrolchAgent startContainer(String rootPath) { - File rootPathF = new File(rootPath); - return startContainer(rootPathF); - } - private static void testContainer(StrolchAgent agent) { ComponentContainer container = agent.getContainer(); @@ -98,6 +102,13 @@ public class ComponentContainerTest { assertEquals("@testRes", resource.getId()); } + public static StrolchAgent startContainer(String rootPath, String configSrc) { + File rootPathF = new File(rootPath); + File configSrcF = new File(configSrc); + mockRuntime(rootPathF, configSrcF); + return startContainer(rootPathF); + } + public static StrolchAgent startContainer(File rootPathF) { StrolchAgent agent = new StrolchAgent(); agent.setup(rootPathF); @@ -111,4 +122,57 @@ public class ComponentContainerTest { agent.stop(); agent.destroy(); } + + public static void mockRuntime(File rootPathF, File rootSrc) { + + 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); + } + + File configSrc = new File(rootSrc, RuntimeConfiguration.PATH_CONFIG); + File dataSrc = new File(rootSrc, RuntimeConfiguration.PATH_DATA); + + 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()) { + logger.info("Deleting all files in " + rootPathF.getAbsolutePath()); //$NON-NLS-1$ + 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); + } + + if (dataSrc.exists()) { + File dataPathF = new File(rootPathF, RuntimeConfiguration.PATH_DATA); + dataPathF.mkdir(); + + if (!FileHelper.copy(dataSrc.listFiles(), dataPathF, false)) { + String msg = "Failed to copy source data from {0} to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, configSrc.getAbsolutePath(), configPathF.getAbsolutePath()); + throw new RuntimeException(msg); + } + } + } } diff --git a/src/test/java/li/strolch/runtime/test/query/inmemory/QueryTest.java b/src/test/java/li/strolch/runtime/test/query/inmemory/QueryTest.java index afe5bbb7f..2a1a5d831 100644 --- a/src/test/java/li/strolch/runtime/test/query/inmemory/QueryTest.java +++ b/src/test/java/li/strolch/runtime/test/query/inmemory/QueryTest.java @@ -48,10 +48,13 @@ import org.junit.Test; @SuppressWarnings("nls") public class QueryTest { + public static final String PATH_EMPTY_RUNTIME = "target/QueryTest/"; //$NON-NLS-1$ + @Test public void shouldQueryResourceWithParamValue() { - StrolchAgent agent = ComponentContainerTest.startContainer(ComponentContainerTest.PATH_EMPTY_CONTAINER); + StrolchAgent agent = ComponentContainerTest.startContainer(PATH_EMPTY_RUNTIME, + ComponentContainerTest.PATH_EMPTY_CONTAINER); Resource res1 = createResource("@1", "Test Resource", "MyType"); IntegerParameter iP = new IntegerParameter("nbOfBooks", "Number of Books", 33); res1.addParameter(BAG_ID, iP); @@ -74,7 +77,8 @@ public class QueryTest { @Test public void shouldQueryOrderWithParamValue() { - StrolchAgent agent = ComponentContainerTest.startContainer(ComponentContainerTest.PATH_EMPTY_CONTAINER); + StrolchAgent agent = ComponentContainerTest.startContainer(PATH_EMPTY_RUNTIME, + ComponentContainerTest.PATH_EMPTY_CONTAINER); Order o1 = createOrder("@1", "Test Order", "MyType"); IntegerParameter iP = new IntegerParameter("nbOfBooks", "Number of Books", 33); o1.addParameter(BAG_ID, iP);