1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.commons.jelly.tags.junit;
17
18 import junit.framework.Test;
19 import junit.framework.TestSuite;
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.TagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24
25 /***
26 * Represents a collection of TestCases.. This tag is analagous to
27 * JUnit's TestSuite class.
28 *
29 * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
30 * @version $Revision: 201960 $
31 */
32 public class SuiteTag extends TagSupport {
33
34 /*** the test suite this tag created */
35 private TestSuite suite;
36
37 /*** the name of the variable of the test suite */
38 private String var;
39
40 /*** the name of the test suite to create */
41 private String name;
42
43 public SuiteTag() {
44 }
45
46 /***
47 * Adds a new Test to this suite
48 */
49 public void addTest(Test test) {
50 getSuite().addTest(test);
51 }
52
53
54
55 public void doTag(XMLOutput output) throws JellyTagException {
56 suite = createSuite();
57
58 TestSuite parent = (TestSuite) context.getVariable("org.apache.commons.jelly.junit.suite");
59 if ( parent == null ) {
60 context.setVariable("org.apache.commons.jelly.junit.suite", suite );
61 }
62 else {
63 parent.addTest( suite );
64 }
65
66 invokeBody(output);
67
68 if ( var != null ) {
69 context.setVariable(var, suite);
70 }
71 }
72
73
74
75 public TestSuite getSuite() {
76 return suite;
77 }
78
79 /***
80 * Sets the name of the test suite whichi is exported
81 */
82 public void setVar(String var) {
83 this.var = var;
84 }
85
86 /***
87 * @return the name of this test suite
88 */
89 public String getName() {
90 return name;
91 }
92
93 /***
94 * Sets the name of this test suite
95 */
96 public void setName(String name) {
97 this.name = name;
98 }
99
100
101
102
103 /***
104 * Factory method to create a new TestSuite
105 */
106 protected TestSuite createSuite() {
107 if ( name == null ) {
108 return new TestSuite();
109 }
110 return new TestSuite(name);
111 }
112 }