001: /*
002: * Copyright 2002,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.jelly.tags.junit;
017:
018: import junit.framework.Test;
019: import junit.framework.TestSuite;
020:
021: import org.apache.commons.jelly.JellyTagException;
022: import org.apache.commons.jelly.TagSupport;
023: import org.apache.commons.jelly.XMLOutput;
024:
025: /**
026: * Represents a collection of TestCases.. This tag is analagous to
027: * JUnit's TestSuite class.
028: *
029: * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
030: * @version $Revision: 155420 $
031: */
032: public class SuiteTag extends TagSupport {
033:
034: /** the test suite this tag created */
035: private TestSuite suite;
036:
037: /** the name of the variable of the test suite */
038: private String var;
039:
040: /** the name of the test suite to create */
041: private String name;
042:
043: public SuiteTag() {
044: }
045:
046: /**
047: * Adds a new Test to this suite
048: */
049: public void addTest(Test test) {
050: getSuite().addTest(test);
051: }
052:
053: // Tag interface
054: //-------------------------------------------------------------------------
055: public void doTag(XMLOutput output) throws JellyTagException {
056: suite = createSuite();
057:
058: TestSuite parent = (TestSuite) context
059: .getVariable("org.apache.commons.jelly.junit.suite");
060: if (parent == null) {
061: context.setVariable("org.apache.commons.jelly.junit.suite",
062: suite);
063: } else {
064: parent.addTest(suite);
065: }
066:
067: invokeBody(output);
068:
069: if (var != null) {
070: context.setVariable(var, suite);
071: }
072: }
073:
074: // Properties
075: //-------------------------------------------------------------------------
076: public TestSuite getSuite() {
077: return suite;
078: }
079:
080: /**
081: * Sets the name of the test suite whichi is exported
082: */
083: public void setVar(String var) {
084: this .var = var;
085: }
086:
087: /**
088: * @return the name of this test suite
089: */
090: public String getName() {
091: return name;
092: }
093:
094: /**
095: * Sets the name of this test suite
096: */
097: public void setName(String name) {
098: this .name = name;
099: }
100:
101: // Implementation methods
102: //-------------------------------------------------------------------------
103:
104: /**
105: * Factory method to create a new TestSuite
106: */
107: protected TestSuite createSuite() {
108: if (name == null) {
109: return new TestSuite();
110: } else {
111: return new TestSuite(name);
112: }
113: }
114: }
|