1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon;
20
21 import net.sf.jameleon.event.TestSuiteEventHandler;
22 import net.sf.jameleon.event.TestSuiteListener;
23 import net.sf.jameleon.exception.JameleonScriptException;
24
25 import org.apache.commons.jelly.JellyTagException;
26 import org.apache.commons.jelly.MissingAttributeException;
27 import org.apache.commons.jelly.XMLOutput;
28
29 /***
30 * This is currently a tag meant to group several test case scripts
31 * together into a test suite.
32 * An example use might be:
33 * <pre>
34 * <test-suite name="some test suite name">
35 * <precondition>
36 * <test-script script="scripts/setup.xml"/>
37 * </precondition>
38 * <test-script script="scripts/foo/0002.xml"/>
39 * <test-script script="scripts/foo/0003.xml"/>
40 * </test-suite>
41 * </pre>
42 * NOTE: There is currently no support for a postcondition tag yet.
43 * @jameleon.function name="test-suite"
44 */
45 public class TestSuiteTag extends JameleonTagSupport {
46
47
48 /***
49 * cache this for later removal
50 */
51 private TestSuiteListener listener;
52 /***
53 * The executor to use to execute all test scripts
54 */
55 protected ExecuteTestCase executor;
56 /***
57 * A fully qualified class name that implements TestSuiteListener.
58 * @jameleon.attribute
59 */
60 protected String testSuiteListener;
61 /***
62 * The name of the test suite.
63 * @jameleon.attribute
64 */
65 protected String name;
66
67 public void init() throws MissingAttributeException{
68 testForUnsupportedAttributesCaught();
69 broker.transferAttributes(context);
70 broker.validate(context);
71 }
72
73 public void registerTestSuiteListener(String testSuiteListener){
74 if (testSuiteListener != null) {
75 TestSuiteEventHandler tsHandler = TestSuiteEventHandler.getInstance();
76 Class c;
77 try{
78 c = Thread.currentThread().getContextClassLoader().loadClass(testSuiteListener);
79 listener = (TestSuiteListener)c.newInstance();
80 tsHandler.addTestSuiteListener(listener);
81 }catch(Exception e){
82 throw new JameleonScriptException("Could not register '"+testSuiteListener+"' due to the following reason", e, this);
83 }
84 }
85 }
86
87 public ExecuteTestCase getExecuteTestCase(){
88 return executor;
89 }
90
91 /***
92 * This method executes the tags inside the test-suite tag.
93 */
94 public void doTag(XMLOutput out) throws MissingAttributeException, JellyTagException{
95 init();
96 registerTestSuiteListener(testSuiteListener);
97 TestSuiteEventHandler eventHandler = TestSuiteEventHandler.getInstance();
98 eventHandler.beginTestSuite(this);
99 executor = new ExecuteTestCase();
100
101 try{
102 invokeBody(out);
103 }finally{
104
105 eventHandler.endTestSuite(this);
106 eventHandler.removeTestSuiteListener(listener);
107 }
108 }
109
110 }