dion 2003/01/18 22:03:12 Added: jelly/src/test/org/apache/commons/jelly/tags/junit AssertEqualsTag.java RunTag.java AssertThrowsTag.java JellyTestSuite.java JUnitTagLibrary.java package.html AssertTagSupport.java AssertTag.java SuiteTag.java FailTag.java CaseTag.java JellyAssertionFailedError.java Log: Copy current junit tags into test source tree for use in core testing Revision Changes Path 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertEqualsTag.java Index: AssertEqualsTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertEqualsTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: AssertEqualsTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.expression.Expression; /** * Compares an actual object against an expected object and if they are different * then the test will fail. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class AssertEqualsTag extends AssertTagSupport { private Expression actual; private Expression expected; // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { String message = getBodyText(); Object expectedValue = expected.evaluate(context); Object actualValue = actual.evaluate(context); if (expectedValue == null && actualValue == null) { return; } if (actualValue != null && expectedValue.equals(actualValue)) { return; } String expressions = "\nExpected expression: " + expected.getExpressionText() + "\nActual expression: " + actual.getExpressionText(); failNotEquals(message, expectedValue, actualValue, expressions); } // Properties //------------------------------------------------------------------------- /** * Sets the actual value which will be compared against the * expected value. */ public void setActual(Expression actual) { this.actual = actual; } /** * Sets the expected value to be tested against */ public void setExpected(Expression expected) { this.expected = expected; } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/RunTag.java Index: RunTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/RunTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: RunTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import java.io.PrintWriter; import java.io.StringWriter; import junit.framework.AssertionFailedError; import junit.framework.Test; import junit.framework.TestListener; import junit.framework.TestResult; import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributesImpl; /** * This tag will run the given Test which could be an individual TestCase or a TestSuite. * The TestResult can be specified to capture the output, otherwise the results are output * as XML so that they can be formatted in some custom manner. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class RunTag extends TagSupport { /** The Log to which logging calls will be made. */ private static final Log log = LogFactory.getLog(RunTag.class); private Test test; private TestResult result; private TestListener listener; // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { Test test = getTest(); if ( test == null ) { test = (Test) context.getVariable("org.apache.commons.jelly.junit.suite"); } if ( test == null ) { throw new MissingAttributeException( "test" ); } TestResult result = getResult(); if ( result == null ) { result = createResult(output); } TestListener listener = getListener(); if ( listener == null ) { listener = createTestListener(output); } result.addListener(listener); test.run(result); } // Properties //------------------------------------------------------------------------- /** * Returns the TestResult used to capture the output of the test. * @return TestResult */ public TestResult getResult() { return result; } /** * Returns the Test to be ran. * @return Test */ public Test getTest() { return test; } /** * Sets the JUnit TestResult used to capture the results of the tst * @param result The TestResult to use */ public void setResult(TestResult result) { this.result = result; } /** * Sets the JUnit Test to run which could be an individual test or a TestSuite * @param test The test to run */ public void setTest(Test test) { this.test = test; } /** * Returns the listener. * @return TestListener */ public TestListener getListener() { return listener; } /** * Sets the TestListener.to be used to format the output of running the unit test cases * @param listener The listener to set */ public void setListener(TestListener listener) { this.listener = listener; } // Implementation methods //------------------------------------------------------------------------- /** * Factory method to create a new TestResult to capture the output of * the test cases */ protected TestResult createResult(XMLOutput output) { return new TestResult(); } /** * Factory method to create a new TestListener to capture the output of * the test cases */ protected TestListener createTestListener(final XMLOutput output) { return new TestListener() { public void addError(Test test, Throwable t) { try { output.startElement("error"); output.startElement("message"); output.write(t.getMessage()); output.endElement("message"); output.startElement("stack"); output.write( stackTraceToString(t) ); output.endElement("stack"); output.endElement("error"); } catch (SAXException e) { handleSAXException(e); } } public void addFailure(Test test, AssertionFailedError t) { try { output.startElement("failure"); output.startElement("message"); output.write(t.getMessage()); output.endElement("message"); output.startElement("stack"); output.write( stackTraceToString(t) ); output.endElement("stack"); output.endElement("failure"); } catch (SAXException e) { handleSAXException(e); } } public void endTest(Test test) { try { output.endElement("test"); } catch (SAXException e) { handleSAXException(e); } } public void startTest(Test test) { try { String name = test.toString(); AttributesImpl attributes = new AttributesImpl(); attributes.addAttribute("", "name", "name", "CDATA", name); output.startElement("test", attributes); } catch (SAXException e) { handleSAXException(e); } } }; } /** * @return the stack trace as a String */ protected String stackTraceToString(Throwable t) { StringWriter writer = new StringWriter(); t.printStackTrace(new PrintWriter(writer)); return writer.toString(); } /** * Handles SAX Exceptions */ protected void handleSAXException(SAXException e) { log.error( "Caught: " + e, e ); } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertThrowsTag.java Index: AssertThrowsTag.java =================================================================== /* * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.JellyException; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * Runs its body and asserts that an exception is thrown by it. If no * exception is thrown the tag fails. By default all exceptions are caught. * If however <code>expected</code> was specified the body must throw * an exception of the given class, otherwise the assertion fails. The * exception thrown by the body can also be of any subtype of the specified * exception class. The optional <code>var</code> attribute can be specified if * the caught exception is to be exported to a variable. */ public class AssertThrowsTag extends AssertTagSupport { /** The Log to which logging calls will be made. */ private static final Log log = LogFactory.getLog(AssertThrowsTag.class); /** * The variable name to export the caught exception to. */ private String var; /** * The class name (fully qualified) of the exception expected to be thrown * by the body. Also a superclass of the expected exception can be given. */ private String expected; /** * Sets the ClassLoader to be used when loading an exception class */ private ClassLoader classLoader; // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { Class throwableClass = getThrowableClass(); try { invokeBody(output); } catch (Throwable t) { if (t instanceof JellyException) { // unwrap Jelly exceptions which wrap other exceptions JellyException je = (JellyException) t; if (je.getCause() != null) { t = je.getCause(); } } if (var != null) { context.setVariable(var, t); } if (throwableClass != null && !throwableClass.isAssignableFrom(t.getClass())) { fail("Unexpected exception: " + t); } else { return; } } fail("No exception was thrown."); } // Properties //------------------------------------------------------------------------- /** * Sets the class name of exception expected to be thrown by the body. The * class name must be fully qualified and can either be the expected * exception class itself or any supertype of it, but must be a subtype of * <code>java.lang.Throwable</code>. */ public void setExpected(String expected) { this.expected = expected; } /** * Sets the variable name to define for this expression. */ public void setVar(String var) { this.var = var; } /** * Sets the class loader to be used to load the exception type */ public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } public ClassLoader getClassLoader() { if (classLoader == null) { return getClass().getClassLoader(); } return classLoader; } // Implementation methods //------------------------------------------------------------------------- /** * Returns the <code>Class</code> corresponding to the class * specified by <code>expected</code>. If * <code>expected</code> was either not specified then <code>java. lang. * Throwable</code> is returned. * Otherwise if the class couldn't be * found or doesn't denote an exception class then an exception is thrown. * * @return Class The class of the exception to expect */ protected Class getThrowableClass() throws ClassNotFoundException { if (expected == null) { return Throwable.class; } Class throwableClass = null; try { throwableClass = getClassLoader().loadClass(expected); } catch (ClassNotFoundException e) { try { throwableClass = Thread.currentThread().getContextClassLoader().loadClass(expected); } catch (ClassNotFoundException e2) { log.warn( "Could not find exception class: " + expected ); throw e; } } if (!Throwable.class.isAssignableFrom(throwableClass)) { log.warn( "The class: " + expected + " is not an Exception class."); return null; } return throwableClass; } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JellyTestSuite.java Index: JellyTestSuite.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JellyTestSuite.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: JellyTestSuite.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import java.net.URL; import junit.framework.TestSuite; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; /** * An abstract base class for creating a TestSuite via a Jelly script. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public abstract class JellyTestSuite { /** The Log to which logging calls will be made. */ private static final Log log = LogFactory.getLog(JellyTestSuite.class); /** * Helper method to create a test suite from a file name on the class path * in the package of the given class. * For example a test could call * <code> * createTestSuite( Foo.class, "suite.jelly" ); * </code> * which would loaad the 'suite.jelly script from the same package as the Foo * class on the classpath. * * @param testClass is the test class used to load the script via the classpath * @param script is the name of the script, which is typically just a name, no directory. * @return a newly created TestSuite */ public static TestSuite createTestSuite(Class testClass, String script) throws Exception { URL url = testClass.getResource(script); if ( url == null ) { throw new Exception( "Could not find Jelly script: " + script + " in package of class: " + testClass.getName() ); } return createTestSuite( url ); } /** * Helper method to create a test suite from the given Jelly script * * @param script is the URL to the script which should create a TestSuite * @return a newly created TestSuite */ public static TestSuite createTestSuite(URL script) throws Exception { JellyContext context = new JellyContext(script); XMLOutput output = XMLOutput.createXMLOutput(System.out); context = context.runScript(script, output); TestSuite answer = (TestSuite) context.getVariable("org.apache.commons.jelly.junit.suite"); if ( answer == null ) { log.warn( "Could not find a TestSuite created by Jelly for the script:" + script ); // return an empty test suite return new TestSuite(); } return answer; } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JUnitTagLibrary.java Index: JUnitTagLibrary.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JUnitTagLibrary.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: JUnitTagLibrary.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.TagLibrary; import org.apache.commons.jelly.JellyException; import org.apache.commons.jelly.TagLibrary; import org.apache.commons.jelly.expression.Expression; import org.apache.commons.jelly.expression.ExpressionFactory; import org.apache.commons.jelly.impl.TagScript; import org.apache.commons.jelly.expression.xpath.XPathExpression; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jaxen.JaxenException; /** Describes the Taglib. This class could be generated by XDoclet * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class JUnitTagLibrary extends TagLibrary { /** The Log to which logging calls will be made. */ private Log log = LogFactory.getLog(JUnitTagLibrary.class); public JUnitTagLibrary() { registerTag("assert", AssertTag.class); registerTag("assertEquals", AssertEqualsTag.class); registerTag("assertThrows", AssertThrowsTag.class); registerTag("fail", FailTag.class); registerTag("run", RunTag.class ); registerTag("case", CaseTag.class ); registerTag("suite", SuiteTag.class ); } public Expression createExpression( ExpressionFactory factory, TagScript tagScript, String attributeName, String attributeValue) throws Exception { // #### may need to include some namespace URI information in the XPath instance? if (attributeName.equals("xpath")) { if ( log.isDebugEnabled() ) { log.debug( "Parsing XPath expression: " + attributeValue ); } try { // XPath xpath = new Dom4jXPath(attributeValue); Expression xpathExpr = super.createExpression( factory, tagScript, attributeName, attributeValue ); return new XPathExpression(attributeValue, xpathExpr, tagScript); } catch (JaxenException e) { throw new JellyException( "Could not parse XPath expression: \"" + attributeValue + "\" reason: " + e, e ); } } // will use the default expression instead return super.createExpression(factory, tagScript, attributeName, attributeValue); } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/package.html Index: package.html =================================================================== <html> <head> </head> <body> <p>A collection of <a href="http://www.junit.org">JUnit</a> tags for performing unit tests written in Jelly script. </p> <p> The <suite> tag allows a test suite to be created and then test cases can either be individually ran or the whole suite ran. </p> <p> The <case> tag allows a single test case to be created as part of a suite. </p> <p> The <run> tag can be used to run a given Test, TestCase or TestSuite </p> <p>There is an example of these tags in action <a href="http://cvs.apache.org/viewcvs.cgi/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/junit/suite.jelly?rev=HEAD&content-type=text/vnd.viewcvs-markup">here</a> </p> </body> </html> 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertTagSupport.java Index: AssertTagSupport.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertTagSupport.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: AssertTagSupport.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.xpath.XPathTagSupport; /** * The abstract base class of any assertion tag which is * useful for implementation inheritence. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public abstract class AssertTagSupport extends XPathTagSupport { public AssertTagSupport() { } // Implementation methods //------------------------------------------------------------------------- /** * Produces a failure assertion with the given message */ protected void fail(String message) throws JellyAssertionFailedError { throw new JellyAssertionFailedError(message); } /** * Produces a failure assertion with the given message and added detail. */ protected void fail(String message, String detail) throws JellyAssertionFailedError { if (message == null || message.length() == 0) { fail(detail); } else { fail(message + ". Assertion failed while " + detail); } } /** * Produces a failure if the actual value was not equal to the expected value */ protected void failNotEquals(String message, Object expected, Object actual, String expressions) throws JellyAssertionFailedError { String formatted= ""; if (message != null) { formatted = message +" "; } fail(formatted + "expected:[" + expected + "] but was:[" + actual + "]" + expressions); } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertTag.java Index: AssertTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/AssertTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: AssertTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.XMLOutput; import org.apache.commons.jelly.MissingAttributeException; import org.apache.commons.jelly.expression.Expression; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jaxen.XPath; /** * Performs an assertion that a given boolean expression, or XPath expression is * true. If the expression returns false then this test fails. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class AssertTag extends AssertTagSupport { /** The Log to which logging calls will be made. */ private static final Log log = LogFactory.getLog(AssertTag.class); /** The expression to evaluate. */ private Expression test; /** The XPath expression to evaluate */ private XPath xpath; public AssertTag() { } // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { if (test == null && xpath == null) { throw new MissingAttributeException( "test" ); } if (test != null) { if (! test.evaluateAsBoolean(context)) { fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); } } else { Object xpathContext = getXPathContext(); if (! xpath.booleanValueOf(xpathContext)) { fail( getBodyText(), "evaluating xpath: "+ xpath ); } } } // Properties //------------------------------------------------------------------------- /** * Sets the boolean expression to evaluate. If this expression returns true * then the test succeeds otherwise if it returns false then the text will * fail with the content of the tag being the error message. */ public void setTest(Expression test) { this.test = test; } /** * Sets the boolean XPath expression to evaluate. If this expression returns true * then the test succeeds otherwise if it returns false then the text will * fail with the content of the tag being the error message. */ public void setXpath(XPath xpath) { this.xpath = xpath; } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/SuiteTag.java Index: SuiteTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/SuiteTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: SuiteTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import junit.framework.Test; import junit.framework.TestSuite; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; /** * Represents a collection of TestCases.. This tag is analagous to * JUnit's TestSuite class. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class SuiteTag extends TagSupport { /** the test suite this tag created */ private TestSuite suite; /** the name of the variable of the test suite */ private String var; /** the name of the test suite to create */ private String name; public SuiteTag() { } /** * Adds a new Test to this suite */ public void addTest(Test test) { getSuite().addTest(test); } // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { suite = createSuite(); TestSuite parent = (TestSuite) context.getVariable("org.apache.commons.jelly.junit.suite"); if ( parent == null ) { context.setVariable("org.apache.commons.jelly.junit.suite", suite ); } else { parent.addTest( suite ); } invokeBody(output); if ( var != null ) { context.setVariable(var, suite); } } // Properties //------------------------------------------------------------------------- public TestSuite getSuite() { return suite; } /** * Sets the name of the test suite whichi is exported */ public void setVar(String var) { this.var = var; } /** * @return the name of this test suite */ public String getName() { return name; } /** * Sets the name of this test suite */ public void setName(String name) { this.name = name; } // Implementation methods //------------------------------------------------------------------------- /** * Factory method to create a new TestSuite */ protected TestSuite createSuite() { if ( name == null ) { return new TestSuite(); } else { return new TestSuite(name); } } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/FailTag.java Index: FailTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/FailTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: FailTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import org.apache.commons.jelly.XMLOutput; /** * This tag causes a failure message. The message can either * be specified in the tags body or via the message attribute. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class FailTag extends AssertTagSupport { private String message; public FailTag() { } // Tag interface //------------------------------------------------------------------------- public void doTag(XMLOutput output) throws Exception { String message = getMessage(); if ( message == null ) { message = getBodyText(); } fail( message ); } // Properties //------------------------------------------------------------------------- /** * @return the failure message */ public String getMessage() { return message; } /** * Sets the failure message. If this attribute is not specified then the * body of this tag will be used instead. */ public void setMessage(String message) { this.message = message; } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/CaseTag.java Index: CaseTag.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/CaseTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: CaseTag.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import junit.framework.TestCase; import junit.framework.TestSuite; import org.apache.commons.jelly.JellyContext; import org.apache.commons.jelly.JellyException; import org.apache.commons.jelly.TagSupport; import org.apache.commons.jelly.XMLOutput; /** * Represents a single test case in a test suite; this tag is analagous to * JUnit's TestCase class. * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class CaseTag extends TagSupport { private String name; // Tag interface //------------------------------------------------------------------------- public void doTag(final XMLOutput output) throws Exception { String name = getName(); if ( name == null ) { name = toString(); } // #### we need to redirect the output to a TestListener // or something? TestCase testCase = new TestCase(name) { protected void runTest() throws Throwable { // create a new child context so that each test case // will have its own variable scopes JellyContext newContext = new JellyContext( context ); // disable inheritence of variables and tag libraries newContext.setExportLibraries(false); newContext.setExport(false); // invoke the test case getBody().run(newContext, output); } }; // lets find the test suite TestSuite suite = getSuite(); if ( suite == null ) { throw new JellyException( "Could not find a TestSuite to add this test to. This tag should be inside a <test:suite> tag" ); } suite.addTest(testCase); } // Properties //------------------------------------------------------------------------- /** * @return the name of this test case */ public String getName() { return name; } /** * Sets the name of this test case */ public void setName(String name) { this.name = name; } // Implementation methods //------------------------------------------------------------------------- /** * Strategy method to find the corrent TestSuite to add a new Test case to */ protected TestSuite getSuite() { SuiteTag tag = (SuiteTag) findAncestorWithClass( SuiteTag.class ); if ( tag != null ) { return tag.getSuite(); } return (TestSuite) context.getVariable( "org.apache.commons.jelly.junit.suite" ); } } 1.1 jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JellyAssertionFailedError.java Index: JellyAssertionFailedError.java =================================================================== /* * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/tags/junit/JellyAssertionFailedError.java,v 1.1 2003/01/19 06:03:12 dion Exp $ * $Revision: 1.1 $ * $Date: 2003/01/19 06:03:12 $ * * ==================================================================== * * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, if * any, must include the following acknowlegement: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowlegement may appear in the software itself, * if and wherever such third-party acknowlegements normally appear. * * 4. The names "The Jakarta Project", "Commons", and "Apache Software * Foundation" must not be used to endorse or promote products derived * from this software without prior written permission. For written * permission, please contact [EMAIL PROTECTED] * * 5. Products derived from this software may not be called "Apache" * nor may "Apache" appear in their names without prior written * permission of the Apache Group. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. * * $Id: JellyAssertionFailedError.java,v 1.1 2003/01/19 06:03:12 dion Exp $ */ package org.apache.commons.jelly.tags.junit; import java.io.PrintStream; import java.io.PrintWriter; import junit.framework.AssertionFailedError; import org.apache.commons.jelly.LocationAware; /** * <p><code>JellyAssertionFailedError</code> is * a JUnit AssertionFailedError which is LocationAware so that it can include * details of where in the JellyUnit test case that the failure occurred.</p> * * @author <a href="mailto:[EMAIL PROTECTED]">James Strachan</a> * @version $Revision: 1.1 $ */ public class JellyAssertionFailedError extends AssertionFailedError implements LocationAware { /** the underlying cause of the exception */ private Throwable cause; /** the Jelly file which caused the problem */ private String fileName; /** the tag name which caused the problem */ private String elementName; /** the line number in the script of the error */ private int lineNumber = -1; /** the column number in the script of the error */ private int columnNumber = -1; public JellyAssertionFailedError() { } public JellyAssertionFailedError(String message) { super(message); } public JellyAssertionFailedError(String message, Throwable cause) { super(message); this.cause = cause; } public JellyAssertionFailedError(Throwable cause) { super(cause.getLocalizedMessage()); this.cause = cause; } public Throwable getCause() { return cause; } /** * @return the line number of the tag */ public int getLineNumber() { return lineNumber; } /** * Sets the line number of the tag */ public void setLineNumber(int lineNumber) { this.lineNumber = lineNumber; } /** * @return the column number of the tag */ public int getColumnNumber() { return columnNumber; } /** * Sets the column number of the tag */ public void setColumnNumber(int columnNumber) { this.columnNumber = columnNumber; } /** * @return the Jelly file which caused the problem */ public String getFileName() { return fileName; } /** * Sets the Jelly file which caused the problem */ public void setFileName(String fileName) { this.fileName = fileName; } /** * @return the element name which caused the problem */ public String getElementName() { return elementName; } /** * Sets the element name which caused the problem */ public void setElementName(String elementName) { this.elementName = elementName; } public String getMessage() { return super.getMessage() + " File: " + fileName + " At tag <" + elementName + ">: line: " + lineNumber + " column: " + columnNumber; } public String getReason() { return super.getMessage(); } // #### overload the printStackTrace methods... public void printStackTrace(PrintWriter s) { synchronized (s) { super.printStackTrace(s); if (cause != null) { s.println("Root cause"); cause.printStackTrace(s); } } } public void printStackTrace(PrintStream s) { synchronized (s) { super.printStackTrace(s); if (cause != null) { s.println("Root cause"); cause.printStackTrace(s); } } } public void printStackTrace() { super.printStackTrace(); if (cause != null) { System.out.println("Root cause"); cause.printStackTrace(); } } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>