2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.core
.test
.tree
;
19 import java
.util
.List
;
20 import java
.util
.Vector
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.slc
.core
.structure
.SimpleSElement
;
25 import org
.argeo
.slc
.core
.structure
.tree
.TreeSPath
;
26 import org
.argeo
.slc
.structure
.StructureAware
;
27 import org
.argeo
.slc
.structure
.StructureElement
;
28 import org
.argeo
.slc
.structure
.StructureElementProvider
;
29 import org
.argeo
.slc
.structure
.StructureRegistry
;
30 import org
.argeo
.slc
.test
.TestDefinition
;
31 import org
.argeo
.slc
.test
.TestResult
;
32 import org
.argeo
.slc
.test
.TestRun
;
35 * Collection of test definitions propagating tree structure information to its
38 public class CompositeTreeTestDefinition
implements TestDefinition
,
39 StructureAware
<TreeSPath
> {
40 private Log log
= LogFactory
.getLog(CompositeTreeTestDefinition
.class);
42 private List
<TestDefinition
> tasks
= null;
43 private List
<TreeSPath
> taskPaths
= null;
44 private TreeSPath path
;
45 private StructureRegistry
<TreeSPath
> registry
;
47 @SuppressWarnings("unchecked")
48 public void execute(TestRun testRun
) {
49 if (log
.isTraceEnabled())
50 log
.trace("Execute sequence of test definitions...");
53 for (TestDefinition task
: tasks
) {
54 TestResult result
= testRun
.getTestResult();
55 if (result
instanceof StructureAware
) {
56 ((StructureAware
) result
).notifyCurrentPath(registry
, taskPaths
60 task
.execute(testRun
);
62 // Reset current path in case it has been changed
63 if (result
instanceof StructureAware
) {
64 ((StructureAware
) result
).notifyCurrentPath(registry
, path
);
70 /** Sets the list of children test definitions */
71 public void setTasks(List
<TestDefinition
> tasks
) {
74 taskPaths
= new Vector
<TreeSPath
>();
78 @SuppressWarnings("unchecked")
79 public void notifyCurrentPath(StructureRegistry
<TreeSPath
> registry
,
82 this.registry
= registry
;
88 for (TestDefinition task
: tasks
) {
89 final StructureElement element
;
90 if (task
instanceof StructureElementProvider
) {
91 element
= ((StructureElementProvider
) task
)
92 .createStructureElement();
94 element
= new SimpleSElement("[no desc]");
96 TreeSPath taskPath
= this.path
.createChild(count
.toString());
97 registry
.register(taskPath
, element
);
98 taskPaths
.add(taskPath
);
99 if (task
instanceof StructureAware
) {
100 ((StructureAware
<TreeSPath
>) task
).notifyCurrentPath(registry
,