]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.core/src/main/java/org/argeo/slc/core/test/tree/CompositeTreeTestDefinition.java
First working GPS position provider
[gpl/argeo-slc.git] / runtime / 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.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 @SuppressWarnings("unchecked")
32 public void execute(TestRun testRun) {
33 if (log.isTraceEnabled())
34 log.trace("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 @SuppressWarnings("unchecked")
63 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
64 TreeSPath path) {
65 this.path = path;
66 this.registry = registry;
67
68 // clear task paths
69 taskPaths.clear();
70
71 Integer count = 0;
72 for (TestDefinition task : tasks) {
73 final StructureElement element;
74 if (task instanceof StructureElementProvider) {
75 element = ((StructureElementProvider) task)
76 .createStructureElement();
77 } else {
78 element = new SimpleSElement("[no desc]");
79 }
80 TreeSPath taskPath = this.path.createChild(count.toString());
81 registry.register(taskPath, element);
82 taskPaths.add(taskPath);
83 if (task instanceof StructureAware) {
84 ((StructureAware<TreeSPath>) task).notifyCurrentPath(registry,
85 taskPath);
86 }
87 count++;
88 }
89 }
90
91 }