From 8efe85d6c89b13bfddb89b4670063cbbabc88d57 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 11:29:06 -0700 Subject: [PATCH 01/42] Initial commit --- .gitignore | 1 + LICENSE | 191 +++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 ++ 3 files changed, 196 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..2f7896d1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 000000000..37ec93a14 --- /dev/null +++ b/LICENSE @@ -0,0 +1,191 @@ +Apache License +Version 2.0, January 2004 +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, "control" means (i) the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the +outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising +permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +"Object" form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +"submitted" means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +2. Grant of Copyright License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +3. Grant of Patent License. + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +You must give any other recipients of the Work or Derivative Works a copy of +this License; and +You must cause any modified files to carry prominent notices stating that You +changed the files; and +You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +If the Work includes a "NOTICE" text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +5. Submission of Contributions. + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +6. Trademarks. + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +8. Limitation of Liability. + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets "[]" replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same "printed page" as the copyright notice for easier identification within +third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 000000000..6c1466737 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +li.strolch.testbase +=================== + +Test base for the li.strolch.* projects From c57693d9c3e774e46b425e2d0588c89afd9aec09 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 24 Oct 2013 21:49:04 +0200 Subject: [PATCH 02/42] [New] Added a ModelBuilder to conveniently create Resources and Orders --- .gitignore | 3 + pom.xml | 63 ++++++ .../strolch/testbase/model/ModelBuilder.java | 179 ++++++++++++++++++ 3 files changed, 245 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/li/strolch/testbase/model/ModelBuilder.java diff --git a/.gitignore b/.gitignore index 2f7896d1d..96dedc20e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ target/ +/.project +/.classpath +/.settings diff --git a/pom.xml b/pom.xml new file mode 100644 index 000000000..3adeaabe1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,63 @@ + + 4.0.0 + + + li.strolch + li.strolch.parent + 0.1.0-SNAPSHOT + ../li.strolch.parent/pom.xml + + + li.strolch.testbase + + runtime for Strolch + runtime for Strolch + + https://github.com/eitch/li.strolch.testbase + + 2011 + + + Github Issues + https://github.com/eitch/li.strolch.testbase/issues + + + + scm:git:https://github.com/eitch/li.strolch.testbase.git + scm:git:git@github.com:eitch/li.strolch.testbase.git + https://github.com/eitch/li.strolch.testbase + + + + + li.strolch + li.strolch.model + + + + + + + org.apache.maven.plugins + maven-eclipse-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-source-plugin + + + org.apache.maven.plugins + maven-jar-plugin + + + org.apache.maven.plugins + maven-site-plugin + + + + \ No newline at end of file diff --git a/src/main/java/li/strolch/testbase/model/ModelBuilder.java b/src/main/java/li/strolch/testbase/model/ModelBuilder.java new file mode 100644 index 000000000..77dda9446 --- /dev/null +++ b/src/main/java/li/strolch/testbase/model/ModelBuilder.java @@ -0,0 +1,179 @@ +/* + * Copyright (c) 2012, Robert von Burg + * + * All rights reserved. + * + * This file is part of the li.strolch.model. + * + * li.strolch.model is free software: you can redistribute + * it and/or modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation, either version 3 of the License, + * or (at your option) any later version. + * + * li.strolch.model is distributed in the hope that it will + * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with li.strolch.model. If not, see + * . + */ +package li.strolch.testbase.model; + +import java.util.ArrayList; + +import li.strolch.model.Order; +import li.strolch.model.ParameterBag; +import li.strolch.model.Resource; +import li.strolch.model.State; +import li.strolch.model.parameter.BooleanParameter; +import li.strolch.model.parameter.DateParameter; +import li.strolch.model.parameter.FloatParameter; +import li.strolch.model.parameter.IntegerParameter; +import li.strolch.model.parameter.LongParameter; +import li.strolch.model.parameter.Parameter; +import li.strolch.model.parameter.StringListParameter; +import li.strolch.model.parameter.StringParameter; + +/** + * @author Robert von Burg + * + */ +@SuppressWarnings("nls") +public class ModelBuilder { + + public static final String PARAM_BOOLEAN_ID = "@param1"; + public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; + + public static final String PARAM_FLOAT_ID = "@param2"; + public static final String PARAM_FLOAT_NAME = "Float Param"; + + public static final String PARAM_INTEGER_ID = "@param3"; + public static final String PARAM_INTEGER_NAME = "Integer Param"; + + public static final String PARAM_LONG_ID = "@param4"; + public static final String PARAM_LONG_NAME = "Long Param"; + + public static final String PARAM_STRING_ID = "@param5"; + public static final String PARAM_STRING_NAME = "String Param"; + + public static final String PARAM_DATE_ID = "@param6"; + public static final String PARAM_DATE_NAME = "Date Param"; + + public static final String PARAM_LIST_STRING_ID = "@param7"; + public static final String PARAM_LIST_STRING_NAME = "StringList Param"; + + public static final String BAG_ID = "@bag01"; + public static final String BAG_NAME = "Test Bag"; + public static final String BAG_TYPE = "TestBag"; + + /** + * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Resource} + * @param name + * the name of the {@link Resource} + * @param type + * the type of the {@link Resource} + * + * @return the newly created {@link Resource} + */ + public static Resource createResource(String id, String name, String type) { + Resource resource = new Resource(id, name, type); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + resource.addParameterBag(bag); + + return resource; + } + + /** + * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling + * {@link #createParameterBag(String, String, String)} + * + * @param id + * the id of the {@link Order} + * @param name + * the name of the {@link Order} + * @param type + * the type of the {@link Order} + * @param date + * the date of the {@link Order} + * @param state + * the {@link State} of the {@link Order} + * + * @return the newly created {@link Order} + */ + public static Order createOrder(String id, String name, String type, long date, State state) { + + Order order = new Order(id, name, type, date, state); + ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); + order.addParameterBag(bag); + + return order; + } + + /** + * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add + * {@link Parameter}s + * + * @param id + * the id of the {@link ParameterBag} + * @param name + * the name of the {@link ParameterBag} + * @param type + * the type of the {@link ParameterBag} + * + * @return the newly created {@link ParameterBag} + */ + public static ParameterBag createParameterBag(String id, String name, String type) { + + ParameterBag bag = new ParameterBag(id, name, type); + addAllParameters(bag); + return bag; + } + + /** + * Adds the following {@link Parameter}s to the given {@link ParameterBag}: + *
    + *
  • BooleanParameter - true
  • + *
  • FloatParameter - 44.3
  • + *
  • IntegerParameter - 77
  • + *
  • LongParameter - 4453234566L
  • + *
  • StringParameter - "Strolch"
  • + *
  • DateParameter - 1354295525628L
  • + *
  • StringListParameter - Hello, World
  • + *
+ * + * @param bag + */ + public static void addAllParameters(ParameterBag bag) { + + BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); + bag.addParameter(boolParam); + + FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); + bag.addParameter(floatParam); + + IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); + bag.addParameter(integerParam); + + LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); + bag.addParameter(longParam); + + StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); + bag.addParameter(stringParam); + + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, 1354295525628L); + bag.addParameter(dateParam); + + ArrayList stringList = new ArrayList(); + stringList.add("Hello"); + stringList.add("World"); + StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, + stringList); + bag.addParameter(stringListP); + } +} From 9de31a136eb94e2b416d86155544670e8a2b2f2e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 28 Oct 2013 18:58:36 +0100 Subject: [PATCH 03/42] [Minor] cleaned up .gitignore --- .gitignore | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 96dedc20e..558680bb1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ target/ -/.project -/.classpath -/.settings +.project +.classpath +.settings From a6fe2dce67080d63656d5a89a2c0f0ceb2767986 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Oct 2013 00:44:29 +0100 Subject: [PATCH 04/42] [New] added a container mock which creates the required directory struct --- pom.xml | 4 ++ .../testbase/runtime/ComponentMock.java | 11 ++++ .../strolch/testbase/runtime/RuntimeMock.java | 64 +++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 src/main/java/li/strolch/testbase/runtime/ComponentMock.java create mode 100644 src/main/java/li/strolch/testbase/runtime/RuntimeMock.java 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); +// } + } +} From 1e8648bc2a5f1574ef7488b8980e4ad92f8dfd66 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 14 Nov 2013 21:31:14 +0100 Subject: [PATCH 05/42] [New] implemented a RuntimeMock for easy mockin the container This can be used in the different projects to testing components which need a runtime --- .../testbase/runtime/ComponentMock.java | 11 ---- .../strolch/testbase/runtime/RuntimeMock.java | 65 +++++++++++++++---- 2 files changed, 51 insertions(+), 25 deletions(-) delete mode 100644 src/main/java/li/strolch/testbase/runtime/ComponentMock.java diff --git a/src/main/java/li/strolch/testbase/runtime/ComponentMock.java b/src/main/java/li/strolch/testbase/runtime/ComponentMock.java deleted file mode 100644 index 2696b7866..000000000 --- a/src/main/java/li/strolch/testbase/runtime/ComponentMock.java +++ /dev/null @@ -1,11 +0,0 @@ -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 index 2cdaf44eb..49129d203 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -3,13 +3,28 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; +import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.configuration.RuntimeConfiguration; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import ch.eitchnet.utils.helper.FileHelper; public class RuntimeMock { + private static final Logger logger = LoggerFactory.getLogger(RuntimeMock.class); private static final String TARGET = "target"; //$NON-NLS-1$ + private static ComponentContainer container; + + /** + * @return the container + */ + public static ComponentContainer getContainer() { + return container; + } + public static void mockRuntime(File rootPathF, File configSrc) { if (!rootPathF.getParentFile().getName().equals(TARGET)) { @@ -46,19 +61,41 @@ public class RuntimeMock { 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); -// } + } + + public static void startContainer(File rootPathF) { + + ComponentContainer container = new ComponentContainer(); + try { + + container.setup(rootPathF); + container.initialize(); + container.start(); + + RuntimeMock.container = container; + + } catch (Exception e) { + logger.error("Failed to start mocked container due to: " + e.getMessage(), e); //$NON-NLS-1$ + destroyRuntime(); + throw e; + } + } + + public static void destroyRuntime() { + + if (container == null) + return; + + try { + container.stop(); + } catch (Exception e) { + logger.info("Failed to stop container: " + e.getMessage()); //$NON-NLS-1$ + } + + try { + container.destroy(); + } catch (Exception e) { + logger.info("Failed to destroy container: " + e.getMessage()); //$NON-NLS-1$ + } } } From afda69d2366ea737ab8fd9022908ad9c77a0afc1 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 16 Nov 2013 01:10:20 +0100 Subject: [PATCH 06/42] [Minor] Added convenience method to access PrivilegeHandler --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 49129d203..12f6069af 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -5,6 +5,7 @@ import java.text.MessageFormat; import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.configuration.RuntimeConfiguration; +import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -25,6 +26,10 @@ public class RuntimeMock { return container; } + public static StrolchPrivilegeHandler getPrivilegeHandler() { + return container.getComponent(StrolchPrivilegeHandler.class); + } + public static void mockRuntime(File rootPathF, File configSrc) { if (!rootPathF.getParentFile().getName().equals(TARGET)) { From 9bc5f46f2a25f8ba40f8ac630487c6fc515303a7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 25 Nov 2013 18:53:59 +0100 Subject: [PATCH 07/42] [New] Implemented EMPTY and TRANSIENT dataStoreModes. Refactored Agent to be responsible for starting the container. And it requires the runtime configuration. --- .../strolch/testbase/model/ModelBuilder.java | 5 +++-- .../strolch/testbase/runtime/RuntimeMock.java | 20 ++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/li/strolch/testbase/model/ModelBuilder.java b/src/main/java/li/strolch/testbase/model/ModelBuilder.java index 77dda9446..004530d8f 100644 --- a/src/main/java/li/strolch/testbase/model/ModelBuilder.java +++ b/src/main/java/li/strolch/testbase/model/ModelBuilder.java @@ -22,6 +22,7 @@ package li.strolch.testbase.model; import java.util.ArrayList; +import java.util.Date; import li.strolch.model.Order; import li.strolch.model.ParameterBag; @@ -106,7 +107,7 @@ public class ModelBuilder { * * @return the newly created {@link Order} */ - public static Order createOrder(String id, String name, String type, long date, State state) { + public static Order createOrder(String id, String name, String type, Date date, State state) { Order order = new Order(id, name, type, date, state); ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); @@ -166,7 +167,7 @@ public class ModelBuilder { StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); bag.addParameter(stringParam); - DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, 1354295525628L); + DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); bag.addParameter(dateParam); ArrayList stringList = new ArrayList(); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 12f6069af..6cf4578b3 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -3,6 +3,7 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; +import li.strolch.runtime.agent.StrolchAgent; import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; @@ -18,6 +19,7 @@ public class RuntimeMock { private static final String TARGET = "target"; //$NON-NLS-1$ private static ComponentContainer container; + private static StrolchAgent agent; /** * @return the container @@ -70,14 +72,14 @@ public class RuntimeMock { public static void startContainer(File rootPathF) { - ComponentContainer container = new ComponentContainer(); try { + StrolchAgent agent = new StrolchAgent(); + agent.setup(rootPathF); + agent.initialize(); + agent.start(); - container.setup(rootPathF); - container.initialize(); - container.start(); - - RuntimeMock.container = container; + RuntimeMock.agent = agent; + RuntimeMock.container = agent.getContainer(); } catch (Exception e) { logger.error("Failed to start mocked container due to: " + e.getMessage(), e); //$NON-NLS-1$ @@ -88,17 +90,17 @@ public class RuntimeMock { public static void destroyRuntime() { - if (container == null) + if (agent == null) return; try { - container.stop(); + agent.stop(); } catch (Exception e) { logger.info("Failed to stop container: " + e.getMessage()); //$NON-NLS-1$ } try { - container.destroy(); + agent.destroy(); } catch (Exception e) { logger.info("Failed to destroy container: " + e.getMessage()); //$NON-NLS-1$ } From 9bd1453f7f6330471b17e49d147f2ad173a7d6df Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 11 Dec 2013 23:53:23 +0100 Subject: [PATCH 08/42] [Minor] moved the ModelBuilder to li.strolch.model ModelGenerator now generating objects is available everywhere --- .../strolch/testbase/model/ModelBuilder.java | 180 ------------------ 1 file changed, 180 deletions(-) delete mode 100644 src/main/java/li/strolch/testbase/model/ModelBuilder.java diff --git a/src/main/java/li/strolch/testbase/model/ModelBuilder.java b/src/main/java/li/strolch/testbase/model/ModelBuilder.java deleted file mode 100644 index 004530d8f..000000000 --- a/src/main/java/li/strolch/testbase/model/ModelBuilder.java +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2012, Robert von Burg - * - * All rights reserved. - * - * This file is part of the li.strolch.model. - * - * li.strolch.model is free software: you can redistribute - * it and/or modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 3 of the License, - * or (at your option) any later version. - * - * li.strolch.model is distributed in the hope that it will - * be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with li.strolch.model. If not, see - * . - */ -package li.strolch.testbase.model; - -import java.util.ArrayList; -import java.util.Date; - -import li.strolch.model.Order; -import li.strolch.model.ParameterBag; -import li.strolch.model.Resource; -import li.strolch.model.State; -import li.strolch.model.parameter.BooleanParameter; -import li.strolch.model.parameter.DateParameter; -import li.strolch.model.parameter.FloatParameter; -import li.strolch.model.parameter.IntegerParameter; -import li.strolch.model.parameter.LongParameter; -import li.strolch.model.parameter.Parameter; -import li.strolch.model.parameter.StringListParameter; -import li.strolch.model.parameter.StringParameter; - -/** - * @author Robert von Burg - * - */ -@SuppressWarnings("nls") -public class ModelBuilder { - - public static final String PARAM_BOOLEAN_ID = "@param1"; - public static final String PARAM_BOOLEAN_NAME = "Boolean Param"; - - public static final String PARAM_FLOAT_ID = "@param2"; - public static final String PARAM_FLOAT_NAME = "Float Param"; - - public static final String PARAM_INTEGER_ID = "@param3"; - public static final String PARAM_INTEGER_NAME = "Integer Param"; - - public static final String PARAM_LONG_ID = "@param4"; - public static final String PARAM_LONG_NAME = "Long Param"; - - public static final String PARAM_STRING_ID = "@param5"; - public static final String PARAM_STRING_NAME = "String Param"; - - public static final String PARAM_DATE_ID = "@param6"; - public static final String PARAM_DATE_NAME = "Date Param"; - - public static final String PARAM_LIST_STRING_ID = "@param7"; - public static final String PARAM_LIST_STRING_NAME = "StringList Param"; - - public static final String BAG_ID = "@bag01"; - public static final String BAG_NAME = "Test Bag"; - public static final String BAG_TYPE = "TestBag"; - - /** - * Creates an {@link Resource} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id - * the id of the {@link Resource} - * @param name - * the name of the {@link Resource} - * @param type - * the type of the {@link Resource} - * - * @return the newly created {@link Resource} - */ - public static Resource createResource(String id, String name, String type) { - Resource resource = new Resource(id, name, type); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - resource.addParameterBag(bag); - - return resource; - } - - /** - * Creates an {@link Order} with the given values and adds a {@link ParameterBag} by calling - * {@link #createParameterBag(String, String, String)} - * - * @param id - * the id of the {@link Order} - * @param name - * the name of the {@link Order} - * @param type - * the type of the {@link Order} - * @param date - * the date of the {@link Order} - * @param state - * the {@link State} of the {@link Order} - * - * @return the newly created {@link Order} - */ - public static Order createOrder(String id, String name, String type, Date date, State state) { - - Order order = new Order(id, name, type, date, state); - ParameterBag bag = createParameterBag(BAG_ID, BAG_NAME, BAG_TYPE); - order.addParameterBag(bag); - - return order; - } - - /** - * Creates a {@link ParameterBag} with the given values and calls {@link #addAllParameters(ParameterBag)} to add - * {@link Parameter}s - * - * @param id - * the id of the {@link ParameterBag} - * @param name - * the name of the {@link ParameterBag} - * @param type - * the type of the {@link ParameterBag} - * - * @return the newly created {@link ParameterBag} - */ - public static ParameterBag createParameterBag(String id, String name, String type) { - - ParameterBag bag = new ParameterBag(id, name, type); - addAllParameters(bag); - return bag; - } - - /** - * Adds the following {@link Parameter}s to the given {@link ParameterBag}: - *
    - *
  • BooleanParameter - true
  • - *
  • FloatParameter - 44.3
  • - *
  • IntegerParameter - 77
  • - *
  • LongParameter - 4453234566L
  • - *
  • StringParameter - "Strolch"
  • - *
  • DateParameter - 1354295525628L
  • - *
  • StringListParameter - Hello, World
  • - *
- * - * @param bag - */ - public static void addAllParameters(ParameterBag bag) { - - BooleanParameter boolParam = new BooleanParameter(PARAM_BOOLEAN_ID, PARAM_BOOLEAN_NAME, true); - bag.addParameter(boolParam); - - FloatParameter floatParam = new FloatParameter(PARAM_FLOAT_ID, PARAM_FLOAT_NAME, 44.3); - bag.addParameter(floatParam); - - IntegerParameter integerParam = new IntegerParameter(PARAM_INTEGER_ID, PARAM_INTEGER_NAME, 77); - bag.addParameter(integerParam); - - LongParameter longParam = new LongParameter(PARAM_LONG_ID, PARAM_LONG_NAME, 4453234566L); - bag.addParameter(longParam); - - StringParameter stringParam = new StringParameter(PARAM_STRING_ID, PARAM_STRING_NAME, "Strolch"); - bag.addParameter(stringParam); - - DateParameter dateParam = new DateParameter(PARAM_DATE_ID, PARAM_DATE_NAME, new Date(1354295525628L)); - bag.addParameter(dateParam); - - ArrayList stringList = new ArrayList(); - stringList.add("Hello"); - stringList.add("World"); - StringListParameter stringListP = new StringListParameter(PARAM_LIST_STRING_ID, PARAM_LIST_STRING_NAME, - stringList); - bag.addParameter(stringListP); - } -} From 0dd1a5b3f9790fb57a405c917f99848f53d92376 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 15 Dec 2013 13:10:31 +0100 Subject: [PATCH 09/42] [Project] Changed all licence references to Apache License 2.0 --- LICENSE | 309 +++++++++--------- .../strolch/testbase/runtime/RuntimeMock.java | 15 + 2 files changed, 175 insertions(+), 149 deletions(-) diff --git a/LICENSE b/LICENSE index 37ec93a14..d64569567 100644 --- a/LICENSE +++ b/LICENSE @@ -1,180 +1,191 @@ -Apache License -Version 2.0, January 2004 -http://www.apache.org/licenses/ -TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ -1. Definitions. + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION -"License" shall mean the terms and conditions for use, reproduction, and -distribution as defined by Sections 1 through 9 of this document. + 1. Definitions. -"Licensor" shall mean the copyright owner or entity authorized by the copyright -owner that is granting the License. + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. -"Legal Entity" shall mean the union of the acting entity and all other entities -that control, are controlled by, or are under common control with that entity. -For the purposes of this definition, "control" means (i) the power, direct or -indirect, to cause the direction or management of such entity, whether by -contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the -outstanding shares, or (iii) beneficial ownership of such entity. + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. -"You" (or "Your") shall mean an individual or Legal Entity exercising -permissions granted by this License. + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. -"Source" form shall mean the preferred form for making modifications, including -but not limited to software source code, documentation source, and configuration -files. + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. -"Object" form shall mean any form resulting from mechanical transformation or -translation of a Source form, including but not limited to compiled object code, -generated documentation, and conversions to other media types. + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. -"Work" shall mean the work of authorship, whether in Source or Object form, made -available under the License, as indicated by a copyright notice that is included -in or attached to the work (an example is provided in the Appendix below). + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. -"Derivative Works" shall mean any work, whether in Source or Object form, that -is based on (or derived from) the Work and for which the editorial revisions, -annotations, elaborations, or other modifications represent, as a whole, an -original work of authorship. For the purposes of this License, Derivative Works -shall not include works that remain separable from, or merely link (or bind by -name) to the interfaces of, the Work and Derivative Works thereof. + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). -"Contribution" shall mean any work of authorship, including the original version -of the Work and any modifications or additions to that Work or Derivative Works -thereof, that is intentionally submitted to Licensor for inclusion in the Work -by the copyright owner or by an individual or Legal Entity authorized to submit -on behalf of the copyright owner. For the purposes of this definition, -"submitted" means any form of electronic, verbal, or written communication sent -to the Licensor or its representatives, including but not limited to -communication on electronic mailing lists, source code control systems, and -issue tracking systems that are managed by, or on behalf of, the Licensor for -the purpose of discussing and improving the Work, but excluding communication -that is conspicuously marked or otherwise designated in writing by the copyright -owner as "Not a Contribution." + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. -"Contributor" shall mean Licensor and any individual or Legal Entity on behalf -of whom a Contribution has been received by Licensor and subsequently -incorporated within the Work. + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." -2. Grant of Copyright License. + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable copyright license to reproduce, prepare Derivative Works of, -publicly display, publicly perform, sublicense, and distribute the Work and such -Derivative Works in Source or Object form. + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. -3. Grant of Patent License. + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. -Subject to the terms and conditions of this License, each Contributor hereby -grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, -irrevocable (except as stated in this section) patent license to make, have -made, use, offer to sell, sell, import, and otherwise transfer the Work, where -such license applies only to those patent claims licensable by such Contributor -that are necessarily infringed by their Contribution(s) alone or by combination -of their Contribution(s) with the Work to which such Contribution(s) was -submitted. If You institute patent litigation against any entity (including a -cross-claim or counterclaim in a lawsuit) alleging that the Work or a -Contribution incorporated within the Work constitutes direct or contributory -patent infringement, then any patent licenses granted to You under this License -for that Work shall terminate as of the date such litigation is filed. + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: -4. Redistribution. + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and -You may reproduce and distribute copies of the Work or Derivative Works thereof -in any medium, with or without modifications, and in Source or Object form, -provided that You meet the following conditions: + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and -You must give any other recipients of the Work or Derivative Works a copy of -this License; and -You must cause any modified files to carry prominent notices stating that You -changed the files; and -You must retain, in the Source form of any Derivative Works that You distribute, -all copyright, patent, trademark, and attribution notices from the Source form -of the Work, excluding those notices that do not pertain to any part of the -Derivative Works; and -If the Work includes a "NOTICE" text file as part of its distribution, then any -Derivative Works that You distribute must include a readable copy of the -attribution notices contained within such NOTICE file, excluding those notices -that do not pertain to any part of the Derivative Works, in at least one of the -following places: within a NOTICE text file distributed as part of the -Derivative Works; within the Source form or documentation, if provided along -with the Derivative Works; or, within a display generated by the Derivative -Works, if and wherever such third-party notices normally appear. The contents of -the NOTICE file are for informational purposes only and do not modify the -License. You may add Your own attribution notices within Derivative Works that -You distribute, alongside or as an addendum to the NOTICE text from the Work, -provided that such additional attribution notices cannot be construed as -modifying the License. -You may add Your own copyright statement to Your modifications and may provide -additional or different license terms and conditions for use, reproduction, or -distribution of Your modifications, or for any such Derivative Works as a whole, -provided Your use, reproduction, and distribution of the Work otherwise complies -with the conditions stated in this License. + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and -5. Submission of Contributions. + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. -Unless You explicitly state otherwise, any Contribution intentionally submitted -for inclusion in the Work by You to the Licensor shall be under the terms and -conditions of this License, without any additional terms or conditions. -Notwithstanding the above, nothing herein shall supersede or modify the terms of -any separate license agreement you may have executed with Licensor regarding -such Contributions. + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. -6. Trademarks. + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. -This License does not grant permission to use the trade names, trademarks, -service marks, or product names of the Licensor, except as required for -reasonable and customary use in describing the origin of the Work and -reproducing the content of the NOTICE file. + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. -7. Disclaimer of Warranty. + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. -Unless required by applicable law or agreed to in writing, Licensor provides the -Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, -including, without limitation, any warranties or conditions of TITLE, -NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are -solely responsible for determining the appropriateness of using or -redistributing the Work and assume any risks associated with Your exercise of -permissions under this License. + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. -8. Limitation of Liability. + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. -In no event and under no legal theory, whether in tort (including negligence), -contract, or otherwise, unless required by applicable law (such as deliberate -and grossly negligent acts) or agreed to in writing, shall any Contributor be -liable to You for damages, including any direct, indirect, special, incidental, -or consequential damages of any character arising as a result of this License or -out of the use or inability to use the Work (including but not limited to -damages for loss of goodwill, work stoppage, computer failure or malfunction, or -any and all other commercial damages or losses), even if such Contributor has -been advised of the possibility of such damages. + END OF TERMS AND CONDITIONS -9. Accepting Warranty or Additional Liability. + APPENDIX: How to apply the Apache License to your work. -While redistributing the Work or Derivative Works thereof, You may choose to -offer, and charge a fee for, acceptance of support, warranty, indemnity, or -other liability obligations and/or rights consistent with this License. However, -in accepting such obligations, You may act only on Your own behalf and on Your -sole responsibility, not on behalf of any other Contributor, and only if You -agree to indemnify, defend, and hold each Contributor harmless for any liability -incurred by, or claims asserted against, such Contributor by reason of your -accepting any such warranty or additional liability. - -END OF TERMS AND CONDITIONS - -APPENDIX: How to apply the Apache License to your work - -To apply the Apache License to your work, attach the following boilerplate -notice, with the fields enclosed by brackets "[]" replaced with your own -identifying information. (Don't include the brackets!) The text should be -enclosed in the appropriate comment syntax for the file format. We also -recommend that a file or class name and description of purpose be included on -the same "printed page" as the copyright notice for easier identification within -third-party archives. + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. Copyright [yyyy] [name of copyright owner] @@ -182,7 +193,7 @@ third-party archives. you may not use this file except in compliance with the License. You may obtain a copy of the License at - http://www.apache.org/licenses/LICENSE-2.0 + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 6cf4578b3..e63f2b4e9 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -1,3 +1,18 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package li.strolch.testbase.runtime; import java.io.File; From 111d8a97c5c49e33b0166d9c4b56ac7be5c2b63d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 23 Dec 2013 18:42:57 +0100 Subject: [PATCH 10/42] [Major] refactored Element maps for better handling Now they are not components, now there is an ElementMapHandler which is the component and the OrderMap and ResourceMap can be retrieved from the ElementMapHandler --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index e63f2b4e9..33798e6f7 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -18,8 +18,8 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; +import li.strolch.runtime.agent.ComponentContainer; import li.strolch.runtime.agent.StrolchAgent; -import li.strolch.runtime.component.ComponentContainer; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; From 2c10b1b7271727ef51d113146f7d077493a63516 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 00:36:36 +0100 Subject: [PATCH 11/42] [Major] moved OrderDao and ResourceDao factory methods to transaction It makes using transaction feel easier. --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 33798e6f7..adc91d4bc 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -18,6 +18,7 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; +import li.strolch.persistence.api.PersistenceHandler; import li.strolch.runtime.agent.ComponentContainer; import li.strolch.runtime.agent.StrolchAgent; import li.strolch.runtime.configuration.RuntimeConfiguration; @@ -47,6 +48,10 @@ public class RuntimeMock { return container.getComponent(StrolchPrivilegeHandler.class); } + public static PersistenceHandler getPersistenceHandler() { + return container.getComponent(PersistenceHandler.class); + } + public static void mockRuntime(File rootPathF, File configSrc) { if (!rootPathF.getParentFile().getName().equals(TARGET)) { From 8c786d4fbcd9a1e95cd366be8a5d54190b9ae156 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 24 Dec 2013 02:44:06 +0100 Subject: [PATCH 12/42] [Minor] set artifact name to artifactId for easier reading of build log --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e9647fab8..392b09802 100644 --- a/pom.xml +++ b/pom.xml @@ -11,7 +11,7 @@ li.strolch.testbase - runtime for Strolch + li.strolch.testbase runtime for Strolch https://github.com/eitch/li.strolch.testbase From 153857071160ca8b0f48ccf84b7eb2f77c2940b7 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:02:09 +0100 Subject: [PATCH 13/42] [Minor] refactored tests for persistence layers to remove duplicate code --- pom.xml | 5 + .../runtime/OrderModelTestRunner.java | 157 ++++++++++++++++++ .../runtime/ResourceModelTestRunner.java | 157 ++++++++++++++++++ .../strolch/testbase/runtime/RuntimeMock.java | 41 ++--- 4 files changed, 340 insertions(+), 20 deletions(-) create mode 100644 src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java create mode 100644 src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java diff --git a/pom.xml b/pom.xml index 392b09802..a447a7b93 100644 --- a/pom.xml +++ b/pom.xml @@ -38,6 +38,11 @@ li.strolch li.strolch.runtime + + junit + junit + compile + diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java new file mode 100644 index 000000000..f9561c0bb --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -0,0 +1,157 @@ +package li.strolch.testbase.runtime; + +import static li.strolch.model.ModelGenerator.BAG_ID; +import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; +import static li.strolch.model.ModelGenerator.createOrder; +import static li.strolch.model.ModelGenerator.createOrders; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import li.strolch.model.Order; +import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.OrderDao; +import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.persistence.api.StrolchTransaction; + +@SuppressWarnings("nls") +public class OrderModelTestRunner { + + private static final String ID = "@testOrder"; + private static final String NAME = "Test Order"; + private static final String TYPE = "ToStock"; + + private RuntimeMock runtimeMock; + + public OrderModelTestRunner(RuntimeMock runtimeMock) { + this.runtimeMock = runtimeMock; + } + + protected PersistenceHandler getPersistenceHandler() { + return this.runtimeMock.getPersistenceHandler(); + } + + public void runCreateOrderTest() { + + // create + Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getOrderDao().save(newOrder); + } + } + + public void runCrudTests() { + + // create + Order newOrder = createOrder(ID, NAME, TYPE); + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getOrderDao().save(newOrder); + } + + // read + Order readOrder = null; + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + readOrder = tx.getOrderDao().queryBy(TYPE, ID); + } + assertNotNull("Should read Order with id " + ID, readOrder); + + // update + Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); + String newStringValue = "Giddiya!"; + sParam.setValue(newStringValue); + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getOrderDao().update(readOrder); + } + + // read updated + Order updatedOrder = null; + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); + } + assertNotNull("Should read Order with id " + ID, updatedOrder); + assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); + Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); + assertEquals(newStringValue, updatedParam.getValue()); + + // delete + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getOrderDao().remove(readOrder); + } + + // fail to re-read + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + Order order = tx.getOrderDao().queryBy(TYPE, ID); + assertNull("Should no read Order with id " + ID, order); + } + } + + public void runBulkOperationTests() { + + List orders = new ArrayList<>(); + orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1")); + orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2")); + orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3")); + + Comparator comparator = new Comparator() { + @Override + public int compare(Order o1, Order o2) { + return o1.getId().compareTo(o2.getId()); + } + }; + Collections.sort(orders, comparator); + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + tx.getOrderDao().saveAll(orders); + } + + Set expectedTypes = new HashSet<>(); + expectedTypes.add("MyType1"); + expectedTypes.add("MyType2"); + expectedTypes.add("MyType3"); + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + List allOrders = tx.getOrderDao().queryAll(); + Collections.sort(allOrders, comparator); + assertEquals(orders, allOrders); + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + OrderDao orderDao = tx.getOrderDao(); + + Set types = orderDao.queryTypes(); + assertEquals(expectedTypes, types); + + Set keySet = orderDao.queryKeySet(); + assertEquals(15, keySet.size()); + + for (String type : types) { + Set idsByType = orderDao.queryKeySet(type); + assertEquals(5, idsByType.size()); + + List ordersByType = orderDao.queryAll(type); + assertEquals(5, ordersByType.size()); + } + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); + assertNotNull(order); + order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); + assertNotNull(order); + order = tx.getOrderDao().queryBy("MyType3", "@_00000011"); + assertNotNull(order); + } + } +} diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java new file mode 100644 index 000000000..6d46c79b8 --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -0,0 +1,157 @@ +package li.strolch.testbase.runtime; + +import static li.strolch.model.ModelGenerator.BAG_ID; +import static li.strolch.model.ModelGenerator.PARAM_STRING_ID; +import static li.strolch.model.ModelGenerator.createResource; +import static li.strolch.model.ModelGenerator.createResources; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import li.strolch.model.Resource; +import li.strolch.model.parameter.Parameter; +import li.strolch.persistence.api.PersistenceHandler; +import li.strolch.persistence.api.ResourceDao; +import li.strolch.persistence.api.StrolchTransaction; + +@SuppressWarnings("nls") +public class ResourceModelTestRunner { + + private static final String ID = "@testResource"; //$NON-NLS-1$ + private static final String NAME = "Test Resource"; //$NON-NLS-1$ + private static final String TYPE = "Box"; //$NON-NLS-1$ + + private RuntimeMock runtimeMock; + + public ResourceModelTestRunner(RuntimeMock runtimeMock) { + this.runtimeMock = runtimeMock; + } + + protected PersistenceHandler getPersistenceHandler() { + return this.runtimeMock.getPersistenceHandler(); + } + + public void runCreateResourceTest() { + + // create + Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getResourceDao().save(newResource); + } + } + + public void runCrudTests() { + + // create + Resource newResource = createResource(ID, NAME, TYPE); + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getResourceDao().save(newResource); + } + + // read + Resource readResource = null; + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + readResource = tx.getResourceDao().queryBy(TYPE, ID); + } + assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ + + // update + Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); + String newStringValue = "Giddiya!"; //$NON-NLS-1$ + sParam.setValue(newStringValue); + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getResourceDao().update(readResource); + } + + // read updated + Resource updatedResource = null; + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + updatedResource = tx.getResourceDao().queryBy(TYPE, ID); + } + assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ + assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ + Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); + assertEquals(newStringValue, updatedParam.getValue()); + + // delete + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + tx.getResourceDao().remove(readResource); + } + + // fail to re-read + try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + Resource resource = tx.getResourceDao().queryBy(TYPE, ID); + assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ + } + } + + public void runBulkOperationTests() { + + List resources = new ArrayList<>(); + resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1")); + resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2")); + resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3")); + + Comparator comparator = new Comparator() { + @Override + public int compare(Resource o1, Resource o2) { + return o1.getId().compareTo(o2.getId()); + } + }; + Collections.sort(resources, comparator); + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + tx.getResourceDao().saveAll(resources); + } + + Set expectedTypes = new HashSet<>(); + expectedTypes.add("MyType1"); + expectedTypes.add("MyType2"); + expectedTypes.add("MyType3"); + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + List allResources = tx.getResourceDao().queryAll(); + Collections.sort(allResources, comparator); + assertEquals(resources, allResources); + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + ResourceDao resourceDao = tx.getResourceDao(); + + Set types = resourceDao.queryTypes(); + assertEquals(expectedTypes, types); + + Set keySet = resourceDao.queryKeySet(); + assertEquals(15, keySet.size()); + + for (String type : types) { + Set idsByType = resourceDao.queryKeySet(type); + assertEquals(5, idsByType.size()); + + List resourcesByType = resourceDao.queryAll(type); + assertEquals(5, resourcesByType.size()); + } + } + + try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); + assertNotNull(resource); + resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); + assertNotNull(resource); + resource = tx.getResourceDao().queryBy("MyType3", "@_00000011"); + assertNotNull(resource); + } + } +} diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index adc91d4bc..f63f1f64e 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -29,30 +29,31 @@ import org.slf4j.LoggerFactory; import ch.eitchnet.utils.helper.FileHelper; -public class RuntimeMock { +public final class RuntimeMock { private static final Logger logger = LoggerFactory.getLogger(RuntimeMock.class); private static final String TARGET = "target"; //$NON-NLS-1$ - private static ComponentContainer container; - private static StrolchAgent agent; + private ComponentContainer container; + private StrolchAgent agent; - /** - * @return the container - */ - public static ComponentContainer getContainer() { - return container; + public ComponentContainer getContainer() { + return this.container; } - public static StrolchPrivilegeHandler getPrivilegeHandler() { - return container.getComponent(StrolchPrivilegeHandler.class); + public StrolchAgent getAgent() { + return this.agent; } - public static PersistenceHandler getPersistenceHandler() { - return container.getComponent(PersistenceHandler.class); + public StrolchPrivilegeHandler getPrivilegeHandler() { + return this.container.getComponent(StrolchPrivilegeHandler.class); } - public static void mockRuntime(File rootPathF, File configSrc) { + public PersistenceHandler getPersistenceHandler() { + return this.container.getComponent(PersistenceHandler.class); + } + + public 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$ @@ -90,7 +91,7 @@ public class RuntimeMock { } } - public static void startContainer(File rootPathF) { + public void startContainer(File rootPathF) { try { StrolchAgent agent = new StrolchAgent(); @@ -98,8 +99,8 @@ public class RuntimeMock { agent.initialize(); agent.start(); - RuntimeMock.agent = agent; - RuntimeMock.container = agent.getContainer(); + this.agent = agent; + this.container = agent.getContainer(); } catch (Exception e) { logger.error("Failed to start mocked container due to: " + e.getMessage(), e); //$NON-NLS-1$ @@ -108,19 +109,19 @@ public class RuntimeMock { } } - public static void destroyRuntime() { + public void destroyRuntime() { - if (agent == null) + if (this.agent == null) return; try { - agent.stop(); + this.agent.stop(); } catch (Exception e) { logger.info("Failed to stop container: " + e.getMessage()); //$NON-NLS-1$ } try { - agent.destroy(); + this.agent.destroy(); } catch (Exception e) { logger.info("Failed to destroy container: " + e.getMessage()); //$NON-NLS-1$ } From 0879db11526cac73072924464cc5e55f6ba40738 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:33:55 +0100 Subject: [PATCH 14/42] [Minor] refactored tests for persistence layers to remove duplicate code --- .../testbase/runtime/AbstractModelTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java new file mode 100644 index 000000000..a623e7b28 --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -0,0 +1,59 @@ +package li.strolch.testbase.runtime; + +import li.strolch.persistence.api.StrolchTransaction; + +import org.junit.Test; + +public abstract class AbstractModelTest { + + protected abstract RuntimeMock getRuntimeMock(); + + @Test + public void shouldStartContainer() { + try (StrolchTransaction tx = getRuntimeMock().getPersistenceHandler().openTx()) { + tx.getOrderDao().queryKeySet(); + } + } + + @Test + public void shouldCreateOrders() { + + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + testRunner.runCreateOrderTest(); + } + + @Test + public void shouldOrderCrud() { + + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + testRunner.runCrudTests(); + } + + @Test + public void shouldOrderPerformBulkOperations() { + + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + testRunner.runBulkOperationTests(); + } + + @Test + public void shouldCreateResources() { + + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + testRunner.runCreateResourceTest(); + } + + @Test + public void shouldResourceCrud() { + + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + testRunner.runCrudTests(); + } + + @Test + public void shouldResourcePerformBulkOperations() { + + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + testRunner.runBulkOperationTests(); + } +} From edce1aaba4892d84512f5cd2f3bb826b98512a11 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 17:40:42 +0100 Subject: [PATCH 15/42] [Minor] additional logger --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index f63f1f64e..280b4b891 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -68,6 +68,7 @@ public final class RuntimeMock { } 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()); From f8ce5f22ecae945cbcf3bb73418a1b8bcdff6051 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 19:04:49 +0100 Subject: [PATCH 16/42] [Major] RuntimeMock now also copies data --- .../li/strolch/testbase/runtime/RuntimeMock.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 280b4b891..76406c73e 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -53,7 +53,7 @@ public final class RuntimeMock { return this.container.getComponent(PersistenceHandler.class); } - public void mockRuntime(File rootPathF, File configSrc) { + public 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$ @@ -61,6 +61,9 @@ public final class RuntimeMock { 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()); @@ -90,6 +93,17 @@ public final class RuntimeMock { 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); + } + } } public void startContainer(File rootPathF) { From 3cbac517f39b42412b04908173f3624ccfaca342 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 25 Dec 2013 22:31:04 +0100 Subject: [PATCH 17/42] [Minor] reorganized classes for Agent into api and impl packages --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 76406c73e..58999dcb2 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -19,8 +19,8 @@ import java.io.File; import java.text.MessageFormat; import li.strolch.persistence.api.PersistenceHandler; -import li.strolch.runtime.agent.ComponentContainer; -import li.strolch.runtime.agent.StrolchAgent; +import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.StrolchAgent; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; From 3081e0882871a9f8559bc8e6c3fbeba6bcdf3a8a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 26 Dec 2013 00:05:03 +0100 Subject: [PATCH 18/42] [Major] TXs are opened from ElementMap and all methods need a TX now --- .../testbase/runtime/AbstractModelTest.java | 2 +- .../runtime/OrderModelTestRunner.java | 29 ++++++++----------- .../runtime/ResourceModelTestRunner.java | 29 ++++++++----------- .../strolch/testbase/runtime/RuntimeMock.java | 11 +++++-- 4 files changed, 33 insertions(+), 38 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index a623e7b28..44cd0fa11 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -10,7 +10,7 @@ public abstract class AbstractModelTest { @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getRuntimeMock().getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = getRuntimeMock().getOrderMap().openTx()) { tx.getOrderDao().queryKeySet(); } } diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index f9561c0bb..fa6e3d08d 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -19,7 +19,6 @@ import java.util.Set; import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.OrderDao; -import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.StrolchTransaction; @SuppressWarnings("nls") @@ -35,15 +34,11 @@ public class OrderModelTestRunner { this.runtimeMock = runtimeMock; } - protected PersistenceHandler getPersistenceHandler() { - return this.runtimeMock.getPersistenceHandler(); - } - public void runCreateOrderTest() { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { tx.getOrderDao().save(newOrder); } } @@ -52,13 +47,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { tx.getOrderDao().save(newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { readOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -67,13 +62,13 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { tx.getOrderDao().update(readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); @@ -82,12 +77,12 @@ public class OrderModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { tx.getOrderDao().remove(readOrder); } // fail to re-read - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { Order order = tx.getOrderDao().queryBy(TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -108,11 +103,11 @@ public class OrderModelTestRunner { }; Collections.sort(orders, comparator); - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { tx.getOrderDao().saveAll(orders); } @@ -121,13 +116,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { List allOrders = tx.getOrderDao().queryAll(); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { OrderDao orderDao = tx.getOrderDao(); Set types = orderDao.queryTypes(); @@ -145,7 +140,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); assertNotNull(order); order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 6d46c79b8..8e6ef8ded 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -18,7 +18,6 @@ import java.util.Set; import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; -import li.strolch.persistence.api.PersistenceHandler; import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; @@ -35,15 +34,11 @@ public class ResourceModelTestRunner { this.runtimeMock = runtimeMock; } - protected PersistenceHandler getPersistenceHandler() { - return this.runtimeMock.getPersistenceHandler(); - } - public void runCreateResourceTest() { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { tx.getResourceDao().save(newResource); } } @@ -52,13 +47,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { tx.getResourceDao().save(newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { readResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -67,13 +62,13 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { tx.getResourceDao().update(readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { updatedResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ @@ -82,12 +77,12 @@ public class ResourceModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { tx.getResourceDao().remove(readResource); } // fail to re-read - try (StrolchTransaction tx = getPersistenceHandler().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { Resource resource = tx.getResourceDao().queryBy(TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -108,11 +103,11 @@ public class ResourceModelTestRunner { }; Collections.sort(resources, comparator); - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { tx.getResourceDao().saveAll(resources); } @@ -121,13 +116,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { List allResources = tx.getResourceDao().queryAll(); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { ResourceDao resourceDao = tx.getResourceDao(); Set types = resourceDao.queryTypes(); @@ -145,7 +140,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = getPersistenceHandler().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); assertNotNull(resource); resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 58999dcb2..72f64f8c5 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -18,8 +18,9 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; -import li.strolch.persistence.api.PersistenceHandler; import li.strolch.runtime.agent.api.ComponentContainer; +import li.strolch.runtime.agent.api.OrderMap; +import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.runtime.agent.api.StrolchAgent; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; @@ -49,8 +50,12 @@ public final class RuntimeMock { return this.container.getComponent(StrolchPrivilegeHandler.class); } - public PersistenceHandler getPersistenceHandler() { - return this.container.getComponent(PersistenceHandler.class); + public OrderMap getOrderMap() { + return this.container.getOrderMap(); + } + + public ResourceMap getResourceMap() { + return this.container.getResourceMap(); } public void mockRuntime(File rootPathF, File rootSrc) { From e85537878084dba00b4f1bf0b0b72c5ee8c9e297 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 17:17:04 +0100 Subject: [PATCH 19/42] [Major] renamed project li.strolch.runtime to li.strolch.agent --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a447a7b93..337e715af 100644 --- a/pom.xml +++ b/pom.xml @@ -36,7 +36,7 @@ li.strolch - li.strolch.runtime + li.strolch.agent junit From a012c7fff81cf7587119b0f91a9df01e6d11cea6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 19:11:01 +0100 Subject: [PATCH 20/42] [Major] refactored how transactions are opened Now the ElementMapHandler is the central object and clients do not use access DAOs or the PersistenceHandler anymore. This is now transparent. --- .../testbase/runtime/AbstractModelTest.java | 2 +- .../runtime/OrderModelTestRunner.java | 24 +++++++++---------- .../runtime/ResourceModelTestRunner.java | 24 +++++++++---------- .../strolch/testbase/runtime/RuntimeMock.java | 13 +++++----- 4 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index 44cd0fa11..c2d636789 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -10,7 +10,7 @@ public abstract class AbstractModelTest { @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getRuntimeMock().getOrderMap().openTx()) { + try (StrolchTransaction tx = getRuntimeMock().getDefaultRealm().openTx()) { tx.getOrderDao().queryKeySet(); } } diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index fa6e3d08d..c480226a3 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -38,7 +38,7 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getOrderDao().save(newOrder); } } @@ -47,13 +47,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getOrderDao().save(newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { readOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -62,13 +62,13 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getOrderDao().update(readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); @@ -77,12 +77,12 @@ public class OrderModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getOrderDao().remove(readOrder); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { Order order = tx.getOrderDao().queryBy(TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -103,11 +103,11 @@ public class OrderModelTestRunner { }; Collections.sort(orders, comparator); - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); } - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { tx.getOrderDao().saveAll(orders); } @@ -116,13 +116,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { List allOrders = tx.getOrderDao().queryAll(); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { OrderDao orderDao = tx.getOrderDao(); Set types = orderDao.queryTypes(); @@ -140,7 +140,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getOrderMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); assertNotNull(order); order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 8e6ef8ded..73aa92d9f 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -38,7 +38,7 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getResourceDao().save(newResource); } } @@ -47,13 +47,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getResourceDao().save(newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { readResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -62,13 +62,13 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getResourceDao().update(readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { updatedResource = tx.getResourceDao().queryBy(TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ @@ -77,12 +77,12 @@ public class ResourceModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { tx.getResourceDao().remove(readResource); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { Resource resource = tx.getResourceDao().queryBy(TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -103,11 +103,11 @@ public class ResourceModelTestRunner { }; Collections.sort(resources, comparator); - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); } - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { tx.getResourceDao().saveAll(resources); } @@ -116,13 +116,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { List allResources = tx.getResourceDao().queryAll(); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { ResourceDao resourceDao = tx.getResourceDao(); Set types = resourceDao.queryTypes(); @@ -140,7 +140,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getResourceMap().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); assertNotNull(resource); resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 72f64f8c5..ffbe1bc66 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -19,9 +19,8 @@ import java.io.File; import java.text.MessageFormat; import li.strolch.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.OrderMap; -import li.strolch.runtime.agent.api.ResourceMap; import li.strolch.runtime.agent.api.StrolchAgent; +import li.strolch.runtime.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; @@ -50,12 +49,12 @@ public final class RuntimeMock { return this.container.getComponent(StrolchPrivilegeHandler.class); } - public OrderMap getOrderMap() { - return this.container.getOrderMap(); + public StrolchRealm getDefaultRealm() { + return this.container.getDefaultRealm(); } - - public ResourceMap getResourceMap() { - return this.container.getResourceMap(); + + public StrolchRealm getRealm(String realm) { + return this.container.getRealm(realm); } public void mockRuntime(File rootPathF, File rootSrc) { From d1d51587db3637ad4bd3f51817efb2dc8911d426 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 23:15:03 +0100 Subject: [PATCH 21/42] [New] Modified the RuntimeMock to simply copy all root source --- .../strolch/testbase/runtime/RuntimeMock.java | 22 +++++-------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index ffbe1bc66..f83998fb6 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -66,7 +66,6 @@ public final class RuntimeMock { } 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$ @@ -89,25 +88,14 @@ public final class RuntimeMock { throw new RuntimeException(msg); } - File configPathF = new File(rootPathF, RuntimeConfiguration.PATH_CONFIG); - configPathF.mkdir(); + logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", rootSrc.getAbsolutePath(), + rootPathF.getAbsolutePath())); - 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()); + if (!FileHelper.copy(rootSrc.listFiles(), rootPathF, false)) { + String msg = "Failed to copy source files from {0} to {1}"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, rootSrc.getAbsolutePath(), rootPathF.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); - } - } } public void startContainer(File rootPathF) { From 3b7927bdacbfef22a449f92b4a264e56822430e0 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 10 Jan 2014 23:23:34 +0100 Subject: [PATCH 22/42] [Major] moved the package li.strolch.runtime.agent to li.strolch.agent --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index f83998fb6..e49f02e90 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -18,9 +18,9 @@ package li.strolch.testbase.runtime; import java.io.File; import java.text.MessageFormat; -import li.strolch.runtime.agent.api.ComponentContainer; -import li.strolch.runtime.agent.api.StrolchAgent; -import li.strolch.runtime.agent.impl.StrolchRealm; +import li.strolch.agent.api.ComponentContainer; +import li.strolch.agent.api.StrolchAgent; +import li.strolch.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; From 21502ddf82793eed0493878718abcbc5c6d3940e Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 11 Jan 2014 17:56:12 +0100 Subject: [PATCH 23/42] [Major] Implemented CACHED mode This lead to refactoring of other code: - removed get*Dao() from StrolchTransaction - added StrolchTransaction.getPersistenceHandler() - removed unused variables in TransactionalElementMap - this lead to removal of constructors in subclasses - added ComponentContainer.getDataStoreMode() - added ElementMap.addAll(), removeAll() and updateAll() methods - implemented in all ElementMap implementations --- .../testbase/runtime/AbstractModelTest.java | 2 +- .../runtime/OrderModelTestRunner.java | 43 ++++++++++--------- .../runtime/ResourceModelTestRunner.java | 43 ++++++++++--------- 3 files changed, 47 insertions(+), 41 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index c2d636789..b0026eec2 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -11,7 +11,7 @@ public abstract class AbstractModelTest { @Test public void shouldStartContainer() { try (StrolchTransaction tx = getRuntimeMock().getDefaultRealm().openTx()) { - tx.getOrderDao().queryKeySet(); + tx.getOrderMap().getAllKeys(tx); } } diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index c480226a3..d6e5ddfcb 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -16,9 +16,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import li.strolch.agent.api.OrderMap; +import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; -import li.strolch.persistence.api.OrderDao; import li.strolch.persistence.api.StrolchTransaction; @SuppressWarnings("nls") @@ -39,7 +40,7 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getOrderDao().save(newOrder); + tx.getOrderMap().add(tx, newOrder); } } @@ -48,13 +49,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getOrderDao().save(newOrder); + tx.getOrderMap().add(tx, newOrder); } // read Order readOrder = null; try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - readOrder = tx.getOrderDao().queryBy(TYPE, ID); + readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -63,27 +64,28 @@ public class OrderModelTestRunner { String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getOrderDao().update(readOrder); + tx.getOrderMap().update(tx, readOrder); } // read updated Order updatedOrder = null; try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - updatedOrder = tx.getOrderDao().queryBy(TYPE, ID); + updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); - assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); + if (runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); // delete try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getOrderDao().remove(readOrder); + tx.getOrderMap().remove(tx, readOrder); } // fail to re-read try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - Order order = tx.getOrderDao().queryBy(TYPE, ID); + Order order = tx.getOrderMap().getBy(tx, TYPE, ID); assertNull("Should no read Order with id " + ID, order); } } @@ -104,11 +106,12 @@ public class OrderModelTestRunner { Collections.sort(orders, comparator); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - tx.getOrderDao().removeAll(tx.getOrderDao().queryAll()); + OrderMap orderMap = tx.getOrderMap(); + orderMap.removeAll(tx, orderMap.getAllElements(tx)); } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - tx.getOrderDao().saveAll(orders); + tx.getOrderMap().addAll(tx, orders); } Set expectedTypes = new HashSet<>(); @@ -117,35 +120,35 @@ public class OrderModelTestRunner { expectedTypes.add("MyType3"); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - List allOrders = tx.getOrderDao().queryAll(); + List allOrders = tx.getOrderMap().getAllElements(tx); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - OrderDao orderDao = tx.getOrderDao(); + OrderMap orderMap = tx.getOrderMap(); - Set types = orderDao.queryTypes(); + Set types = orderMap.getTypes(tx); assertEquals(expectedTypes, types); - Set keySet = orderDao.queryKeySet(); + Set keySet = orderMap.getAllKeys(tx); assertEquals(15, keySet.size()); for (String type : types) { - Set idsByType = orderDao.queryKeySet(type); + Set idsByType = orderMap.getKeysBy(tx, type); assertEquals(5, idsByType.size()); - List ordersByType = orderDao.queryAll(type); + List ordersByType = orderMap.getElementsBy(tx, type); assertEquals(5, ordersByType.size()); } } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - Order order = tx.getOrderDao().queryBy("MyType1", "@_00000001"); + Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType2", "@_00000006"); + order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006"); assertNotNull(order); - order = tx.getOrderDao().queryBy("MyType3", "@_00000011"); + order = tx.getOrderMap().getBy(tx, "MyType3", "@_00000011"); assertNotNull(order); } } diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 73aa92d9f..1055e65bb 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -16,9 +16,10 @@ import java.util.HashSet; import java.util.List; import java.util.Set; +import li.strolch.agent.api.ResourceMap; +import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; -import li.strolch.persistence.api.ResourceDao; import li.strolch.persistence.api.StrolchTransaction; @SuppressWarnings("nls") @@ -39,7 +40,7 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getResourceDao().save(newResource); + tx.getResourceMap().add(tx, newResource); } } @@ -48,13 +49,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getResourceDao().save(newResource); + tx.getResourceMap().add(tx, newResource); } // read Resource readResource = null; try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - readResource = tx.getResourceDao().queryBy(TYPE, ID); + readResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -63,27 +64,28 @@ public class ResourceModelTestRunner { String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getResourceDao().update(readResource); + tx.getResourceMap().update(tx, readResource); } // read updated Resource updatedResource = null; try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - updatedResource = tx.getResourceDao().queryBy(TYPE, ID); + updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ - assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ + if (runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); // delete try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - tx.getResourceDao().remove(readResource); + tx.getResourceMap().remove(tx, readResource); } // fail to re-read try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { - Resource resource = tx.getResourceDao().queryBy(TYPE, ID); + Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } } @@ -104,11 +106,12 @@ public class ResourceModelTestRunner { Collections.sort(resources, comparator); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - tx.getResourceDao().removeAll(tx.getResourceDao().queryAll()); + ResourceMap resourceMap = tx.getResourceMap(); + resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - tx.getResourceDao().saveAll(resources); + tx.getResourceMap().addAll(tx, resources); } Set expectedTypes = new HashSet<>(); @@ -117,35 +120,35 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType3"); try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - List allResources = tx.getResourceDao().queryAll(); + List allResources = tx.getResourceMap().getAllElements(tx); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - ResourceDao resourceDao = tx.getResourceDao(); + ResourceMap resourceMap = tx.getResourceMap(); - Set types = resourceDao.queryTypes(); + Set types = resourceMap.getTypes(tx); assertEquals(expectedTypes, types); - Set keySet = resourceDao.queryKeySet(); + Set keySet = resourceMap.getAllKeys(tx); assertEquals(15, keySet.size()); for (String type : types) { - Set idsByType = resourceDao.queryKeySet(type); + Set idsByType = resourceMap.getKeysBy(tx, type); assertEquals(5, idsByType.size()); - List resourcesByType = resourceDao.queryAll(type); + List resourcesByType = resourceMap.getElementsBy(tx, type); assertEquals(5, resourcesByType.size()); } } try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { - Resource resource = tx.getResourceDao().queryBy("MyType1", "@_00000001"); + Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType2", "@_00000006"); + resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006"); assertNotNull(resource); - resource = tx.getResourceDao().queryBy("MyType3", "@_00000011"); + resource = tx.getResourceMap().getBy(tx, "MyType3", "@_00000011"); assertNotNull(resource); } } From a3a0b4cacbcad492b3097569ef5388b5070ea765 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 15 Jan 2014 22:09:32 +0100 Subject: [PATCH 24/42] [New] added querySize() methods to ElementMap --- .../testbase/runtime/AbstractModelTest.java | 14 ++++++++ .../runtime/OrderModelTestRunner.java | 36 +++++++++++++++++++ .../runtime/ResourceModelTestRunner.java | 36 +++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index b0026eec2..9de32a2f2 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -22,6 +22,13 @@ public abstract class AbstractModelTest { testRunner.runCreateOrderTest(); } + @Test + public void shouldQueryOrderSizes() { + + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + testRunner.runQuerySizeTest(); + } + @Test public void shouldOrderCrud() { @@ -43,6 +50,13 @@ public abstract class AbstractModelTest { testRunner.runCreateResourceTest(); } + @Test + public void shouldQueryResourceSizes() { + + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + testRunner.runQuerySizeTest(); + } + @Test public void shouldResourceCrud() { diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index d6e5ddfcb..c6df0ef9e 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -44,6 +44,42 @@ public class OrderModelTestRunner { } } + public void runQuerySizeTest() { + + // remove all + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); + } + + // create three orders + Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + tx.getOrderMap().add(tx, order1); + tx.getOrderMap().add(tx, order2); + tx.getOrderMap().add(tx, order3); + } + + // query size + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + long size = tx.getOrderMap().querySize(tx); + assertEquals("Should have three objects", 3, size); + + size = tx.getOrderMap().querySize(tx, "QTestType1"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getOrderMap().querySize(tx, "QTestType2"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getOrderMap().querySize(tx, "QTestType3"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getOrderMap().querySize(tx, "NonExistingType"); + assertEquals("Should have zero objects of type 'NonExistingType'", 0, size); + } + } + public void runCrudTests() { // create diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 1055e65bb..6a5b4250b 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -44,6 +44,42 @@ public class ResourceModelTestRunner { } } + public void runQuerySizeTest() { + + // remove all + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); + } + + // create three resources + Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + tx.getResourceMap().add(tx, resource1); + tx.getResourceMap().add(tx, resource2); + tx.getResourceMap().add(tx, resource3); + } + + // query size + try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + long size = tx.getResourceMap().querySize(tx); + assertEquals("Should have three objects", 3, size); + + size = tx.getResourceMap().querySize(tx, "QTestType1"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getResourceMap().querySize(tx, "QTestType2"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getResourceMap().querySize(tx, "QTestType3"); + assertEquals("Should have only one object of type 'QTestType1'", 1, size); + + size = tx.getResourceMap().querySize(tx, "NonExistingType"); + assertEquals("Should have zero objects of type 'NonExistingType'", 0, size); + } + } + public void runCrudTests() { // create From 3eed58f19a599058fab6fee42db12896a3d0895f Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 23 Jan 2014 22:52:52 +0100 Subject: [PATCH 25/42] [Project] added Jenkins build badge to README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6c1466737..d774be67d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ li.strolch.testbase =================== +[![Build Status](http://jenkins.eitchnet.ch/buildStatus/icon?job=li.strolch.testbase)](http://jenkins.eitchnet.ch/view/strolch/job/li.strolch.testbase/) + Test base for the li.strolch.* projects From e667ca900165c7f2c1b17d527b37ebe6a3a70556 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 31 Jan 2014 16:14:47 +0100 Subject: [PATCH 26/42] [Minor] code cleanup --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index e49f02e90..1092386ed 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -88,7 +88,7 @@ public final class RuntimeMock { throw new RuntimeException(msg); } - logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", rootSrc.getAbsolutePath(), + logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", rootSrc.getAbsolutePath(), //$NON-NLS-1$ rootPathF.getAbsolutePath())); if (!FileHelper.copy(rootSrc.listFiles(), rootPathF, false)) { From be67876faf832cad101ff7e00f7cb5b41e1d9a97 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 2 Feb 2014 20:34:10 +0100 Subject: [PATCH 27/42] [Minor] RuntimeMock now has a parameterless startContainer()-method the root path passed when mocking is started when startContainer() is called. the existing startContainer(File)-method is marked deprecated --- .../runtime/OrderModelTestRunner.java | 2 +- .../runtime/ResourceModelTestRunner.java | 2 +- .../strolch/testbase/runtime/RuntimeMock.java | 45 ++++++++++++------- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index c6df0ef9e..6514735e1 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -109,7 +109,7 @@ public class OrderModelTestRunner { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); - if (runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 6a5b4250b..e7aa533f6 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -109,7 +109,7 @@ public class ResourceModelTestRunner { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ - if (runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 1092386ed..4321e9220 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -27,6 +27,7 @@ import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ch.eitchnet.utils.dbc.DBC; import ch.eitchnet.utils.helper.FileHelper; public final class RuntimeMock { @@ -36,6 +37,8 @@ public final class RuntimeMock { private ComponentContainer container; private StrolchAgent agent; + private File rootPath; + private File rootSrc; public ComponentContainer getContainer() { return this.container; @@ -57,15 +60,18 @@ public final class RuntimeMock { return this.container.getRealm(realm); } - public void mockRuntime(File rootPathF, File rootSrc) { + public void mockRuntime(File rootPath, File rootSrc) { - if (!rootPathF.getParentFile().getName().equals(TARGET)) { + this.rootPath = rootPath; + this.rootSrc = rootSrc; + + if (!this.rootPath.getParentFile().getName().equals(TARGET)) { String msg = "Mocking path must be in a maven target: {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + msg = MessageFormat.format(msg, this.rootPath.getAbsolutePath()); throw new RuntimeException(msg); } - File configSrc = new File(rootSrc, RuntimeConfiguration.PATH_CONFIG); + File configSrc = new File(this.rootSrc, RuntimeConfiguration.PATH_CONFIG); if (!configSrc.isDirectory() || !configSrc.canRead()) { String msg = "Could not find config source in: {0}"; //$NON-NLS-1$ @@ -73,36 +79,45 @@ public final class RuntimeMock { throw new RuntimeException(msg); } - if (rootPathF.exists()) { - logger.info("Deleting all files in " + rootPathF.getAbsolutePath()); //$NON-NLS-1$ - if (!FileHelper.deleteFile(rootPathF, true)) { + if (this.rootPath.exists()) { + logger.info("Deleting all files in " + this.rootPath.getAbsolutePath()); //$NON-NLS-1$ + if (!FileHelper.deleteFile(this.rootPath, true)) { String msg = "Failed to delete {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + msg = MessageFormat.format(msg, this.rootPath.getAbsolutePath()); throw new RuntimeException(msg); } } - if (!rootPathF.mkdirs()) { + if (!this.rootPath.mkdirs()) { String msg = "Failed to create {0}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, rootPathF.getAbsolutePath()); + msg = MessageFormat.format(msg, this.rootPath.getAbsolutePath()); throw new RuntimeException(msg); } - logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", rootSrc.getAbsolutePath(), //$NON-NLS-1$ - rootPathF.getAbsolutePath())); + logger.info(MessageFormat.format("Mocking runtime from {0} to {1}", this.rootSrc.getAbsolutePath(), //$NON-NLS-1$ + this.rootPath.getAbsolutePath())); - if (!FileHelper.copy(rootSrc.listFiles(), rootPathF, false)) { + if (!FileHelper.copy(this.rootSrc.listFiles(), this.rootPath, false)) { String msg = "Failed to copy source files from {0} to {1}"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, rootSrc.getAbsolutePath(), rootPathF.getAbsolutePath()); + msg = MessageFormat.format(msg, this.rootSrc.getAbsolutePath(), this.rootPath.getAbsolutePath()); throw new RuntimeException(msg); } } + /** + * @deprecated use parameterless {@link #startContainer()} + */ + @Deprecated public void startContainer(File rootPathF) { + DBC.PRE.assertEquals("Starting a different runtime than was mocked!", this.rootPath, rootPathF); //$NON-NLS-1$ + startContainer(); + } + + public void startContainer() { try { StrolchAgent agent = new StrolchAgent(); - agent.setup(rootPathF); + agent.setup(this.rootPath); agent.initialize(); agent.start(); From 5ce91bfe4ba2c93cb5b0afede8520d3ec59f164b Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 2 Feb 2014 20:41:39 +0100 Subject: [PATCH 28/42] [Minor] added RuntimeMock.getServiceHandler() --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 4321e9220..4972c2ab1 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -23,6 +23,7 @@ import li.strolch.agent.api.StrolchAgent; import li.strolch.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; +import li.strolch.service.api.ServiceHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,6 +53,10 @@ public final class RuntimeMock { return this.container.getComponent(StrolchPrivilegeHandler.class); } + public ServiceHandler getServiceHandler() { + return this.container.getComponent(ServiceHandler.class); + } + public StrolchRealm getDefaultRealm() { return this.container.getDefaultRealm(); } From bb3f3e78544fcc76e0bd601a85a55f3bd05b0d57 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 13 Feb 2014 22:22:11 +0100 Subject: [PATCH 29/42] [Minor] there is no getDefaultRealm() method anymore --- .../testbase/runtime/AbstractModelTest.java | 3 +- .../runtime/OrderModelTestRunner.java | 31 ++++++++++--------- .../runtime/ResourceModelTestRunner.java | 31 ++++++++++--------- .../strolch/testbase/runtime/RuntimeMock.java | 14 --------- 4 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index 9de32a2f2..494ad23ff 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -1,6 +1,7 @@ package li.strolch.testbase.runtime; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.StrolchConstants; import org.junit.Test; @@ -10,7 +11,7 @@ public abstract class AbstractModelTest { @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getRuntimeMock().getDefaultRealm().openTx()) { + try (StrolchTransaction tx = getRuntimeMock().getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { tx.getOrderMap().getAllKeys(tx); } } diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 6514735e1..2564479cf 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -21,6 +21,7 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.StrolchConstants; @SuppressWarnings("nls") public class OrderModelTestRunner { @@ -39,7 +40,7 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().add(tx, newOrder); } } @@ -47,7 +48,7 @@ public class OrderModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); } @@ -55,14 +56,14 @@ public class OrderModelTestRunner { Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().add(tx, order1); tx.getOrderMap().add(tx, order2); tx.getOrderMap().add(tx, order3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { long size = tx.getOrderMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -84,13 +85,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().add(tx, newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -99,13 +100,13 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().update(tx, readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); @@ -115,12 +116,12 @@ public class OrderModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getOrderMap().remove(tx, readOrder); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { Order order = tx.getOrderMap().getBy(tx, TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -141,12 +142,12 @@ public class OrderModelTestRunner { }; Collections.sort(orders, comparator); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { OrderMap orderMap = tx.getOrderMap(); orderMap.removeAll(tx, orderMap.getAllElements(tx)); } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { tx.getOrderMap().addAll(tx, orders); } @@ -155,13 +156,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { List allOrders = tx.getOrderMap().getAllElements(tx); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { OrderMap orderMap = tx.getOrderMap(); Set types = orderMap.getTypes(tx); @@ -179,7 +180,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(order); order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index e7aa533f6..5a831e753 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -21,6 +21,7 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.StrolchConstants; @SuppressWarnings("nls") public class ResourceModelTestRunner { @@ -39,7 +40,7 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().add(tx, newResource); } } @@ -47,7 +48,7 @@ public class ResourceModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); } @@ -55,14 +56,14 @@ public class ResourceModelTestRunner { Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().add(tx, resource1); tx.getResourceMap().add(tx, resource2); tx.getResourceMap().add(tx, resource3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { long size = tx.getResourceMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -84,13 +85,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().add(tx, newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { readResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -99,13 +100,13 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().update(tx, readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ @@ -115,12 +116,12 @@ public class ResourceModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { tx.getResourceMap().remove(tx, readResource); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -141,12 +142,12 @@ public class ResourceModelTestRunner { }; Collections.sort(resources, comparator); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { ResourceMap resourceMap = tx.getResourceMap(); resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { tx.getResourceMap().addAll(tx, resources); } @@ -155,13 +156,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { List allResources = tx.getResourceMap().getAllElements(tx); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { ResourceMap resourceMap = tx.getResourceMap(); Set types = resourceMap.getTypes(tx); @@ -179,7 +180,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getDefaultRealm().openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(resource); resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 4972c2ab1..09a902388 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -28,7 +28,6 @@ import li.strolch.service.api.ServiceHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import ch.eitchnet.utils.dbc.DBC; import ch.eitchnet.utils.helper.FileHelper; public final class RuntimeMock { @@ -57,10 +56,6 @@ public final class RuntimeMock { return this.container.getComponent(ServiceHandler.class); } - public StrolchRealm getDefaultRealm() { - return this.container.getDefaultRealm(); - } - public StrolchRealm getRealm(String realm) { return this.container.getRealm(realm); } @@ -109,15 +104,6 @@ public final class RuntimeMock { } } - /** - * @deprecated use parameterless {@link #startContainer()} - */ - @Deprecated - public void startContainer(File rootPathF) { - DBC.PRE.assertEquals("Starting a different runtime than was mocked!", this.rootPath, rootPathF); //$NON-NLS-1$ - startContainer(); - } - public void startContainer() { try { From c37792fead43f2464e319b29b09fccb4b29be01d Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Feb 2014 21:17:30 +0100 Subject: [PATCH 30/42] [New] added RuntimeMock.assertServiceResult() --- .../li/strolch/testbase/runtime/RuntimeMock.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 09a902388..f5518dc72 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -15,6 +15,9 @@ */ package li.strolch.testbase.runtime; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.File; import java.text.MessageFormat; @@ -24,11 +27,14 @@ import li.strolch.agent.impl.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import li.strolch.service.api.ServiceHandler; +import li.strolch.service.api.ServiceResult; +import li.strolch.service.api.ServiceResultState; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import ch.eitchnet.utils.helper.FileHelper; +import ch.eitchnet.utils.helper.StringHelper; public final class RuntimeMock { @@ -139,4 +145,14 @@ public final class RuntimeMock { logger.info("Failed to destroy container: " + e.getMessage()); //$NON-NLS-1$ } } + + public void assertServiceResult(ServiceResultState expectedState, Class expectedResultType, ServiceResult result) { + assertEquals("Expected service result of type " + expectedResultType + " but was " + result.getClass(), + expectedResultType, result.getClass()); + + if (!expectedState.equals(result.getState())) { + fail("Expected service result state " + expectedState + " but was " + result.getState() + ": Reason: " + + StringHelper.formatException(result.getThrowable())); + } + } } From 0189eab99aec5499e9d6240d3ab7d8b903ea0b18 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 17 Feb 2014 22:08:27 +0100 Subject: [PATCH 31/42] [New] Implemented separate DataStoreMode for each StrolchRealm --- .../java/li/strolch/testbase/runtime/OrderModelTestRunner.java | 2 +- .../li/strolch/testbase/runtime/ResourceModelTestRunner.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 2564479cf..23cef60db 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -110,7 +110,7 @@ public class OrderModelTestRunner { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); - if (this.runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 5a831e753..6bf25a553 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -110,7 +110,7 @@ public class ResourceModelTestRunner { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ - if (this.runtimeMock.getContainer().getDataStoreMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); From 9d72df10b10690eb9bda5e2d7f488e59add4e5e6 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 19 Feb 2014 00:11:46 +0100 Subject: [PATCH 32/42] [Minor] allow for overriding the realm in which the tests run --- .../testbase/runtime/AbstractModelTest.java | 20 +++++----- .../runtime/OrderModelTestRunner.java | 39 ++++++++++--------- .../runtime/ResourceModelTestRunner.java | 36 +++++++++-------- 3 files changed, 50 insertions(+), 45 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index 494ad23ff..0a4f697ec 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -9,9 +9,11 @@ public abstract class AbstractModelTest { protected abstract RuntimeMock getRuntimeMock(); + protected String realmName = StrolchConstants.DEFAULT_REALM; + @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getRuntimeMock().getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx()) { tx.getOrderMap().getAllKeys(tx); } } @@ -19,56 +21,56 @@ public abstract class AbstractModelTest { @Test public void shouldCreateOrders() { - OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runCreateOrderTest(); } @Test public void shouldQueryOrderSizes() { - OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runQuerySizeTest(); } @Test public void shouldOrderCrud() { - OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runCrudTests(); } @Test public void shouldOrderPerformBulkOperations() { - OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock()); + OrderModelTestRunner testRunner = new OrderModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runBulkOperationTests(); } @Test public void shouldCreateResources() { - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runCreateResourceTest(); } @Test public void shouldQueryResourceSizes() { - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runQuerySizeTest(); } @Test public void shouldResourceCrud() { - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runCrudTests(); } @Test public void shouldResourcePerformBulkOperations() { - ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock()); + ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runBulkOperationTests(); } } diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 23cef60db..1664d6862 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -21,7 +21,6 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.runtime.StrolchConstants; @SuppressWarnings("nls") public class OrderModelTestRunner { @@ -31,24 +30,26 @@ public class OrderModelTestRunner { private static final String TYPE = "ToStock"; private RuntimeMock runtimeMock; + private String realmName; - public OrderModelTestRunner(RuntimeMock runtimeMock) { + public OrderModelTestRunner(RuntimeMock runtimeMock, String realmName) { this.runtimeMock = runtimeMock; + this.realmName = realmName; } public void runCreateOrderTest() { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().add(tx, newOrder); } } public void runQuerySizeTest() { - + // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); } @@ -56,14 +57,14 @@ public class OrderModelTestRunner { Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().add(tx, order1); tx.getOrderMap().add(tx, order2); tx.getOrderMap().add(tx, order3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { long size = tx.getOrderMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -85,13 +86,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().add(tx, newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -100,28 +101,28 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().update(tx, readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); - if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readOrder == updatedOrder); Parameter updatedParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getOrderMap().remove(tx, readOrder); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { Order order = tx.getOrderMap().getBy(tx, TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -142,12 +143,12 @@ public class OrderModelTestRunner { }; Collections.sort(orders, comparator); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { OrderMap orderMap = tx.getOrderMap(); orderMap.removeAll(tx, orderMap.getAllElements(tx)); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { tx.getOrderMap().addAll(tx, orders); } @@ -156,13 +157,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { List allOrders = tx.getOrderMap().getAllElements(tx); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { OrderMap orderMap = tx.getOrderMap(); Set types = orderMap.getTypes(tx); @@ -180,7 +181,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(order); order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 6bf25a553..388b9cb27 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -31,16 +31,18 @@ public class ResourceModelTestRunner { private static final String TYPE = "Box"; //$NON-NLS-1$ private RuntimeMock runtimeMock; + private String realmName; - public ResourceModelTestRunner(RuntimeMock runtimeMock) { + public ResourceModelTestRunner(RuntimeMock runtimeMock, String realmName) { this.runtimeMock = runtimeMock; + this.realmName = realmName; } public void runCreateResourceTest() { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().add(tx, newResource); } } @@ -48,7 +50,7 @@ public class ResourceModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); } @@ -56,14 +58,14 @@ public class ResourceModelTestRunner { Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().add(tx, resource1); tx.getResourceMap().add(tx, resource2); tx.getResourceMap().add(tx, resource3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { long size = tx.getResourceMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -85,13 +87,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().add(tx, newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { readResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -100,28 +102,28 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().update(tx, readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ - if (this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).getMode() != DataStoreMode.CACHED) + if (this.runtimeMock.getRealm(this.realmName).getMode() != DataStoreMode.CACHED) assertFalse("Objects can't be the same reference after re-reading!", readResource == updatedResource); //$NON-NLS-1$ Parameter updatedParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { tx.getResourceMap().remove(tx, readResource); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -142,12 +144,12 @@ public class ResourceModelTestRunner { }; Collections.sort(resources, comparator); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { ResourceMap resourceMap = tx.getResourceMap(); resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { tx.getResourceMap().addAll(tx, resources); } @@ -156,13 +158,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { List allResources = tx.getResourceMap().getAllElements(tx); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { ResourceMap resourceMap = tx.getResourceMap(); Set types = resourceMap.getTypes(tx); @@ -180,7 +182,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(StrolchConstants.DEFAULT_REALM).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(resource); resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006"); From 859ca6a89d88056fec44f8ba31bf34f12e19ccf2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 24 Feb 2014 21:49:33 +0100 Subject: [PATCH 33/42] [New] Implemented locking for Strolch elements Also cleaned up hierarchy of StrolchTransaction by moving up everything into AbstractTransaction as made sense and added special delegation methods for the actual commit() and rollback() ind the concrete implementations. --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index f5518dc72..d5f692256 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -23,7 +23,7 @@ import java.text.MessageFormat; import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchAgent; -import li.strolch.agent.impl.StrolchRealm; +import li.strolch.agent.api.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; import li.strolch.runtime.privilege.StrolchPrivilegeHandler; import li.strolch.service.api.ServiceHandler; From c8d41ac497fee6cc1475a264ac423a0998283b19 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Mon, 3 Mar 2014 23:35:45 +0100 Subject: [PATCH 34/42] [Minor] RuntimeMock.assertServiceResult is static --- .../li/strolch/testbase/runtime/ResourceModelTestRunner.java | 1 - src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index 388b9cb27..cef7b40b5 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -21,7 +21,6 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; -import li.strolch.runtime.StrolchConstants; @SuppressWarnings("nls") public class ResourceModelTestRunner { diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index d5f692256..1d4b535a7 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -146,7 +146,8 @@ public final class RuntimeMock { } } - public void assertServiceResult(ServiceResultState expectedState, Class expectedResultType, ServiceResult result) { + public static void assertServiceResult(ServiceResultState expectedState, Class expectedResultType, + ServiceResult result) { assertEquals("Expected service result of type " + expectedResultType + " but was " + result.getClass(), expectedResultType, result.getClass()); From 88e3c6961e117b79d778c1b5e7de347e54d79724 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Fri, 14 Mar 2014 14:37:11 +0100 Subject: [PATCH 35/42] [Project] fixed urls of projects --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 337e715af..3a9d2c1c8 100644 --- a/pom.xml +++ b/pom.xml @@ -14,19 +14,19 @@ li.strolch.testbase runtime for Strolch - https://github.com/eitch/li.strolch.testbase + https://github.com/eitchnet/li.strolch.testbase 2011 Github Issues - https://github.com/eitch/li.strolch.testbase/issues + https://github.com/eitchnet/li.strolch.testbase/issues - scm:git:https://github.com/eitch/li.strolch.testbase.git + scm:git:https://github.com/eitchnet/li.strolch.testbase.git scm:git:git@github.com:eitch/li.strolch.testbase.git - https://github.com/eitch/li.strolch.testbase + https://github.com/eitchnet/li.strolch.testbase From c16685dfc6b43d0877aab1ba4201dc900b9158f2 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Thu, 31 Jul 2014 16:12:56 +0200 Subject: [PATCH 36/42] [New] added tests for ElementMap.removeAll() --- .../runtime/OrderModelTestRunner.java | 48 +++++++++++++++++++ .../runtime/ResourceModelTestRunner.java | 48 +++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 1664d6862..7ac799d1d 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -130,11 +130,13 @@ public class OrderModelTestRunner { public void runBulkOperationTests() { + // create 15 orders List orders = new ArrayList<>(); orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1")); orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2")); orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3")); + // sort them so we know which order our objects are Comparator comparator = new Comparator() { @Override public int compare(Order o1, Order o2) { @@ -143,11 +145,57 @@ public class OrderModelTestRunner { }; Collections.sort(orders, comparator); + // first clear the map, so that we have a clean state try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { OrderMap orderMap = tx.getOrderMap(); orderMap.removeAll(tx, orderMap.getAllElements(tx)); } + { + // make sure it is empty + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + OrderMap orderMap = tx.getOrderMap(); + assertEquals(0, orderMap.querySize(tx)); + } + + // now add some orders + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + tx.getOrderMap().addAll(tx, orders); + } + + // make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + OrderMap orderMap = tx.getOrderMap(); + assertEquals(orders.size(), orderMap.querySize(tx)); + assertEquals(5, orderMap.querySize(tx, "MyType3")); + } + + // now use the remove all by type + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + tx.getOrderMap().removeAllBy(tx, "MyType3"); + } + + // again make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + OrderMap orderMap = tx.getOrderMap(); + assertEquals(orders.size() - 5, orderMap.querySize(tx)); + assertEquals(0, orderMap.querySize(tx, "MyType3")); + } + + // now use the remove all + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + long removed = tx.getOrderMap().removeAll(tx); + assertEquals(orders.size() - 5, removed); + } + + // again make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + OrderMap orderMap = tx.getOrderMap(); + assertEquals(0, orderMap.querySize(tx)); + } + } + + // now add all again try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { tx.getOrderMap().addAll(tx, orders); } diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index cef7b40b5..fca679116 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -130,11 +130,13 @@ public class ResourceModelTestRunner { public void runBulkOperationTests() { + // create 15 resources List resources = new ArrayList<>(); resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1")); resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2")); resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3")); + // sort them so we know which order our objects are Comparator comparator = new Comparator() { @Override public int compare(Resource o1, Resource o2) { @@ -143,11 +145,57 @@ public class ResourceModelTestRunner { }; Collections.sort(resources, comparator); + // first clear the map, so that we have a clean state try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { ResourceMap resourceMap = tx.getResourceMap(); resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } + { + // make sure it is empty + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + ResourceMap resourceMap = tx.getResourceMap(); + assertEquals(0, resourceMap.querySize(tx)); + } + + // now add some resources + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + tx.getResourceMap().addAll(tx, resources); + } + + // make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + ResourceMap resourceMap = tx.getResourceMap(); + assertEquals(resources.size(), resourceMap.querySize(tx)); + assertEquals(5, resourceMap.querySize(tx, "MyType3")); + } + + // now use the remove all by type + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + tx.getResourceMap().removeAllBy(tx, "MyType3"); + } + + // again make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + ResourceMap resourceMap = tx.getResourceMap(); + assertEquals(resources.size() - 5, resourceMap.querySize(tx)); + assertEquals(0, resourceMap.querySize(tx, "MyType3")); + } + + // now use the remove all + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + long removed = tx.getResourceMap().removeAll(tx); + assertEquals(resources.size() - 5, removed); + } + + // again make sure we have our expected size + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + ResourceMap resourceMap = tx.getResourceMap(); + assertEquals(0, resourceMap.querySize(tx)); + } + } + + // now add all again try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { tx.getResourceMap().addAll(tx, resources); } From 54c9038c9f3353f2cc74d723fdf274b1efba1341 Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Wed, 13 Aug 2014 16:07:06 +0200 Subject: [PATCH 37/42] [Major] Refactored StrolchConfiguration.xml to use environments Now the agent requires an environment parameter to start, and the configuration of that environment is used to load different sections of the configuration file --- src/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 1d4b535a7..0f7c30042 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -111,10 +111,14 @@ public final class RuntimeMock { } public void startContainer() { + startContainer("dev"); + } + + public void startContainer(String environment) { try { StrolchAgent agent = new StrolchAgent(); - agent.setup(this.rootPath); + agent.setup(environment, this.rootPath); agent.initialize(); agent.start(); From cc9cfcadba1e151ba62aee01eb3ea7af779d3c5f Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sat, 23 Aug 2014 20:50:28 +0200 Subject: [PATCH 38/42] [New] Implemented opt-in audit trail in Strolch The audit trail has its own map on the Realm and a trail is written by realm at the end of the transaction. You can write your own audit trail using tx.getAuditTrail(). Enable the audit trail by setting the realm configuration value 'enableAuditTrail'. --- .../testbase/runtime/AbstractModelTest.java | 13 +- .../runtime/AuditModelTestRunner.java | 319 ++++++++++++++++++ .../runtime/OrderModelTestRunner.java | 50 +-- .../runtime/ResourceModelTestRunner.java | 50 +-- .../strolch/testbase/runtime/RuntimeMock.java | 6 +- 5 files changed, 390 insertions(+), 48 deletions(-) create mode 100644 src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java index 0a4f697ec..48217b11f 100644 --- a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java +++ b/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java @@ -2,9 +2,12 @@ package li.strolch.testbase.runtime; import li.strolch.persistence.api.StrolchTransaction; import li.strolch.runtime.StrolchConstants; +import li.strolch.runtime.privilege.PrivilegeHandler; import org.junit.Test; +import ch.eitchnet.privilege.model.Certificate; + public abstract class AbstractModelTest { protected abstract RuntimeMock getRuntimeMock(); @@ -13,7 +16,9 @@ public abstract class AbstractModelTest { @Test public void shouldStartContainer() { - try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx()) { + PrivilegeHandler privilegeHandler = getRuntimeMock().getContainer().getPrivilegeHandler(); + Certificate certificate = privilegeHandler.authenticate("test", "test".getBytes()); + try (StrolchTransaction tx = getRuntimeMock().getRealm(this.realmName).openTx(certificate, "test")) { tx.getOrderMap().getAllKeys(tx); } } @@ -73,4 +78,10 @@ public abstract class AbstractModelTest { ResourceModelTestRunner testRunner = new ResourceModelTestRunner(getRuntimeMock(), this.realmName); testRunner.runBulkOperationTests(); } + + @Test + public void shouldTestAudits() { + AuditModelTestRunner testRunner = new AuditModelTestRunner(getRuntimeMock(), this.realmName); + testRunner.runTestForAudits(); + } } diff --git a/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java new file mode 100644 index 000000000..abc3d3156 --- /dev/null +++ b/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java @@ -0,0 +1,319 @@ +/* + * Copyright 2013 Robert von Burg + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package li.strolch.testbase.runtime; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collections; +import java.util.Comparator; +import java.util.Date; +import java.util.List; +import java.util.Set; + +import li.strolch.agent.api.AuditTrail; +import li.strolch.agent.api.StrolchRealm; +import li.strolch.model.ModelGenerator; +import li.strolch.model.audit.Audit; +import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; +import ch.eitchnet.utils.collections.DateRange; + +/** + * @author Robert von Burg + */ +public class AuditModelTestRunner { + + private RuntimeMock runtimeMock; + private String realmName; + private Certificate certificate; + + /** + * @param runtimeMock + * @param realmName + */ + public AuditModelTestRunner(RuntimeMock runtimeMock, String realmName) { + this.runtimeMock = runtimeMock; + this.realmName = realmName; + + PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); + certificate = privilegeHandler.authenticate("test", "test".getBytes()); + } + + public void runTestForAudits() { + + StrolchRealm realm = runtimeMock.getRealm(realmName); + + Calendar cal = Calendar.getInstance(); + + cal.set(2000, 6, 1); + Date beforeCurrent = cal.getTime(); + cal.set(2000, 6, 2); + Date current = cal.getTime(); + cal.set(2000, 6, 3); + Date afterCurrent = cal.getTime(); + cal.set(2000, 1, 1); + Date earlier = cal.getTime(); + cal.set(2000, 11, 1); + Date later = cal.getTime(); + + DateRange earlierRange = new DateRange().from(earlier, true).to(beforeCurrent, true); + DateRange equalsRange = new DateRange().from(current, true).to(current, true); + DateRange laterRange = new DateRange().from(afterCurrent, true).to(later, true); + DateRange containsRange = new DateRange().from(earlier, true).to(later, true); + + // first cleanup + cleanup(realm); + + // single element actions + { + Audit audit = ModelGenerator.randomAudit(); + audit.setDate(current); + + // add + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.add(tx, audit); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + Set types = auditTrail.getTypes(tx); + assertEquals(1, types.size()); + assertTrue(types.contains(audit.getElementType())); + } + + // has + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertTrue(auditTrail.hasAudit(tx, audit.getElementType(), audit.getId())); + + Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); + assertNotNull(dbAudit); + assertEquals(audit, dbAudit); + + dbAudit = auditTrail.getBy(tx, "Foo", audit.getId()); + assertNull(dbAudit); + } + + // remove + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.remove(tx, audit); + } + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); + assertNull(dbAudit); + } + + // update + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.add(tx, audit); + } + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); + dbAudit.setAction("Foo"); + auditTrail.update(tx, dbAudit); + } + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); + assertEquals("Foo", dbAudit.getAction()); + } + } + + // querying + { + Audit audit = ModelGenerator.randomAudit(); + audit.setDate(current); + + // querySize + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), equalsRange)); + assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange)); + assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), earlierRange)); + assertEquals(0, auditTrail.querySize(tx, audit.getElementType(), laterRange)); + } + } + + // mass element actions + { + List audits = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Audit randomAudit = ModelGenerator.randomAudit(); + randomAudit.setElementType("FooBar"); + randomAudit.setDate(current); + audits.add(randomAudit); + } + Collections.sort(audits, new AuditByIdComparator()); + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.addAll(tx, audits); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertEquals(100, auditTrail.querySize(tx, "FooBar", containsRange)); + + List allElements = auditTrail.getAllElements(tx, "FooBar", containsRange); + Collections.sort(allElements, new AuditByIdComparator()); + assertEquals(audits, allElements); + + allElements = auditTrail.getAllElements(tx, "FooBar", earlierRange); + assertEquals(0, allElements.size()); + allElements = auditTrail.getAllElements(tx, "FooBar", laterRange); + assertEquals(0, allElements.size()); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.removeAll(tx, audits); + assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); + } + } + + // update all + { + List audits = new ArrayList<>(); + for (int i = 0; i < 100; i++) { + Audit randomAudit = ModelGenerator.randomAudit(); + randomAudit.setElementType("Bar"); + randomAudit.setDate(current); + randomAudit.setAction("BarFoo"); + audits.add(randomAudit); + } + Collections.sort(audits, new AuditByIdComparator()); + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.addAll(tx, audits); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + List allElements = auditTrail.getAllElements(tx, "Bar", containsRange); + Collections.sort(allElements, new AuditByIdComparator()); + assertEquals(audits, allElements); + + for (Audit dbAudit : allElements) { + assertEquals("BarFoo", dbAudit.getAction()); + } + + for (Audit dbAudit : allElements) { + dbAudit.setAction("Foo"); + } + + auditTrail.updateAll(tx, allElements); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + List allElements = auditTrail.getAllElements(tx, "Bar", containsRange); + for (Audit dbAudit : allElements) { + assertEquals("Foo", dbAudit.getAction()); + } + } + } + + // remove all + { + // first cleanup + cleanup(realm); + + List audits = new ArrayList<>(); + for (int i = 0; i < 5; i++) { + Audit randomAudit = ModelGenerator.randomAudit(); + randomAudit.setDate(current); + randomAudit.setElementType("BarBarBar"); + audits.add(randomAudit); + } + for (int i = 0; i < 5; i++) { + Audit randomAudit = ModelGenerator.randomAudit(); + randomAudit.setDate(current); + randomAudit.setElementType("FooFooFoo"); + audits.add(randomAudit); + } + for (int i = 0; i < 5; i++) { + Audit randomAudit = ModelGenerator.randomAudit(); + randomAudit.setDate(current); + randomAudit.setElementType("BarFooBar"); + audits.add(randomAudit); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + auditTrail.addAll(tx, audits); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertEquals(15, auditTrail.querySize(tx, containsRange)); + assertEquals(5, auditTrail.querySize(tx, "BarBarBar", containsRange)); + assertEquals(5, auditTrail.querySize(tx, "FooFooFoo", containsRange)); + assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange)); + } + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + assertEquals(5, auditTrail.removeAll(tx, "BarBarBar", containsRange)); + assertEquals(10, auditTrail.querySize(tx, containsRange)); + + assertEquals(5, auditTrail.removeAll(tx, "FooFooFoo", containsRange)); + assertEquals(5, auditTrail.querySize(tx, containsRange)); + + assertEquals(5, auditTrail.removeAll(tx, "BarFooBar", containsRange)); + assertEquals(0, auditTrail.querySize(tx, containsRange)); + } + } + } + + private void cleanup(StrolchRealm realm) { + + DateRange dateRange = new DateRange().from(new Date(0), true).to(new Date((long) Math.pow(2, 50)), true); + + try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + AuditTrail auditTrail = tx.getAuditTrail(); + Set types = auditTrail.getTypes(tx); + for (String type : types) { + auditTrail.removeAll(tx, type, dateRange); + } + + assertEquals(0, auditTrail.querySize(tx, dateRange)); + } + } + + private final class AuditByIdComparator implements Comparator { + @Override + public int compare(Audit o1, Audit o2) { + return o1.getId().compareTo(o2.getId()); + } + } +} diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 7ac799d1d..72dedb490 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -21,6 +21,8 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Order; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; @SuppressWarnings("nls") public class OrderModelTestRunner { @@ -31,17 +33,21 @@ public class OrderModelTestRunner { private RuntimeMock runtimeMock; private String realmName; + private Certificate certificate; public OrderModelTestRunner(RuntimeMock runtimeMock, String realmName) { this.runtimeMock = runtimeMock; this.realmName = realmName; + + PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); + certificate = privilegeHandler.authenticate("test", "test".getBytes()); } public void runCreateOrderTest() { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().add(tx, newOrder); } } @@ -49,7 +55,7 @@ public class OrderModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); } @@ -57,14 +63,14 @@ public class OrderModelTestRunner { Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().add(tx, order1); tx.getOrderMap().add(tx, order2); tx.getOrderMap().add(tx, order3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { long size = tx.getOrderMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -86,13 +92,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().add(tx, newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -101,13 +107,13 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().update(tx, readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); @@ -117,12 +123,12 @@ public class OrderModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getOrderMap().remove(tx, readOrder); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { Order order = tx.getOrderMap().getBy(tx, TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -146,57 +152,57 @@ public class OrderModelTestRunner { Collections.sort(orders, comparator); // first clear the map, so that we have a clean state - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); orderMap.removeAll(tx, orderMap.getAllElements(tx)); } { // make sure it is empty - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(0, orderMap.querySize(tx)); } // now add some orders - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getOrderMap().addAll(tx, orders); } // make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(orders.size(), orderMap.querySize(tx)); assertEquals(5, orderMap.querySize(tx, "MyType3")); } // now use the remove all by type - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getOrderMap().removeAllBy(tx, "MyType3"); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(orders.size() - 5, orderMap.querySize(tx)); assertEquals(0, orderMap.querySize(tx, "MyType3")); } // now use the remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { long removed = tx.getOrderMap().removeAll(tx); assertEquals(orders.size() - 5, removed); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(0, orderMap.querySize(tx)); } } // now add all again - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getOrderMap().addAll(tx, orders); } @@ -205,13 +211,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { List allOrders = tx.getOrderMap().getAllElements(tx); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); Set types = orderMap.getTypes(tx); @@ -229,7 +235,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(order); order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index fca679116..e790e8dde 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -21,6 +21,8 @@ import li.strolch.agent.impl.DataStoreMode; import li.strolch.model.Resource; import li.strolch.model.parameter.Parameter; import li.strolch.persistence.api.StrolchTransaction; +import li.strolch.runtime.privilege.PrivilegeHandler; +import ch.eitchnet.privilege.model.Certificate; @SuppressWarnings("nls") public class ResourceModelTestRunner { @@ -31,17 +33,21 @@ public class ResourceModelTestRunner { private RuntimeMock runtimeMock; private String realmName; + private Certificate certificate; public ResourceModelTestRunner(RuntimeMock runtimeMock, String realmName) { this.runtimeMock = runtimeMock; this.realmName = realmName; + + PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); + certificate = privilegeHandler.authenticate("test", "test".getBytes()); } public void runCreateResourceTest() { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().add(tx, newResource); } } @@ -49,7 +55,7 @@ public class ResourceModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); } @@ -57,14 +63,14 @@ public class ResourceModelTestRunner { Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().add(tx, resource1); tx.getResourceMap().add(tx, resource2); tx.getResourceMap().add(tx, resource3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { long size = tx.getResourceMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -86,13 +92,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().add(tx, newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { readResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -101,13 +107,13 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().update(tx, readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ @@ -117,12 +123,12 @@ public class ResourceModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { tx.getResourceMap().remove(tx, readResource); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx();) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -146,57 +152,57 @@ public class ResourceModelTestRunner { Collections.sort(resources, comparator); // first clear the map, so that we have a clean state - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } { // make sure it is empty - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(0, resourceMap.querySize(tx)); } // now add some resources - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getResourceMap().addAll(tx, resources); } // make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(resources.size(), resourceMap.querySize(tx)); assertEquals(5, resourceMap.querySize(tx, "MyType3")); } // now use the remove all by type - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getResourceMap().removeAllBy(tx, "MyType3"); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(resources.size() - 5, resourceMap.querySize(tx)); assertEquals(0, resourceMap.querySize(tx, "MyType3")); } // now use the remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { long removed = tx.getResourceMap().removeAll(tx); assertEquals(resources.size() - 5, removed); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(0, resourceMap.querySize(tx)); } } // now add all again - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { tx.getResourceMap().addAll(tx, resources); } @@ -205,13 +211,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { List allResources = tx.getResourceMap().getAllElements(tx); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); Set types = resourceMap.getTypes(tx); @@ -229,7 +235,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx()) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001"); assertNotNull(resource); resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java index 0f7c30042..757aa84f3 100644 --- a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java +++ b/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java @@ -25,7 +25,7 @@ import li.strolch.agent.api.ComponentContainer; import li.strolch.agent.api.StrolchAgent; import li.strolch.agent.api.StrolchRealm; import li.strolch.runtime.configuration.RuntimeConfiguration; -import li.strolch.runtime.privilege.StrolchPrivilegeHandler; +import li.strolch.runtime.privilege.PrivilegeHandler; import li.strolch.service.api.ServiceHandler; import li.strolch.service.api.ServiceResult; import li.strolch.service.api.ServiceResultState; @@ -54,8 +54,8 @@ public final class RuntimeMock { return this.agent; } - public StrolchPrivilegeHandler getPrivilegeHandler() { - return this.container.getComponent(StrolchPrivilegeHandler.class); + public PrivilegeHandler getPrivilegeHandler() { + return this.container.getPrivilegeHandler(); } public ServiceHandler getServiceHandler() { From b6a0938dc3bebc11aea10611055a522bc0c0d19f Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 24 Aug 2014 17:24:10 +0200 Subject: [PATCH 39/42] [Project] set version to 1.0.0-SNAPSHOT --- pom.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3a9d2c1c8..ed13b0aae 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ li.strolch li.strolch.parent - 0.1.0-SNAPSHOT + 1.0.0-SNAPSHOT ../li.strolch.parent/pom.xml @@ -30,6 +30,7 @@ + li.strolch li.strolch.model From a8d25c2dd1590978e7c9e498139edf2d2391ba9c Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 14 Sep 2014 12:14:25 +0200 Subject: [PATCH 40/42] [Minor] removed underscore in test objects --- .../testbase/runtime/OrderModelTestRunner.java | 12 ++++++------ .../testbase/runtime/ResourceModelTestRunner.java | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index 72dedb490..aa217abfc 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -138,9 +138,9 @@ public class OrderModelTestRunner { // create 15 orders List orders = new ArrayList<>(); - orders.addAll(createOrders(orders.size(), 5, "@", "My Order ", "MyType1")); - orders.addAll(createOrders(orders.size(), 5, "@", "Other Order ", "MyType2")); - orders.addAll(createOrders(orders.size(), 5, "@", "Further Order ", "MyType3")); + orders.addAll(createOrders(orders.size(), 5, "@", "My Order", "MyType1")); + orders.addAll(createOrders(orders.size(), 5, "@", "Other Order", "MyType2")); + orders.addAll(createOrders(orders.size(), 5, "@", "Further Order", "MyType3")); // sort them so we know which order our objects are Comparator comparator = new Comparator() { @@ -236,11 +236,11 @@ public class OrderModelTestRunner { } try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { - Order order = tx.getOrderMap().getBy(tx, "MyType1", "@_00000001"); + Order order = tx.getOrderMap().getBy(tx, "MyType1", "@00000001"); assertNotNull(order); - order = tx.getOrderMap().getBy(tx, "MyType2", "@_00000006"); + order = tx.getOrderMap().getBy(tx, "MyType2", "@00000006"); assertNotNull(order); - order = tx.getOrderMap().getBy(tx, "MyType3", "@_00000011"); + order = tx.getOrderMap().getBy(tx, "MyType3", "@00000011"); assertNotNull(order); } } diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index e790e8dde..c8820016c 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -138,9 +138,9 @@ public class ResourceModelTestRunner { // create 15 resources List resources = new ArrayList<>(); - resources.addAll(createResources(resources.size(), 5, "@", "My Resource ", "MyType1")); - resources.addAll(createResources(resources.size(), 5, "@", "Other Resource ", "MyType2")); - resources.addAll(createResources(resources.size(), 5, "@", "Further Resource ", "MyType3")); + resources.addAll(createResources(resources.size(), 5, "@", "My Resource", "MyType1")); + resources.addAll(createResources(resources.size(), 5, "@", "Other Resource", "MyType2")); + resources.addAll(createResources(resources.size(), 5, "@", "Further Resource", "MyType3")); // sort them so we know which order our objects are Comparator comparator = new Comparator() { @@ -236,11 +236,11 @@ public class ResourceModelTestRunner { } try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { - Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@_00000001"); + Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@00000001"); assertNotNull(resource); - resource = tx.getResourceMap().getBy(tx, "MyType2", "@_00000006"); + resource = tx.getResourceMap().getBy(tx, "MyType2", "@00000006"); assertNotNull(resource); - resource = tx.getResourceMap().getBy(tx, "MyType3", "@_00000011"); + resource = tx.getResourceMap().getBy(tx, "MyType3", "@00000011"); assertNotNull(resource); } } From a703361db0992e009ccc2253d7c81ccc980a485a Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Sun, 14 Sep 2014 12:20:58 +0200 Subject: [PATCH 41/42] [Minor] code cleanup --- .../runtime/AuditModelTestRunner.java | 44 +++++++++--------- .../runtime/OrderModelTestRunner.java | 46 +++++++++---------- .../runtime/ResourceModelTestRunner.java | 46 +++++++++---------- 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java index abc3d3156..12d1bf5f4 100644 --- a/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java @@ -55,12 +55,12 @@ public class AuditModelTestRunner { this.realmName = realmName; PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); - certificate = privilegeHandler.authenticate("test", "test".getBytes()); + this.certificate = privilegeHandler.authenticate("test", "test".getBytes()); } public void runTestForAudits() { - StrolchRealm realm = runtimeMock.getRealm(realmName); + StrolchRealm realm = this.runtimeMock.getRealm(this.realmName); Calendar cal = Calendar.getInstance(); @@ -89,12 +89,12 @@ public class AuditModelTestRunner { audit.setDate(current); // add - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.add(tx, audit); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); Set types = auditTrail.getTypes(tx); assertEquals(1, types.size()); @@ -102,7 +102,7 @@ public class AuditModelTestRunner { } // has - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertTrue(auditTrail.hasAudit(tx, audit.getElementType(), audit.getId())); @@ -115,28 +115,28 @@ public class AuditModelTestRunner { } // remove - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.remove(tx, audit); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); assertNull(dbAudit); } // update - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.add(tx, audit); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); dbAudit.setAction("Foo"); auditTrail.update(tx, dbAudit); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); Audit dbAudit = auditTrail.getBy(tx, audit.getElementType(), audit.getId()); assertEquals("Foo", dbAudit.getAction()); @@ -149,7 +149,7 @@ public class AuditModelTestRunner { audit.setDate(current); // querySize - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), equalsRange)); assertEquals(1, auditTrail.querySize(tx, audit.getElementType(), containsRange)); @@ -169,12 +169,12 @@ public class AuditModelTestRunner { } Collections.sort(audits, new AuditByIdComparator()); - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.addAll(tx, audits); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertEquals(100, auditTrail.querySize(tx, "FooBar", containsRange)); @@ -188,13 +188,13 @@ public class AuditModelTestRunner { assertEquals(0, allElements.size()); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.removeAll(tx, audits); assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertEquals(0, auditTrail.querySize(tx, "FooBar", containsRange)); } @@ -212,12 +212,12 @@ public class AuditModelTestRunner { } Collections.sort(audits, new AuditByIdComparator()); - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.addAll(tx, audits); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); List allElements = auditTrail.getAllElements(tx, "Bar", containsRange); Collections.sort(allElements, new AuditByIdComparator()); @@ -234,7 +234,7 @@ public class AuditModelTestRunner { auditTrail.updateAll(tx, allElements); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); List allElements = auditTrail.getAllElements(tx, "Bar", containsRange); for (Audit dbAudit : allElements) { @@ -268,12 +268,12 @@ public class AuditModelTestRunner { audits.add(randomAudit); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); auditTrail.addAll(tx, audits); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertEquals(15, auditTrail.querySize(tx, containsRange)); assertEquals(5, auditTrail.querySize(tx, "BarBarBar", containsRange)); @@ -281,7 +281,7 @@ public class AuditModelTestRunner { assertEquals(5, auditTrail.querySize(tx, "BarFooBar", containsRange)); } - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); assertEquals(5, auditTrail.removeAll(tx, "BarBarBar", containsRange)); assertEquals(10, auditTrail.querySize(tx, containsRange)); @@ -299,7 +299,7 @@ public class AuditModelTestRunner { DateRange dateRange = new DateRange().from(new Date(0), true).to(new Date((long) Math.pow(2, 50)), true); - try (StrolchTransaction tx = realm.openTx(certificate, "test")) { + try (StrolchTransaction tx = realm.openTx(this.certificate, "test")) { AuditTrail auditTrail = tx.getAuditTrail(); Set types = auditTrail.getTypes(tx); for (String type : types) { diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java index aa217abfc..59fc3f4f2 100644 --- a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java @@ -40,14 +40,14 @@ public class OrderModelTestRunner { this.realmName = realmName; PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); - certificate = privilegeHandler.authenticate("test", "test".getBytes()); + this.certificate = privilegeHandler.authenticate("test", "test".getBytes()); } public void runCreateOrderTest() { // create Order newOrder = createOrder("MyTestOrder", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().add(tx, newOrder); } } @@ -55,7 +55,7 @@ public class OrderModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().removeAll(tx, tx.getOrderMap().getAllElements(tx)); } @@ -63,14 +63,14 @@ public class OrderModelTestRunner { Order order1 = createOrder("myTestOrder1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order2 = createOrder("myTestOrder2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Order order3 = createOrder("myTestOrder3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().add(tx, order1); tx.getOrderMap().add(tx, order2); tx.getOrderMap().add(tx, order3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { long size = tx.getOrderMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -92,13 +92,13 @@ public class OrderModelTestRunner { // create Order newOrder = createOrder(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().add(tx, newOrder); } // read Order readOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { readOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, readOrder); @@ -107,13 +107,13 @@ public class OrderModelTestRunner { Parameter sParam = readOrder.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().update(tx, readOrder); } // read updated Order updatedOrder = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { updatedOrder = tx.getOrderMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Order with id " + ID, updatedOrder); @@ -123,12 +123,12 @@ public class OrderModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getOrderMap().remove(tx, readOrder); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { Order order = tx.getOrderMap().getBy(tx, TYPE, ID); assertNull("Should no read Order with id " + ID, order); } @@ -152,57 +152,57 @@ public class OrderModelTestRunner { Collections.sort(orders, comparator); // first clear the map, so that we have a clean state - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); orderMap.removeAll(tx, orderMap.getAllElements(tx)); } { // make sure it is empty - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(0, orderMap.querySize(tx)); } // now add some orders - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getOrderMap().addAll(tx, orders); } // make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(orders.size(), orderMap.querySize(tx)); assertEquals(5, orderMap.querySize(tx, "MyType3")); } // now use the remove all by type - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getOrderMap().removeAllBy(tx, "MyType3"); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(orders.size() - 5, orderMap.querySize(tx)); assertEquals(0, orderMap.querySize(tx, "MyType3")); } // now use the remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { long removed = tx.getOrderMap().removeAll(tx); assertEquals(orders.size() - 5, removed); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); assertEquals(0, orderMap.querySize(tx)); } } // now add all again - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getOrderMap().addAll(tx, orders); } @@ -211,13 +211,13 @@ public class OrderModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { List allOrders = tx.getOrderMap().getAllElements(tx); Collections.sort(allOrders, comparator); assertEquals(orders, allOrders); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { OrderMap orderMap = tx.getOrderMap(); Set types = orderMap.getTypes(tx); @@ -235,7 +235,7 @@ public class OrderModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { Order order = tx.getOrderMap().getBy(tx, "MyType1", "@00000001"); assertNotNull(order); order = tx.getOrderMap().getBy(tx, "MyType2", "@00000006"); diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java index c8820016c..4725a53e7 100644 --- a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java +++ b/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java @@ -40,14 +40,14 @@ public class ResourceModelTestRunner { this.realmName = realmName; PrivilegeHandler privilegeHandler = runtimeMock.getContainer().getPrivilegeHandler(); - certificate = privilegeHandler.authenticate("test", "test".getBytes()); + this.certificate = privilegeHandler.authenticate("test", "test".getBytes()); } public void runCreateResourceTest() { // create Resource newResource = createResource("MyTestResource", "Test Name", "TestType"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().add(tx, newResource); } } @@ -55,7 +55,7 @@ public class ResourceModelTestRunner { public void runQuerySizeTest() { // remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().removeAll(tx, tx.getResourceMap().getAllElements(tx)); } @@ -63,14 +63,14 @@ public class ResourceModelTestRunner { Resource resource1 = createResource("myTestResource1", "Test Name", "QTestType1"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource2 = createResource("myTestResource2", "Test Name", "QTestType2"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ Resource resource3 = createResource("myTestResource3", "Test Name", "QTestType3"); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().add(tx, resource1); tx.getResourceMap().add(tx, resource2); tx.getResourceMap().add(tx, resource3); } // query size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { long size = tx.getResourceMap().querySize(tx); assertEquals("Should have three objects", 3, size); @@ -92,13 +92,13 @@ public class ResourceModelTestRunner { // create Resource newResource = createResource(ID, NAME, TYPE); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().add(tx, newResource); } // read Resource readResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { readResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, readResource); //$NON-NLS-1$ @@ -107,13 +107,13 @@ public class ResourceModelTestRunner { Parameter sParam = readResource.getParameter(BAG_ID, PARAM_STRING_ID); String newStringValue = "Giddiya!"; //$NON-NLS-1$ sParam.setValue(newStringValue); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().update(tx, readResource); } // read updated Resource updatedResource = null; - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { updatedResource = tx.getResourceMap().getBy(tx, TYPE, ID); } assertNotNull("Should read Resource with id " + ID, updatedResource); //$NON-NLS-1$ @@ -123,12 +123,12 @@ public class ResourceModelTestRunner { assertEquals(newStringValue, updatedParam.getValue()); // delete - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { tx.getResourceMap().remove(tx, readResource); } // fail to re-read - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test");) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test");) { Resource resource = tx.getResourceMap().getBy(tx, TYPE, ID); assertNull("Should no read Resource with id " + ID, resource); //$NON-NLS-1$ } @@ -152,57 +152,57 @@ public class ResourceModelTestRunner { Collections.sort(resources, comparator); // first clear the map, so that we have a clean state - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); resourceMap.removeAll(tx, resourceMap.getAllElements(tx)); } { // make sure it is empty - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(0, resourceMap.querySize(tx)); } // now add some resources - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getResourceMap().addAll(tx, resources); } // make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(resources.size(), resourceMap.querySize(tx)); assertEquals(5, resourceMap.querySize(tx, "MyType3")); } // now use the remove all by type - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getResourceMap().removeAllBy(tx, "MyType3"); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(resources.size() - 5, resourceMap.querySize(tx)); assertEquals(0, resourceMap.querySize(tx, "MyType3")); } // now use the remove all - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { long removed = tx.getResourceMap().removeAll(tx); assertEquals(resources.size() - 5, removed); } // again make sure we have our expected size - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); assertEquals(0, resourceMap.querySize(tx)); } } // now add all again - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { tx.getResourceMap().addAll(tx, resources); } @@ -211,13 +211,13 @@ public class ResourceModelTestRunner { expectedTypes.add("MyType2"); expectedTypes.add("MyType3"); - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { List allResources = tx.getResourceMap().getAllElements(tx); Collections.sort(allResources, comparator); assertEquals(resources, allResources); } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { ResourceMap resourceMap = tx.getResourceMap(); Set types = resourceMap.getTypes(tx); @@ -235,7 +235,7 @@ public class ResourceModelTestRunner { } } - try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(certificate, "test")) { + try (StrolchTransaction tx = this.runtimeMock.getRealm(this.realmName).openTx(this.certificate, "test")) { Resource resource = tx.getResourceMap().getBy(tx, "MyType1", "@00000001"); assertNotNull(resource); resource = tx.getResourceMap().getBy(tx, "MyType2", "@00000006"); From 77ef27a7f2a6b313f0c79967f798027851a115cf Mon Sep 17 00:00:00 2001 From: Robert von Burg Date: Tue, 16 Sep 2014 08:54:07 +0200 Subject: [PATCH 42/42] moved everything to a subdirectory for repo merge --- .gitignore => li.strolch.testbase/.gitignore | 0 LICENSE => li.strolch.testbase/LICENSE | 0 README.md => li.strolch.testbase/README.md | 0 pom.xml => li.strolch.testbase/pom.xml | 0 .../main/java/li/strolch/testbase/runtime/AbstractModelTest.java | 0 .../java/li/strolch/testbase/runtime/AuditModelTestRunner.java | 0 .../java/li/strolch/testbase/runtime/OrderModelTestRunner.java | 0 .../java/li/strolch/testbase/runtime/ResourceModelTestRunner.java | 0 .../src}/main/java/li/strolch/testbase/runtime/RuntimeMock.java | 0 9 files changed, 0 insertions(+), 0 deletions(-) rename .gitignore => li.strolch.testbase/.gitignore (100%) rename LICENSE => li.strolch.testbase/LICENSE (100%) rename README.md => li.strolch.testbase/README.md (100%) rename pom.xml => li.strolch.testbase/pom.xml (100%) rename {src => li.strolch.testbase/src}/main/java/li/strolch/testbase/runtime/AbstractModelTest.java (100%) rename {src => li.strolch.testbase/src}/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java (100%) rename {src => li.strolch.testbase/src}/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java (100%) rename {src => li.strolch.testbase/src}/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java (100%) rename {src => li.strolch.testbase/src}/main/java/li/strolch/testbase/runtime/RuntimeMock.java (100%) diff --git a/.gitignore b/li.strolch.testbase/.gitignore similarity index 100% rename from .gitignore rename to li.strolch.testbase/.gitignore diff --git a/LICENSE b/li.strolch.testbase/LICENSE similarity index 100% rename from LICENSE rename to li.strolch.testbase/LICENSE diff --git a/README.md b/li.strolch.testbase/README.md similarity index 100% rename from README.md rename to li.strolch.testbase/README.md diff --git a/pom.xml b/li.strolch.testbase/pom.xml similarity index 100% rename from pom.xml rename to li.strolch.testbase/pom.xml diff --git a/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java similarity index 100% rename from src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java rename to li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/AbstractModelTest.java diff --git a/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java similarity index 100% rename from src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java rename to li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/AuditModelTestRunner.java diff --git a/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java similarity index 100% rename from src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java rename to li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/OrderModelTestRunner.java diff --git a/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java similarity index 100% rename from src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java rename to li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/ResourceModelTestRunner.java diff --git a/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java b/li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java similarity index 100% rename from src/main/java/li/strolch/testbase/runtime/RuntimeMock.java rename to li.strolch.testbase/src/main/java/li/strolch/testbase/runtime/RuntimeMock.java