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