diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java index adb846d93..d9216cd0e 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/AbstractDaoImplTest.java @@ -23,20 +23,17 @@ package li.strolch.persistence.impl.dao.test; import java.io.File; import java.text.MessageFormat; -import java.util.HashMap; -import java.util.Map; -import li.strolch.persistence.api.StrolchPersistenceHandler; import li.strolch.persistence.impl.XmlPersistenceHandler; import li.strolch.runtime.configuration.ComponentConfiguration; -import li.strolch.runtime.configuration.RuntimeConfiguration; +import li.strolch.runtime.configuration.ConfigurationParser; +import li.strolch.runtime.configuration.StrolchConfiguration; +import li.strolch.testbase.runtime.RuntimeMock; import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ch.eitchnet.utils.helper.FileHelper; - /** * @author Robert von Burg * @@ -44,6 +41,7 @@ import ch.eitchnet.utils.helper.FileHelper; public abstract class AbstractDaoImplTest { private static final String RUNTIME_PATH = "target/strolchRuntime/"; //$NON-NLS-1$ + private static final String CONFIG_SRC = "src/test/resources/runtime/config"; //$NON-NLS-1$ protected static final Logger logger = LoggerFactory.getLogger(AbstractDaoImplTest.class); protected static XmlPersistenceHandler persistenceHandler; @@ -51,36 +49,23 @@ public abstract class AbstractDaoImplTest { @BeforeClass public static void beforeClass() { - File file = new File(RUNTIME_PATH); - if (file.exists()) { - if (!FileHelper.deleteFile(file, true)) { - String msg = "Failed to delete {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, file.getAbsolutePath()); - throw new RuntimeException(msg); - } - } + File rootPath = new File(RUNTIME_PATH); + File configSrc = new File(CONFIG_SRC); + RuntimeMock.mockRuntime(rootPath, configSrc); - file = new File(file, XmlPersistenceHandler.DB_STORE_PATH); - if (!file.mkdirs()) { + File dbStorePath = new File(rootPath, XmlPersistenceHandler.DB_STORE_PATH); + if (!dbStorePath.mkdirs()) { String msg = "Failed to create path {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, file.getAbsolutePath()); + msg = MessageFormat.format(msg, dbStorePath.getAbsolutePath()); throw new RuntimeException(msg); } - // initialize a runtime configuration - Map runtimeConfigurationValues = new HashMap<>(); - String rootPath = RUNTIME_PATH; - RuntimeConfiguration runtimeConfiguration = new RuntimeConfiguration(runtimeConfigurationValues, rootPath); - // initialize the component configuration - String componentName = StrolchPersistenceHandler.class.getName(); - Map configurationValues = new HashMap<>(); - ComponentConfiguration componentConfiguration = new ComponentConfiguration(runtimeConfiguration, componentName, - configurationValues); - + StrolchConfiguration strolchConfiguration = ConfigurationParser.parseConfiguration(rootPath); + ComponentConfiguration componentConfiguration = strolchConfiguration + .getComponentConfiguration("PersistenceHandler"); //$NON-NLS-1$ persistenceHandler = new XmlPersistenceHandler(); persistenceHandler.initialize(componentConfiguration); } - } diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java index 2fe44c51d..b6c83a0d3 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlOrderDaoTest.java @@ -20,6 +20,16 @@ public class XmlOrderDaoTest extends AbstractDaoImplTest { private static final String NAME = "Test Order"; //$NON-NLS-1$ private static final String TYPE = "ToStock"; //$NON-NLS-1$ + @Test + public void shouldCreateOrder() { + + // create + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType", System.currentTimeMillis(), State.CREATED); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getOrderDao(tx).save(newOrder); + } + } + @Test public void shouldCrud() { diff --git a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java index 7832a4759..bb2117d0f 100644 --- a/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java +++ b/src/test/java/li/strolch/persistence/impl/dao/test/XmlResourceDaoTest.java @@ -19,6 +19,16 @@ public class XmlResourceDaoTest extends AbstractDaoImplTest { private static final String NAME = "Test Resource"; //$NON-NLS-1$ private static final String TYPE = "Box"; //$NON-NLS-1$ + @Test + public void shouldCreateOrder() { + + // create + Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = persistenceHandler.openTx();) { + persistenceHandler.getResourceDao(tx).save(newResource); + } + } + @Test public void shouldCrud() { diff --git a/src/test/resources/runtime/config/StrolchConfiguration.xml b/src/test/resources/runtime/config/StrolchConfiguration.xml new file mode 100644 index 000000000..89ea0f543 --- /dev/null +++ b/src/test/resources/runtime/config/StrolchConfiguration.xml @@ -0,0 +1,17 @@ + + + + StrolchPersistenceTest + + true + + + + PersistenceHandler + li.strolch.persistence.api.StrolchPersistenceHandler + li.strolch.persistence.impl.XmlPersistenceHandler + + true + + + \ No newline at end of file