View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2006 Christian W. Hargraves (engrean@hotmail.com)
4       
5       This library is free software; you can redistribute it and/or
6       modify it under the terms of the GNU Lesser General Public
7       License as published by the Free Software Foundation; either
8       version 2.1 of the License, or (at your option) any later version.
9   
10      This library is distributed in the hope that it will be useful,
11      but WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13      Lesser General Public License for more details.
14  
15      You should have received a copy of the GNU Lesser General Public
16      License along with this library; if not, write to the Free Software
17      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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   *  &lt;test-suite name="some test suite name"&gt;
35   *    &lt;precondition&gt;
36   *      &lt;test-script script="scripts/setup.xml"/&gt;
37   *    &lt;/precondition&gt;
38   *    &lt;test-script script="scripts/foo/0002.xml"/&gt;
39   *    &lt;test-script script="scripts/foo/0003.xml"/&gt;
40   *  &lt;/test-suite&gt;
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 //        executor.registerEventListeners();
101         try{
102             invokeBody(out);
103         }finally{
104             //executor.deregisterEventListeners();
105             eventHandler.endTestSuite(this);
106             eventHandler.removeTestSuiteListener(listener);
107         }
108     }
109 
110 }