2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.core
.test
.tree
;
18 import java
.util
.List
;
19 import java
.util
.Vector
;
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
;
34 * Collection of test definitions propagating tree structure information to its
37 public class CompositeTreeTestDefinition
implements TestDefinition
,
38 StructureAware
<TreeSPath
> {
39 private Log log
= LogFactory
.getLog(CompositeTreeTestDefinition
.class);
41 private List
<TestDefinition
> tasks
= null;
42 private List
<TreeSPath
> taskPaths
= null;
43 private TreeSPath path
;
44 private StructureRegistry
<TreeSPath
> registry
;
46 @SuppressWarnings({ "unchecked", "rawtypes" })
47 public void execute(TestRun testRun
) {
48 if (log
.isTraceEnabled())
49 log
.trace("Execute sequence of test definitions...");
52 for (TestDefinition task
: tasks
) {
53 TestResult result
= testRun
.getTestResult();
54 if (result
instanceof StructureAware
) {
55 ((StructureAware
) result
).notifyCurrentPath(registry
,
59 task
.execute(testRun
);
61 // Reset current path in case it has been changed
62 if (result
instanceof StructureAware
) {
63 ((StructureAware
) result
).notifyCurrentPath(registry
, path
);
69 /** Sets the list of children test definitions */
70 public void setTasks(List
<TestDefinition
> tasks
) {
73 taskPaths
= new Vector
<TreeSPath
>();
77 @SuppressWarnings("unchecked")
78 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
81 this.registry
= registry
;
87 for (TestDefinition task
: tasks
) {
88 final StructureElement element
;
89 if (task
instanceof StructureElementProvider
) {
90 element
= ((StructureElementProvider
) task
)
91 .createStructureElement();
93 element
= new SimpleSElement("[no desc]");
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
,