]> 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
Make default execution ressources temp dir dependent of the JVM OS user, in order...
[gpl/argeo-slc.git] / runtime / org.argeo.slc.core / src / main / java / org / argeo / slc / core / test / tree / CompositeTreeTestDefinition.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.core.test.tree;
17
18 import java.util.List;
19 import java.util.Vector;
20
21 import org.apache.commons.logging.Log;
22 import org.apache.commons.logging.LogFactory;
23 import org.argeo.slc.core.structure.SimpleSElement;
24 import org.argeo.slc.core.structure.tree.TreeSPath;
25 import org.argeo.slc.structure.StructureAware;
26 import org.argeo.slc.structure.StructureElement;
27 import org.argeo.slc.structure.StructureElementProvider;
28 import org.argeo.slc.structure.StructureRegistry;
29 import org.argeo.slc.test.TestDefinition;
30 import org.argeo.slc.test.TestResult;
31 import org.argeo.slc.test.TestRun;
32
33 /**
34 * Collection of test definitions propagating tree structure information to its
35 * children.
36 */
37 public class CompositeTreeTestDefinition implements TestDefinition,
38 StructureAware<TreeSPath> {
39 private Log log = LogFactory.getLog(CompositeTreeTestDefinition.class);
40
41 private List<TestDefinition> tasks = null;
42 private List<TreeSPath> taskPaths = null;
43 private TreeSPath path;
44 private StructureRegistry<TreeSPath> registry;
45
46 @SuppressWarnings({ "unchecked", "rawtypes" })
47 public void execute(TestRun testRun) {
48 if (log.isTraceEnabled())
49 log.trace("Execute sequence of test definitions...");
50
51 int i = 0;
52 for (TestDefinition task : tasks) {
53 TestResult result = testRun.getTestResult();
54 if (result instanceof StructureAware) {
55 ((StructureAware) result).notifyCurrentPath(registry,
56 taskPaths.get(i));
57 }
58
59 task.execute(testRun);
60
61 // Reset current path in case it has been changed
62 if (result instanceof StructureAware) {
63 ((StructureAware) result).notifyCurrentPath(registry, path);
64 }
65 i++;
66 }
67 }
68
69 /** Sets the list of children test definitions */
70 public void setTasks(List<TestDefinition> tasks) {
71 this.tasks = tasks;
72 if (tasks != null) {
73 taskPaths = new Vector<TreeSPath>();
74 }
75 }
76
77 @SuppressWarnings("unchecked")
78 public void notifyCurrentPath(StructureRegistry<TreeSPath> registry,
79 TreeSPath path) {
80 this.path = path;
81 this.registry = registry;
82
83 // clear task paths
84 taskPaths.clear();
85
86 Integer count = 0;
87 for (TestDefinition task : tasks) {
88 final StructureElement element;
89 if (task instanceof StructureElementProvider) {
90 element = ((StructureElementProvider) task)
91 .createStructureElement();
92 } else {
93 element = new SimpleSElement("[no desc]");
94 }
95 TreeSPath taskPath = this.path.createChild(count.toString());
96 registry.register(taskPath, element);
97 taskPaths.add(taskPath);
98 if (task instanceof StructureAware) {
99 ((StructureAware<TreeSPath>) task).notifyCurrentPath(registry,
100 taskPath);
101 }
102 count++;
103 }
104 }
105
106 }