* 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
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
this.label = label;\r
}\r
\r
- Long getTid() {\r
+ public Long getTid() {\r
return tid;\r
}\r
\r
\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
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
* 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
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
\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
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
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
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
/** 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
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
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
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
}\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
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
}\r
}\r
\r
- }\r
+ }*/\r
}\r
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
\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
* \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
public void update(TestResult testResult);\r
\r
/** Lists all test results. */\r
- public List<TestResult> listTestResults();\r
+ public List<T> listTestResults();\r
}\r
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
}\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
\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
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
\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
}\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
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
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
--- /dev/null
+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
* 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
+++ /dev/null
-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
<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
\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
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
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