]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java
Various changes
[gpl/argeo-slc.git] / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / CompositeTreeTestDefinition.java
1 package org.argeo.slc.core.test.tree;
2
3 import java.util.List;
4 import java.util.Vector;
5
6 import org.apache.commons.logging.Log;
7 import org.apache.commons.logging.LogFactory;
8
9 import org.argeo.slc.core.structure.SimpleSElement;
10 import org.argeo.slc.core.structure.StructureAware;
11 import org.argeo.slc.core.structure.StructureElement;
12 import org.argeo.slc.core.structure.StructurePath;
13 import org.argeo.slc.core.structure.StructureRegistry;
14 import org.argeo.slc.core.structure.tree.TreeSPath;
15 import org.argeo.slc.core.test.TestDefinition;
16 import org.argeo.slc.core.test.TestResult;
17 import org.argeo.slc.core.test.TestRun;
18
19 /**
20 * Collection of test definitions propagating tree structure information to its
21 * children.
22 */
23 public class CompositeTreeTestDefinition implements TestDefinition,
24 StructureAware {
25 private Log log = LogFactory.getLog(CompositeTreeTestDefinition.class);
26
27 private List<TestDefinition> tasks = null;
28 private List<TreeSPath> taskPaths = null;
29 private TreeSPath path;
30 private StructureRegistry registry;
31
32 public void execute(TestRun testRun) {
33 log.info("Execute sequence of test definitions...");
34
35 int i = 0;
36 for (TestDefinition task : tasks) {
37 TestResult result = testRun.getTestResult();
38 if (result instanceof StructureAware) {
39 ((StructureAware) result).notifyCurrentPath(registry, taskPaths
40 .get(i));
41 }
42
43 task.execute(testRun);
44
45 // Reset current path in case it has been changed
46 if (result instanceof StructureAware) {
47 ((StructureAware) result).notifyCurrentPath(registry, path);
48 }
49 i++;
50 }
51 }
52
53 /** Sets the list of children test definitions */
54 public void setTasks(List<TestDefinition> tasks) {
55 this.tasks = tasks;
56 if (tasks != null) {
57 taskPaths = new Vector<TreeSPath>();
58 }
59 }
60
61 public void notifyCurrentPath(StructureRegistry registry, StructurePath path) {
62 this.path = (TreeSPath) path;
63 this.registry = registry;
64
65 // clear task paths
66 taskPaths.clear();
67
68 Integer count = 0;
69 for (TestDefinition task : tasks) {
70 final StructureElement element;
71 if (task instanceof StructureElement) {
72 element = (StructureElement) task;
73 } else {
74 element = new SimpleSElement("[no desc]");
75 }
76 TreeSPath taskPath = this.path.createChild(count.toString());
77 registry.register(taskPath, element);
78 taskPaths.add(taskPath);
79 if (task instanceof StructureAware) {
80 ((StructureAware) task).notifyCurrentPath(registry, taskPath);
81 }
82 count++;
83 }
84 }
85
86 }