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