01: // Copyright © 2002-2007 Canoo Engineering AG, Switzerland.
02: package com.canoo.webtest.steps;
03:
04: import java.io.Serializable;
05: import java.util.ArrayList;
06: import java.util.Iterator;
07: import java.util.List;
08:
09: import org.apache.log4j.Logger;
10: import org.apache.tools.ant.Task;
11: import org.apache.tools.ant.TaskContainer;
12:
13: import com.canoo.webtest.interfaces.IStepSequence;
14:
15: /**
16: * Common abstract base class for all container steps.<p>
17: * <p/>
18: * This is a container class for a list of AbstractTestSpecificationSteps. It is used for
19: * the <code><steps></code> element in ant build scripts as well as for the
20: * <code><not></code> test step elements.
21: * <p/>
22: * <p>An instance of this class is usually created by ant if it encounters the nested
23: * <code><steps></code> element within a <code><webtest></code> element.
24: * <p/>
25: * <p><em>Note: The nested element object <code>ClickButton</code> is instantiated and "added" to the
26: * <code>AbstractStepSequence</code> before the nested element is completely parsed! No attributes
27: * or nested elements of the <code><clickButton></code> elements are available at time
28: * when it is added to <code>AbstractStepSequence</code>.</em></p>
29: *
30: * @author Carsten Seibert
31: * @author Marc Guillemot
32: * @webtest.step
33: */
34: public abstract class AbstractStepContainer extends Step implements
35: TaskContainer, IStepSequence, Serializable, Cloneable {
36: private static final Logger LOG = Logger
37: .getLogger(AbstractStepContainer.class);
38:
39: private List fSteps = new ArrayList();
40:
41: protected AbstractStepContainer() {
42: }
43:
44: /**
45: * Called by ant to add a nested task to this container.
46: *
47: * @see org.apache.tools.ant.TaskContainer#addTask(org.apache.tools.ant.Task)
48: */
49: public void addTask(final Task newTask) {
50: fSteps.add(newTask);
51: }
52:
53: /**
54: * @param step
55: * @webtest.nested.parameter required="yes"
56: * description="A webtest step."
57: */
58: public void addStep(final Step step) {
59: LOG.debug("Adding WebTest Step: " + step);
60: addTask(step);
61: }
62:
63: public List getSteps() {
64: return fSteps;
65: }
66:
67: /**
68: * Executes the contained step taking care to setup needed properties before execution
69: *
70: * @param step the step to execute
71: */
72: protected void executeContainedStep(final Task step) {
73: step.perform();
74: }
75:
76: /**
77: * Executes the contained steps
78: */
79: protected void executeContainedSteps() {
80: for (final Iterator iter = getSteps().iterator(); iter
81: .hasNext();) {
82: executeContainedStep((Task) iter.next());
83: }
84: }
85: }
|