1 16 package org.apache.commons.jelly.tags.junit; 17 18 import junit.framework.TestCase; 19 import junit.framework.TestSuite; 20 21 import org.apache.commons.jelly.JellyContext; 22 import org.apache.commons.jelly.JellyTagException; 23 import org.apache.commons.jelly.TagSupport; 24 import org.apache.commons.jelly.XMLOutput; 25 26 33 public class CaseTag extends TagSupport { 34 35 private String name; 36 37 38 public void doTag(final XMLOutput output) throws JellyTagException { 41 String name = getName(); 42 if ( name == null ) { 43 name = toString(); 44 } 45 46 TestCase testCase = new TestCase(name) { 49 protected void runTest() throws Throwable { 50 JellyContext newContext = new JellyContext( context ); 53 54 newContext.setExportLibraries(false); 56 newContext.setExport(false); 57 58 getBody().run(newContext, output); 60 } 61 }; 62 63 TestSuite suite = getSuite(); 65 if ( suite == null ) { 66 throw new JellyTagException( "Could not find a TestSuite to add this test to. This tag should be inside a <test:suite> tag" ); 67 } 68 suite.addTest(testCase); 69 } 70 71 74 77 public String getName() { 78 return name; 79 } 80 81 84 public void setName(String name) { 85 this.name = name; 86 } 87 88 91 94 protected TestSuite getSuite() { 95 SuiteTag tag = (SuiteTag) findAncestorWithClass( SuiteTag.class ); 96 if ( tag != null ) { 97 return tag.getSuite(); 98 } 99 return (TestSuite) context.getVariable( "org.apache.commons.jelly.junit.suite" ); 100 } 101 102 } 103 | Popular Tags |