]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java
Make tree test results serializable so that it can be used with ObjectList.
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.simple / 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.tree.TreeSPath;
10 import org.argeo.slc.structure.StructureAware;
11 import org.argeo.slc.structure.StructureElement;
12 import org.argeo.slc.structure.StructureElementProvider;
13 import org.argeo.slc.structure.StructureRegistry;
14 import org.argeo.slc.test.TestDefinition;
15 import org.argeo.slc.test.TestResult;
16 import org.argeo.slc.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 if (log.isTraceEnabled())
33 log.trace("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<TreeSPath> registry,
62 TreeSPath path) {
63 this.path = path;
64 this.registry = registry;
65
66 // clear task paths
67 taskPaths.clear();
68
69 Integer count = 0;
70 for (TestDefinition task : tasks) {
71 final StructureElement element;
72 if (task instanceof StructureElementProvider) {
73 element = ((StructureElementProvider) task)
74 .createStructureElement();
75 } else {
76 element = new SimpleSElement("[no desc]");
77 }
78 TreeSPath taskPath = this.path.createChild(count.toString());
79 registry.register(taskPath, element);
80 taskPaths.add(taskPath);
81 if (task instanceof StructureAware) {
82 ((StructureAware<TreeSPath>) task).notifyCurrentPath(registry,
83 taskPath);
84 }
85 count++;
86 }
87 }
88
89 }