View Javadoc

1   /*
2       Jameleon - An automation testing tool..
3       Copyright (C) 2007 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.unit;
20  
21  import junit.framework.TestCase;
22  import net.sf.jameleon.event.TestCaseListener;
23  import net.sf.jameleon.event.TestCaseEvent;
24  import net.sf.jameleon.ExecuteTestCase;
25  import net.sf.jameleon.TestCaseTag;
26  import net.sf.jameleon.result.TestCaseResult;
27  
28  import java.io.File;
29  
30  /***
31   * A class to help with unit testing scripts and tags.
32   */
33  public abstract class JameleonUnitTestCase extends TestCase implements TestCaseListener {
34  
35      private TestCaseResult testCaseResult;
36      private TestCaseTag testCaseTag;
37  
38      public JameleonUnitTestCase(String name){
39          super(name);
40      }
41  
42      /***
43       * Implementation of the TestCaseListener interface. Currently does nothing.
44       * @param event The TestCaseEvent that spawned this event. The source of the event is the TestCaseTag
45       */
46      public void beginTestCase(TestCaseEvent event){}
47  
48      /***
49       * Implementation of the TestCaseListener interface. Gets the handle on the test case tag and the results.
50       * @param event The TestCaseEvent that spawned this event. The source of the event is the TestCaseTag
51       */
52      public void endTestCase(TestCaseEvent event){
53           testCaseTag = (TestCaseTag)event.getSource();
54           testCaseResult = testCaseTag.getResults();
55      }
56  
57      public TestCaseResult runScript(String script){
58          return runScript(new File(script));
59      }
60  
61      public TestCaseResult runScript(File script){
62           ExecuteTestCase exec = new ExecuteTestCase();
63           exec.registerEventListener(this);
64           exec.executeJellyScript(script);
65           return testCaseResult;
66      }
67  
68      /***
69       * Gets the test case result of the script that was run from the <code>runScript</code> method
70       * @return the test case result of the script that was run from the <code>runScript</code> method
71       */
72      public TestCaseResult getTestCaseResult() {
73          return testCaseResult;
74      }
75  
76      /***
77       * Gets the test case tag of the script that was run from the <code>runScript</code> method
78       * @return the test case tag of the script that was run from the <code>runScript</code> method 
79       */
80      public TestCaseTag getTestCaseTag() {
81          return testCaseTag;
82      }
83  }