From: Mathieu Baudier Date: Tue, 30 Oct 2007 17:40:26 +0000 (+0000) Subject: Introduce complex tree test definition X-Git-Tag: argeo-slc-2.1.7~3188 X-Git-Url: http://git.argeo.org/?a=commitdiff_plain;h=29dd4087314b2f5fa541d13b9723c47b40e14700;p=gpl%2Fargeo-slc.git Introduce complex tree test definition git-svn-id: https://svn.argeo.org/slc/trunk@675 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- diff --git a/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java new file mode 100644 index 000000000..1fc65ab57 --- /dev/null +++ b/org.argeo.slc/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java @@ -0,0 +1,79 @@ +package org.argeo.slc.core.test.tree; + +import java.util.List; +import java.util.Vector; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.argeo.slc.core.structure.SimpleSElement; +import org.argeo.slc.core.structure.StructureAware; +import org.argeo.slc.core.structure.StructureElement; +import org.argeo.slc.core.structure.StructurePath; +import org.argeo.slc.core.structure.StructureRegistry; +import org.argeo.slc.core.structure.tree.TreeSPath; +import org.argeo.slc.core.test.TestDefinition; +import org.argeo.slc.core.test.TestResult; +import org.argeo.slc.core.test.TestRun; + +public class CompositeTreeTestDefinition implements TestDefinition, + StructureAware { + private Log log = LogFactory.getLog(CompositeTreeTestDefinition.class); + + private List tasks = null; + private List taskPaths = null; + private TreeSPath path; + + public void execute(TestRun testRun) { + log.info("Execute sequence of test definitions..."); + + int i = 0; + for (TestDefinition task : tasks) { + TestResult result = testRun.getTestResult(); + if (result instanceof StructureAware) { + ((StructureAware) result).notifyCurrentPath(null, taskPaths + .get(i)); + } + + task.execute(testRun); + + // Reset current path in case it has been changed + if (result instanceof StructureAware) { + ((StructureAware) result).notifyCurrentPath(null, path); + } + i++; + } + } + + public void setTasks(List tasks) { + this.tasks = tasks; + if (tasks != null) { + taskPaths = new Vector(); + } + } + + public void notifyCurrentPath(StructureRegistry registry, StructurePath path) { + this.path = (TreeSPath) path; + + // clear task paths + taskPaths.clear(); + + Integer count = 0; + for (TestDefinition task : tasks) { + final StructureElement element; + if (task instanceof StructureElement) { + element = (StructureElement) task; + } else { + element = new SimpleSElement(""); + } + TreeSPath taskPath = this.path.createChild(count.toString()); + registry.register(taskPath, element); + taskPaths.add(taskPath); + if (task instanceof StructureAware) { + ((StructureAware) task).notifyCurrentPath(registry, taskPath); + } + count++; + } + } + +} diff --git a/org.argeo.slc/src/test/java/org/argeo/slc/example/ComplexExampleTestDef.java b/org.argeo.slc/src/test/java/org/argeo/slc/example/ComplexExampleTestDef.java deleted file mode 100644 index 2de24caae..000000000 --- a/org.argeo.slc/src/test/java/org/argeo/slc/example/ComplexExampleTestDef.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.argeo.slc.example; - -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import org.argeo.slc.core.structure.SimpleSElement; -import org.argeo.slc.core.structure.StructureAware; -import org.argeo.slc.core.structure.StructurePath; -import org.argeo.slc.core.structure.StructureRegistry; -import org.argeo.slc.core.structure.tree.TreeSPath; -import org.argeo.slc.core.test.TestDefinition; -import org.argeo.slc.core.test.TestResult; -import org.argeo.slc.core.test.TestRun; - -public class ComplexExampleTestDef implements TestDefinition, StructureAware { - private Log log = LogFactory.getLog(ComplexExampleTestDef.class); - - private List tasks; - private TreeSPath path; - - public void execute(TestRun testRun) { - log.info("Execute sequence of test definitions..."); - - for (TestDefinition task : tasks) { - task.execute(testRun); - - // Reset current path in case it has been changed - TestResult result = testRun.getTestResult(); - if (result instanceof StructureAware) { - ((StructureAware) result).notifyCurrentPath(null, path); - } - - } - } - - public void setTasks(List tasks) { - this.tasks = tasks; - } - - public void notifyCurrentPath(StructureRegistry registry, StructurePath path) { - this.path = (TreeSPath) path; - - Integer count = 0; - for (TestDefinition task : tasks) { - String description = ""; - if (task instanceof ExampleTask) { - description = ((ExampleTask) task).getDescription(); - } - SimpleSElement element = new SimpleSElement(description); - TreeSPath taskPath = this.path.createChild(count.toString()); - registry.register(taskPath, element); - if (task instanceof StructureAware) { - ((StructureAware) task).notifyCurrentPath(registry, taskPath); - } - count++; - } - } - -} diff --git a/org.argeo.slc/src/test/java/org/argeo/slc/example/ExampleTask.java b/org.argeo.slc/src/test/java/org/argeo/slc/example/ExampleTask.java index 7e8b61733..c709f259c 100644 --- a/org.argeo.slc/src/test/java/org/argeo/slc/example/ExampleTask.java +++ b/org.argeo.slc/src/test/java/org/argeo/slc/example/ExampleTask.java @@ -1,6 +1,7 @@ package org.argeo.slc.example; import org.argeo.slc.core.structure.StructureAware; +import org.argeo.slc.core.structure.StructureElement; import org.argeo.slc.core.structure.StructurePath; import org.argeo.slc.core.structure.StructureRegistry; import org.argeo.slc.core.structure.tree.TreeSPath; @@ -9,24 +10,22 @@ import org.argeo.slc.core.test.TestDefinition; import org.argeo.slc.core.test.TestResult; import org.argeo.slc.core.test.TestRun; -public class ExampleTask implements StructureAware,TestDefinition{ +public class ExampleTask implements StructureAware, TestDefinition, + StructureElement { private TreeSPath path; private String description; - public void execute(TestRun testRun){ + public void execute(TestRun testRun) { SimpleResultPart part = new SimpleResultPart(); part.setStatus(SimpleResultPart.PASSED); - part.setMessage("Sub task executed"); - + part.setMessage("Sub task with path " + path + " executed"); + TestResult result = testRun.getTestResult(); - if(result instanceof StructureAware){ - ((StructureAware)result).notifyCurrentPath(null, path); - } result.addResultPart(part); } public void notifyCurrentPath(StructureRegistry registry, StructurePath path) { - this.path = (TreeSPath)path; + this.path = (TreeSPath) path; } public String getDescription() { @@ -36,6 +35,5 @@ public class ExampleTask implements StructureAware,TestDefinition{ public void setDescription(String description) { this.description = description; } - - + } diff --git a/org.argeo.slc/src/test/slc/conf/data.xml b/org.argeo.slc/src/test/slc/conf/data.xml index 428709133..e6cea56e8 100644 --- a/org.argeo.slc/src/test/slc/conf/data.xml +++ b/org.argeo.slc/src/test/slc/conf/data.xml @@ -50,12 +50,4 @@ class="org.argeo.slc.hibernate.test.tree.TestResultDaoHibernate"> - - - - - - - \ No newline at end of file diff --git a/org.argeo.slc/src/test/slc/conf/slc.xml b/org.argeo.slc/src/test/slc/conf/slc.xml index 4b13480f4..b06544d37 100644 --- a/org.argeo.slc/src/test/slc/conf/slc.xml +++ b/org.argeo.slc/src/test/slc/conf/slc.xml @@ -9,8 +9,8 @@ - + - + class="org.argeo.slc.core.test.tree.TreeTestResultPersister" + init-method="init" destroy-method="destroy"> + + + + + +