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