1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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 }