Improvement in casting
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 20 Dec 2007 21:16:39 +0000 (21:16 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 20 Dec 2007 21:16:39 +0000 (21:16 +0000)
Syncpath in DAO

git-svn-id: https://svn.argeo.org/slc/trunk@893 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

21 files changed:
org.argeo.slc.core/src/main/java/org/argeo/slc/core/UnsupportedException.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/DefaultSRegistry.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/SimpleSElement.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/StructureRegistry.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/structure/tree/TreeSRegistry.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/SimpleTestRun.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/TestRun.java
org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/TreeTestResultPersister.java
org.argeo.slc.core/src/main/java/org/argeo/slc/dao/structure/tree/TreeSRegistryDao.java
org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/TestResultDao.java
org.argeo.slc.core/src/main/java/org/argeo/slc/dao/test/tree/TreeTestResultDao.java
org.argeo.slc.core/src/main/java/org/argeo/slc/hibernate/structure/tree/TreeSPathDaoHibernate.java
org.argeo.slc.core/src/main/java/org/argeo/slc/hibernate/structure/tree/TreeSRegistryDaoHibernate.java
org.argeo.slc.core/src/main/java/org/argeo/slc/hibernate/test/tree/TestResultDaoHibernate.java
org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java [new file with mode: 0644]
org.argeo.slc.core/src/main/java/org/argeo/slc/unit/IndependentDbTestCase.java
org.argeo.slc.core/src/main/java/org/argeo/slc/unit/SpringBasedTestCase.java [deleted file]
org.argeo.slc.core/src/main/resources/org/argeo/slc/hibernate/structure/tree/TreeSRegistry.hbm.xml
org.argeo.slc.core/src/test/java/org/argeo/slc/hibernate/structure/tree/TreeSPathDaoHibernateTest.java
org.argeo.slc.core/src/test/java/org/argeo/slc/hibernate/structure/tree/TreeSRegistryDaoHibernateTest.java
org.argeo.slc.core/src/test/java/org/argeo/slc/hibernate/test/tree/TreeTestResultDaoHibernateTest.java

index 76f6565d2870306a96dcd9b5e317d6fc036a290a..5c786566fb1c358afc1d6664aa7e822e140dd5aa 100644 (file)
@@ -23,7 +23,8 @@ public class UnsupportedException extends SlcException {
         *            the object itself (its class name will be used in message)\r
         */\r
        public UnsupportedException(String nature, Object obj) {\r
-               super("Unsupported " + nature + ": " + obj.getClass());\r
+               super("Unsupported " + nature + ": "\r
+                               + (obj != null ? obj.getClass() : "[object is null]"));\r
        }\r
 \r
        /**\r
index f88b604dda6510d3a232197e867feb79ddf1bec7..a529f1bac5f1eb1c51db73799d75473e00c36d84 100644 (file)
@@ -7,7 +7,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;\r
 \r
 /** Default implementation of a <code>StructureRegistry</code>. */\r
-public class DefaultSRegistry implements StructureRegistry {\r
+public class DefaultSRegistry implements StructureRegistry<StructurePath> {\r
        private static Log log = LogFactory.getLog(DefaultSRegistry.class);\r
 \r
        private List<StructureElement> elements = new Vector<StructureElement>();\r
index 4b50d9c22c7a0a4b3b4b7f880f240d48cec0d778..98bf7e319531139589e570f88e87466fad594e42 100644 (file)
@@ -34,7 +34,7 @@ public class SimpleSElement implements StructureElement {
                this.label = label;\r
        }\r
 \r
-       Long getTid() {\r
+       public Long getTid() {\r
                return tid;\r
        }\r
 \r
index ed0fa592394a15d230947ea9d34742899d84689c..71f80cb772f7018fd2c7d0ed32e4f18659c51af4 100644 (file)
@@ -2,8 +2,10 @@ package org.argeo.slc.core.structure;
 \r
 import java.util.List;\r
 \r
+import org.argeo.slc.core.deploy.DeployedSystem;\r
+\r
 /** Registry where the whole structure is stored. */\r
-public interface StructureRegistry {\r
+public interface StructureRegistry<P extends StructurePath> {\r
        /** Read mode: the structure is only read. */\r
        public static String READ = "READ";\r
        /** All mode: everything is executed regardless of the active paths. */\r
@@ -12,16 +14,16 @@ public interface StructureRegistry {
        public static String ACTIVE = "STATUS_ACTIVE";\r
 \r
        /** Adds an element to the registry. */\r
-       public void register(StructurePath path, StructureElement element);\r
+       public void register(P path, StructureElement element);\r
 \r
        /** Lists <b>all</b> registered elements. */\r
        public List<StructureElement> listElements();\r
 \r
        /** Lists <b>all</b> registered elements. */\r
-       public List<StructurePath> listPaths();\r
+       public List<P> listPaths();\r
 \r
        /** Gets a element based on its path. */\r
-       public StructureElement getElement(StructurePath path);\r
+       public <T extends StructureElement> T getElement(P path);\r
 \r
        /**\r
         * Set the interpreter mode: read, all or active.\r
@@ -45,11 +47,11 @@ public interface StructureRegistry {
         * Gets the list of active paths, which will be run if executed in\r
         * <code>STATUS_ACTIVE</code> mode.\r
         */\r
-       public List<StructurePath> getActivePaths();\r
+       public List<P> getActivePaths();\r
 \r
        /**\r
         * Sets the list of active path, which will be run if executed in\r
         * <code>STATUS_ACTIVE</code> mode.\r
         */\r
-       public void setActivePaths(List<StructurePath> activePaths);\r
+       public void setActivePaths(List<P> activePaths);\r
 }\r
index e38f31e9d3337595006b2b169bdf42632fa33278..10125678c4fb5181a402dc0e210247eae192e80a 100644 (file)
@@ -8,13 +8,12 @@ import java.util.Vector;
 import org.argeo.slc.core.UnsupportedException;\r
 import org.argeo.slc.core.structure.SimpleSElement;\r
 import org.argeo.slc.core.structure.StructureElement;\r
-import org.argeo.slc.core.structure.StructurePath;\r
 import org.argeo.slc.core.structure.StructureRegistry;\r
 \r
 /** Tree based implementation of a structure registry. */\r
-public class TreeSRegistry implements StructureRegistry {\r
+public class TreeSRegistry implements StructureRegistry<TreeSPath> {\r
        public final static String STATUS_ACTIVE = "STATUS_ACTIVE";\r
-       \r
+\r
        /** For ORM */\r
        private Long tid;\r
        private String status;\r
@@ -22,21 +21,21 @@ public class TreeSRegistry implements StructureRegistry {
 \r
        private String mode = StructureRegistry.ALL;\r
 \r
-       private List<StructurePath> activePaths;\r
+       private List<TreeSPath> activePaths;\r
 \r
-       public StructureElement getElement(StructurePath path) {\r
-               return elements.get(path);\r
+       public <T extends StructureElement> T getElement(TreeSPath path) {\r
+               return (T)elements.get(path);\r
        }\r
 \r
        public List<StructureElement> listElements() {\r
                return new Vector<StructureElement>(elements.values());\r
        }\r
 \r
-       public List<StructurePath> listPaths() {\r
-               return new Vector<StructurePath>(elements.keySet());\r
+       public List<TreeSPath> listPaths() {\r
+               return new Vector<TreeSPath>(elements.keySet());\r
        }\r
 \r
-       public void register(StructurePath path, StructureElement element) {\r
+       public void register(TreeSPath path, StructureElement element) {\r
                final SimpleSElement simpleSElement;\r
                if (element instanceof SimpleSElement) {\r
                        simpleSElement = (SimpleSElement) element;\r
@@ -44,10 +43,10 @@ public class TreeSRegistry implements StructureRegistry {
                        simpleSElement = new SimpleSElement(element.getLabel());\r
                }\r
 \r
-               if (!(path instanceof TreeSPath))\r
-                       throw new UnsupportedException("path", path);\r
+               if (path == null)\r
+                       throw new UnsupportedException("Path cannot be null.");\r
 \r
-               elements.put((TreeSPath) path, simpleSElement);\r
+               elements.put(path, simpleSElement);\r
 \r
        }\r
 \r
@@ -59,15 +58,14 @@ public class TreeSRegistry implements StructureRegistry {
                this.mode = mode;\r
        }\r
 \r
-       public List<StructurePath> getActivePaths() {\r
+       public List<TreeSPath> getActivePaths() {\r
                return activePaths;\r
        }\r
 \r
-       public void setActivePaths(List<StructurePath> activePaths) {\r
+       public void setActivePaths(List<TreeSPath> activePaths) {\r
                this.activePaths = activePaths;\r
        }\r
 \r
-\r
        public String getStatus() {\r
                return status;\r
        }\r
index c548f9d593357c83227b027438f17aebb02518d7..684142e96e2c1368112d384e2e0700d5d16f2bcd 100644 (file)
@@ -17,32 +17,32 @@ public class SimpleTestRun implements WritableTestRun, ExecutableTestRun {
                testDefinition.execute(this);\r
        }\r
 \r
-       public DeployedSystem getDeployedSystem() {\r
-               return deployedSystem;\r
+       public <T extends DeployedSystem> T getDeployedSystem() {\r
+               return (T)deployedSystem;\r
        }\r
 \r
        public void setDeployedSystem(DeployedSystem deployedSystem) {\r
                this.deployedSystem = deployedSystem;\r
        }\r
 \r
-       public TestData getTestData() {\r
-               return testData;\r
+       public <T extends TestData> T getTestData() {\r
+               return (T)testData;\r
        }\r
 \r
        public void setTestData(TestData testData) {\r
                this.testData = testData;\r
        }\r
 \r
-       public TestDefinition getTestDefinition() {\r
-               return testDefinition;\r
+       public <T extends TestDefinition> T getTestDefinition() {\r
+               return (T)testDefinition;\r
        }\r
 \r
        public void setTestDefinition(TestDefinition testDefinition) {\r
                this.testDefinition = testDefinition;\r
        }\r
 \r
-       public TestResult getTestResult() {\r
-               return testResult;\r
+       public <T extends TestResult> T getTestResult() {\r
+               return (T)testResult;\r
        }\r
 \r
        public void setTestResult(TestResult testResult) {\r
index 073acb5b2023dd3f3cdd60c37cd5aec314eb17fd..9991e20c3bf65289a197ee9f67bf45de95a99bf8 100644 (file)
@@ -5,14 +5,14 @@ import org.argeo.slc.core.deploy.DeployedSystem;
 /** The actual run of a test */\r
 public interface TestRun {\r
        /** Gets the related test definition. */\r
-       public TestDefinition getTestDefinition();\r
+       public <T extends TestDefinition> T getTestDefinition();\r
 \r
        /** Gets the related test data */\r
-       public TestData getTestData();\r
+       public <T extends TestData> T getTestData();\r
 \r
        /** Gets the related deployed system. */\r
-       public DeployedSystem getDeployedSystem();\r
+       public <T extends DeployedSystem> T getDeployedSystem();\r
 \r
        /** Gets the related result where to record results. */\r
-       public TestResult getTestResult();\r
+       public <T extends TestResult> T getTestResult();\r
 }\r
index 10ce948b47ed9319c9635e8f3bc5d9d561b626e5..164c540b8b1251bd8095aa346024e3c41c925803 100644 (file)
@@ -11,6 +11,7 @@ import org.argeo.slc.core.structure.tree.TreeSRegistry;
 import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
 import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
 import org.argeo.slc.dao.test.TestResultDao;\r
+import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
 \r
 /**\r
  * Listener persisting tree-based results.\r
@@ -20,21 +21,22 @@ import org.argeo.slc.dao.test.TestResultDao;
 public class TreeTestResultPersister extends AsynchronousTreeTestResultListener {\r
        private static Log log = LogFactory.getLog(TreeTestResultPersister.class);\r
 \r
-       private TestResultDao testResultDao;\r
+       private TreeTestResultDao testResultDao;\r
        private TreeSPathDao treeSPathDao;\r
        private TreeSRegistryDao treeSRegistryDao;\r
 \r
        @Override\r
        protected void resultPartAdded(PartStruct partStruct) {\r
                try {\r
-                       TreeTestResult persistedResult = (TreeTestResult) testResultDao\r
+                       TreeTestResult persistedResult = testResultDao\r
                                        .getTestResult(partStruct.resultId);\r
 \r
                        TreeSPath path = treeSPathDao.getOrCreate(partStruct.path);\r
 \r
-                       StructureRegistry localRegistry = partStruct.result.getRegistry();\r
+                       StructureRegistry<TreeSPath> localRegistry = partStruct.result\r
+                                       .getRegistry();\r
                        TreeSRegistry registry = getOrCreateTreeSRegistry(path);\r
-                       syncPath(registry, localRegistry, path);\r
+                       treeSRegistryDao.syncPath(registry, localRegistry, path);\r
 \r
                        if (persistedResult == null) {\r
                                persistedResult = new TreeTestResult();\r
@@ -87,7 +89,6 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                TreeSRegistry registry = treeSRegistryDao.getActiveTreeSRegistry();\r
                if (registry == null) {\r
                        registry = new TreeSRegistry();\r
-                       TreeSPath root = treeSPathDao.getOrCreate(path.getRoot());\r
                        registry.setStatus(TreeSRegistry.STATUS_ACTIVE);\r
                        treeSRegistryDao.create(registry);\r
                        return treeSRegistryDao.getActiveTreeSRegistry();\r
@@ -97,7 +98,7 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
        }\r
 \r
        /** Sets the DAO to use in order to persist the results. */\r
-       public void setTestResultDao(TestResultDao testResultDao) {\r
+       public void setTestResultDao(TreeTestResultDao testResultDao) {\r
                this.testResultDao = testResultDao;\r
        }\r
 \r
@@ -110,9 +111,9 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
        public void setTreeSRegistryDao(TreeSRegistryDao treeSRegistryDao) {\r
                this.treeSRegistryDao = treeSRegistryDao;\r
        }\r
-\r
+/*\r
        private void syncPath(TreeSRegistry registry,\r
-                       StructureRegistry localRegistry, TreeSPath path) {\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path) {\r
                if (path.getParent() != null) {\r
                        TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
                        syncPath(registry, localRegistry, parent);\r
@@ -135,5 +136,5 @@ public class TreeTestResultPersister extends AsynchronousTreeTestResultListener
                        }\r
                }\r
 \r
-       }\r
+       }*/\r
 }\r
index aee0bc27da81a5f0c0fc3698cb42418bfb1209cf..f271f8cbe56b8c2f6295e17b31f550bcd9e808ab 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.slc.dao.structure.tree;\r
 \r
+import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
 \r
@@ -17,4 +18,8 @@ public interface TreeSRegistryDao {
 \r
        /** Updates an existing registry. */\r
        public void update(TreeSRegistry registry);\r
+       \r
+       /** Sync with local registry */\r
+       public void syncPath(TreeSRegistry registry,\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path);\r
 }\r
index f64cfe769aacaea56bee5ef601d56df7acb1a455..3c8033050cfcb8d84a59a0ddff40078769b9f046 100644 (file)
@@ -10,9 +10,9 @@ import org.argeo.slc.core.test.TestResultId;
  * \r
  * @see TestResult\r
  */\r
-public interface TestResultDao {\r
+public interface TestResultDao<T extends TestResult> {\r
        /** Gets a test result based on its id. */\r
-       public TestResult getTestResult(TestResultId id);\r
+       public T getTestResult(TestResultId id);\r
 \r
        /** Persists a new test result. */\r
        public void create(TestResult testResult);\r
@@ -21,5 +21,5 @@ public interface TestResultDao {
        public void update(TestResult testResult);\r
 \r
        /** Lists all test results. */\r
-       public List<TestResult> listTestResults();\r
+       public List<T> listTestResults();\r
 }\r
index 878519cc5b028e335eef26fd9854dcc4c144acc4..5c4a3f879ca1ffec5b93514a843da7ed7f670dba 100644 (file)
@@ -6,7 +6,7 @@ import org.argeo.slc.core.structure.tree.TreeSPath;
 import org.argeo.slc.core.test.tree.TreeTestResult;\r
 import org.argeo.slc.dao.test.TestResultDao;\r
 \r
-public interface TreeTestResultDao extends TestResultDao {\r
+public interface TreeTestResultDao extends TestResultDao<TreeTestResult> {\r
        /** Lists results containing this path*/\r
        public List<TreeTestResult> listResults(TreeSPath path);\r
 }\r
index e20e3deb3c33e2d29b851e34710f8377bcf2b8d5..1e120632c042833e6f3c72b9d4fb8fc1965976a8 100644 (file)
@@ -38,8 +38,6 @@ public class TreeSPathDaoHibernate extends HibernateDaoSupport implements
        }\r
 \r
        public TreeSPath getTreeSPath(String pathString) {\r
-               if (log.isTraceEnabled())\r
-                       log.trace("Query path: " + pathString);\r
                List<?> list = getHibernateTemplate().find(\r
                                "from TreeSPath where asUniqueString=?", pathString);\r
                if (list.size() == 0) {\r
index 57d06dd1470972eb5d238719f2a91b7b649726f1..15a7cede53ae186f5e9d475d3bc92b81c09e1cf0 100644 (file)
@@ -4,8 +4,15 @@ import java.util.List;
 \r
 import org.springframework.orm.hibernate3.support.HibernateDaoSupport;\r
 \r
+import org.apache.commons.logging.Log;\r
+import org.apache.commons.logging.LogFactory;\r
+\r
+import org.argeo.slc.core.structure.SimpleSElement;\r
+import org.argeo.slc.core.structure.StructureElement;\r
+import org.argeo.slc.core.structure.StructureRegistry;\r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
+import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
 import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
 \r
 /**\r
@@ -16,8 +23,9 @@ import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;
 public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements\r
                TreeSRegistryDao {\r
 \r
-       // private static Log log =\r
-       // LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
+       private TreeSPathDao treeSPathDao;\r
+\r
+       private static Log log = LogFactory.getLog(TreeSRegistryDaoHibernate.class);\r
 \r
        public void create(TreeSRegistry registry) {\r
                getHibernateTemplate().save(registry);\r
@@ -29,7 +37,8 @@ public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements
 \r
        public TreeSRegistry getActiveTreeSRegistry() {\r
                List<?> list = getHibernateTemplate().find(\r
-                               "from TreeSRegistry where status=?", TreeSRegistry.STATUS_ACTIVE);\r
+                               "from TreeSRegistry where status=?",\r
+                               TreeSRegistry.STATUS_ACTIVE);\r
                if (list.size() == 0) {\r
                        return null;\r
                } else {\r
@@ -37,4 +46,41 @@ public class TreeSRegistryDaoHibernate extends HibernateDaoSupport implements
                }\r
        }\r
 \r
+       public void syncPath(TreeSRegistry registry,\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path) {\r
+               if (path.getParent() != null) {\r
+                       TreeSPath parent = treeSPathDao.getOrCreate(path.getParent());\r
+                       syncPath(registry, localRegistry, parent);\r
+               }\r
+\r
+               if (log.isDebugEnabled())\r
+                       log.debug("Synchronize path " + path);\r
+               \r
+               if (registry.getElement(path) == null) {\r
+                       if (localRegistry != null) {\r
+                               registry.register(path, getElement(registry, localRegistry, path));\r
+                       } else {\r
+                               registry.register(path, new SimpleSElement(path.getName()));\r
+                       }\r
+                       update(registry);\r
+               } else {\r
+                       if (localRegistry != null) {\r
+                               StructureElement sElement = getElement(registry, localRegistry, path);\r
+                               if (sElement != null) {\r
+                                       registry.register(path, sElement);\r
+                                       update(registry);\r
+                               }\r
+                       }\r
+               }\r
+\r
+       }\r
+\r
+       public void setTreeSPathDao(TreeSPathDao treeSPathDao) {\r
+               this.treeSPathDao = treeSPathDao;\r
+       }\r
+\r
+       protected StructureElement getElement(TreeSRegistry registry,\r
+                       StructureRegistry<TreeSPath> localRegistry, TreeSPath path){\r
+               return localRegistry.getElement(path);\r
+       }\r
 }\r
index 98df1e6c9033252ada19bb286d726c796542420a..7b7fbf45e4aab9433397731b754a5c9f50ce2a49 100644 (file)
@@ -27,7 +27,7 @@ public class TestResultDaoHibernate extends HibernateDaoSupport implements
                getHibernateTemplate().saveOrUpdate(testResult);\r
        }\r
 \r
-       public TestResult getTestResult(TestResultId id) {\r
+       public TreeTestResult getTestResult(TestResultId id) {\r
                NumericTRId ntrid = (NumericTRId) id;\r
                List<?> list = getHibernateTemplate().find(\r
                                "from TreeTestResult where numericResultId.value=?",\r
@@ -35,13 +35,13 @@ public class TestResultDaoHibernate extends HibernateDaoSupport implements
                if (list.size() == 0) {\r
                        return null;\r
                } else {\r
-                       return (TestResult) list.get(0);\r
+                       return (TreeTestResult) list.get(0);\r
                }\r
 \r
        }\r
 \r
-       public List<TestResult> listTestResults() {\r
-               return (List<TestResult>) getHibernateTemplate().find(\r
+       public List<TreeTestResult> listTestResults() {\r
+               return (List<TreeTestResult>) getHibernateTemplate().find(\r
                                "from TreeTestResult");\r
        }\r
 \r
diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/AbstractSpringTestCase.java
new file mode 100644 (file)
index 0000000..06c6cf6
--- /dev/null
@@ -0,0 +1,47 @@
+package org.argeo.slc.unit;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.springframework.context.ApplicationContext;\r
+import org.springframework.context.support.ClassPathXmlApplicationContext;\r
+\r
+/** Helper for tests using a Spring application co,text. */\r
+public abstract class AbstractSpringTestCase extends TestCase {\r
+       private ApplicationContext context;\r
+\r
+       /**\r
+        * Gets (and create if necessary) the application context to use. Default\r
+        * implementation uses a class path xml application context and calls\r
+        * {@link #getApplicationContextLocation()}.\r
+        */\r
+       protected ApplicationContext getContext() {\r
+               if (context == null) {\r
+                       context = new ClassPathXmlApplicationContext(\r
+                                       getApplicationContextLocation());\r
+               }\r
+               return context;\r
+       }\r
+       \r
+       /** Returns a bean from the underlying context */\r
+       protected <T> T getBean(String beanId){\r
+               return (T)getContext().getBean(beanId);\r
+       }\r
+\r
+       /**\r
+        * Th location of the application to load. The default implementation\r
+        * returns <i>applicationContext.xml</i> found in the same package as the\r
+        * test.\r
+        */\r
+       protected String getApplicationContextLocation() {\r
+               return inPackage("applicationContext.xml");\r
+       }\r
+\r
+       /**\r
+        * Prefixes the package of the class after converting the '.' to '/' in\r
+        * order to have a resource path.\r
+        */\r
+       protected String inPackage(String suffix) {\r
+               String prefix = getClass().getPackage().getName().replace('.', '/');\r
+               return prefix + '/' + suffix;\r
+       }\r
+}\r
index 8a0b07e90cf607e012daa938890d73801a975e17..067ae6cef5ca0b39750a72c25357c468756c0019 100644 (file)
@@ -23,7 +23,7 @@ import org.argeo.slc.core.SlcException;
  * Helper to make db vendor independent tests using DbUnit data sets. Based on\r
  * {@link DbModel}.\r
  */\r
-public abstract class IndependentDbTestCase extends SpringBasedTestCase {\r
+public abstract class IndependentDbTestCase extends AbstractSpringTestCase {\r
        private IDatabaseTester databaseTester;\r
 \r
        /** Creates the DDL of the data model and loads the data. */\r
diff --git a/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/SpringBasedTestCase.java b/org.argeo.slc.core/src/main/java/org/argeo/slc/unit/SpringBasedTestCase.java
deleted file mode 100644 (file)
index 3d6f0c8..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.argeo.slc.unit;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.springframework.context.ApplicationContext;\r
-import org.springframework.context.support.ClassPathXmlApplicationContext;\r
-\r
-/** Helper for tests using a Spring application co,text. */\r
-public abstract class SpringBasedTestCase extends TestCase {\r
-       private ApplicationContext context;\r
-\r
-       /**\r
-        * Gets (and create if necessary) the application context to use. Default\r
-        * implementation uses a class path xml application context and calls\r
-        * {@link #getApplicationContextLocation()}.\r
-        */\r
-       protected ApplicationContext getContext() {\r
-               if (context == null) {\r
-                       context = new ClassPathXmlApplicationContext(\r
-                                       getApplicationContextLocation());\r
-               }\r
-               return context;\r
-       }\r
-\r
-       /**\r
-        * Th location of the application to load. The default implementation\r
-        * returns <i>applicationContext.xml</i> found in the same package as the\r
-        * test.\r
-        */\r
-       protected String getApplicationContextLocation() {\r
-               return inPackage("applicationContext.xml");\r
-       }\r
-\r
-       /**\r
-        * Prefixes the package of the class after converting the '.' to '/' in\r
-        * order to have a resource path.\r
-        */\r
-       protected String inPackage(String suffix) {\r
-               String prefix = getClass().getPackage().getName().replace('.', '/');\r
-               return prefix + '/' + suffix;\r
-       }\r
-}\r
index b931df0335b891ee6b3bebca8d31df536b28f506..2182a230412921a96cb173e0b6f837a55f87dd3e 100644 (file)
@@ -8,8 +8,9 @@
                        <generator class="native" />\r
                </id>\r
 \r
-               <property name="status" column="STATUS" not-null="true"/>\r
-                       \r
+               <property name="status" column="STATUS" not-null="true"\r
+                       unique="true" />\r
+\r
                <map name="elements" table="REGISTRY_ELEMENTS" cascade="all"\r
                        lazy="false" sort="natural">\r
                        <key column="PARENT_ID" />\r
index d383313a1e865ca8b7bae391bcd0cdf4df327c21..28ab1c7bc3bf075846faf6622851345cf9088a80 100644 (file)
@@ -2,9 +2,9 @@ package org.argeo.slc.hibernate.structure.tree;
 \r
 import org.argeo.slc.core.structure.tree.TreeSPath;\r
 import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
-import org.argeo.slc.unit.SpringBasedTestCase;\r
+import org.argeo.slc.unit.AbstractSpringTestCase;\r
 \r
-public class TreeSPathDaoHibernateTest extends SpringBasedTestCase {\r
+public class TreeSPathDaoHibernateTest extends AbstractSpringTestCase {\r
 \r
        public void testCreate() {\r
                TreeSPathDao treeSPathDao = (TreeSPathDao) getContext().getBean(\r
index a066c9b0d43eec9ef6c191abe54e984d750b05e6..1fe66c75ad4dfad2458f004a0f9034e58d8bab22 100644 (file)
@@ -5,9 +5,9 @@ import org.argeo.slc.core.structure.tree.TreeSPath;
 import org.argeo.slc.core.structure.tree.TreeSRegistry;\r
 import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
 import org.argeo.slc.dao.structure.tree.TreeSRegistryDao;\r
-import org.argeo.slc.unit.SpringBasedTestCase;\r
+import org.argeo.slc.unit.AbstractSpringTestCase;\r
 \r
-public class TreeSRegistryDaoHibernateTest extends SpringBasedTestCase {\r
+public class TreeSRegistryDaoHibernateTest extends AbstractSpringTestCase {\r
 \r
        public void testCreate() {\r
                TreeSRegistryDao treeSRegistryDao = (TreeSRegistryDao) getContext()\r
index db528c38ff075c23b807facfe1dd19e737321266..44b9b3fc1bcbf8a04e9d2d4c70bed2ac2be86df7 100644 (file)
@@ -12,9 +12,9 @@ import org.argeo.slc.core.test.tree.TreeTestResult;
 import org.argeo.slc.dao.structure.tree.TreeSPathDao;\r
 import org.argeo.slc.dao.test.TestResultDao;\r
 import org.argeo.slc.dao.test.tree.TreeTestResultDao;\r
-import org.argeo.slc.unit.SpringBasedTestCase;\r
+import org.argeo.slc.unit.AbstractSpringTestCase;\r
 \r
-public class TreeTestResultDaoHibernateTest extends SpringBasedTestCase {\r
+public class TreeTestResultDaoHibernateTest extends AbstractSpringTestCase {\r
 \r
        public void testCreate() {\r
                TreeSPathDao treeSPathDao = (TreeSPathDao) getContext().getBean(\r