commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject cvs commit: jakarta-commons-sandbox/jelly project.properties maven.xml
Date Mon, 22 Jul 2002 07:16:52 GMT
jstrachan    2002/07/22 00:16:52

  Modified:    jelly/src/java/org/apache/commons/jelly/tags/junit
                        FailTag.java package.html JUnitTagLibrary.java
                        AssertTagSupport.java
               jelly/src/java/org/apache/commons/jelly jelly.properties
                        JellyContext.java
               jelly/xdocs todo.xml
               jelly    project.properties maven.xml
  Added:       jelly/src/java/org/apache/commons/jelly/tags/junit
                        JellyTestSuite.java RunTestTag.java
                        TestCaseTag.java TestSuiteTag.java
               jelly/src/test/org/apache/commons/jelly/junit suite.jelly
                        runSuite.jelly TestJUnit.java
  Log:
  Enhanced the JUnit tag library so that TestSuite and TestCase objects can be created in
Jelly script so that unit testing becomes easy to do via Jelly scripts.
  This also means that Jelly can be integrated easily into existing test runners.
  
  See the src/test/org/apache/commons/jelly/junit/ directory for details of how this works;
there you'll find a suite.jelly which is the test suite and a TestJUnit.java class which is
a simple class to bind the suite.jelly into Ant's default JUnit test runner.
  This class should be usable in any JUnit test runner, since it provides a class with a static
suite() method, yet internally it uses one or more Jelly scripts to actually create the individual
TestCase objects.
  
  So the new JellyUnit capabilities can be seamlessly integrated with traditional Java test
cases. So users can now use either Java or Jelly; intermixing the two to use the best tool
for the job. So now Jelly could be used for XML, SOAP, SQL, HTTP & JMS testing and such
like.
  
  Revision  Changes    Path
  1.2       +12 -4     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/FailTag.java
  
  Index: FailTag.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/FailTag.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- FailTag.java	20 Jul 2002 08:12:04 -0000	1.1
  +++ FailTag.java	22 Jul 2002 07:16:51 -0000	1.2
  @@ -80,16 +80,24 @@
       // Tag interface
       //------------------------------------------------------------------------- 
       public void doTag(XMLOutput output) throws Exception {
  -        String text = message;
  -        if ( text != null ) {
  -            text = getBodyText();
  +        String message = getMessage();
  +        if ( message == null ) {
  +            message = getBodyText();
           }
  -        fail( text );
  +        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.
  
  
  
  1.2       +8 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/package.html
  
  Index: package.html
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/package.html,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- package.html	20 Jul 2002 08:12:04 -0000	1.1
  +++ package.html	22 Jul 2002 07:16:51 -0000	1.2
  @@ -6,5 +6,13 @@
     <p>A collection of <a href="http://www.junit.org">JUnit</a> tags for

     	performing unit tests written in Jelly script.
     </p>
  +  
  +  <p>
  +    The &lt;suite&gt; 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 &lt;case&gt; tag allows a single test case to be created as part of a suite.
  +  </p>
   </body>
   </html>
  
  
  
  1.2       +3 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/JUnitTagLibrary.java
  
  Index: JUnitTagLibrary.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/JUnitTagLibrary.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- JUnitTagLibrary.java	20 Jul 2002 08:12:04 -0000	1.1
  +++ JUnitTagLibrary.java	22 Jul 2002 07:16:51 -0000	1.2
  @@ -90,6 +90,9 @@
           registerTag("assert", AssertTag.class);
           registerTag("assertEquals", AssertEqualsTag.class);
           registerTag("fail", FailTag.class);
  +        registerTag("run", RunTestTag.class );
  +        registerTag("case", TestCaseTag.class );
  +        registerTag("suite", TestSuiteTag.class );
       }
   
       public Expression createExpression(
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/AssertTagSupport.java
  
  Index: AssertTagSupport.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/AssertTagSupport.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AssertTagSupport.java	20 Jul 2002 08:12:04 -0000	1.1
  +++ AssertTagSupport.java	22 Jul 2002 07:16:51 -0000	1.2
  @@ -97,7 +97,7 @@
           if (message != null) {
               formatted = message +" ";
           }
  -        fail(formatted + "expected:<" + expected + "> but was:<" + actual + ">");
  +        fail(formatted + "expected:[" + expected + "] but was:[" + actual + "]");
       }
       
   }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/JellyTestSuite.java
  
  Index: JellyTestSuite.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTestSuite.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 apache@apache.org.
   *
   * 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.8 2002/07/06 13:53:39 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.TagSupport;
  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:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  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/java/org/apache/commons/jelly/tags/junit/RunTestTag.java
  
  Index: RunTestTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/RunTestTag.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 apache@apache.org.
   *
   * 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: RunTestTag.java,v 1.8 2002/07/06 13:53:39 dion Exp $
   */
  package org.apache.commons.jelly.tags.junit;
  
  import junit.framework.Test;
  import junit.framework.TestResult;
  
  import org.apache.commons.jelly.MissingAttributeException;
  import org.apache.commons.jelly.TagSupport;
  import org.apache.commons.jelly.XMLOutput;
  
  /** 
   * 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:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class RunTestTag extends TagSupport {
  
      private Test test;
      private TestResult result;
      
      
      // Tag interface
      //------------------------------------------------------------------------- 
      public void doTag(XMLOutput output) throws Exception {
          if ( test == null ) {
              throw new MissingAttributeException( "test" );
          }
          TestResult result = getResult();
          if ( result == null ) {
              result = createResult(output);                    
          }
          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;
      }
  
      // 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();
      }
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/TestCaseTag.java
  
  Index: TestCaseTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/TestCaseTag.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 apache@apache.org.
   *
   * 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: TestCaseTag.java,v 1.8 2002/07/06 13:53:39 dion Exp $
   */
  package org.apache.commons.jelly.tags.junit;
  
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  
  
  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:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class TestCaseTag 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 {
                  invokeBody(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() {
          TestSuiteTag tag = (TestSuiteTag) findAncestorWithClass( TestSuiteTag.class );
          if ( tag != null ) {
              return tag.getSuite();
          }
          return (TestSuite) context.getVariable( "org.apache.commons.jelly.junit.suite" );
      }
  
  }
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/junit/TestSuiteTag.java
  
  Index: TestSuiteTag.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/TestSuiteTag.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 apache@apache.org.
   *
   * 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: TestSuiteTag.java,v 1.8 2002/07/06 13:53:39 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:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class TestSuiteTag 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 TestSuiteTag() {
      }
      
      /**
       * 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.18      +1 -0      jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties
  
  Index: jelly.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/jelly.properties,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- jelly.properties	19 Jul 2002 22:19:32 -0000	1.17
  +++ jelly.properties	22 Jul 2002 07:16:51 -0000	1.18
  @@ -8,6 +8,7 @@
   log         = org.apache.commons.jelly.tags.log.LogTagLibrary
   werkz       = org.apache.commons.jelly.tags.werkz.WerkzTagLibrary
   util        = org.apache.commons.jelly.tags.util.UtilTagLibrary
  +junit 	    = org.apache.commons.jelly.tags.junit.JUnitTagLibrary
   
   # optional taglibs
   html		= org.apache.commons.jelly.tags.html.HTMLTagLibrary
  
  
  
  1.17      +23 -8     jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java
  
  Index: JellyContext.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/JellyContext.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- JellyContext.java	15 Jul 2002 16:56:49 -0000	1.16
  +++ JellyContext.java	22 Jul 2002 07:16:52 -0000	1.17
  @@ -435,28 +435,35 @@
       }
   
       /** 
  -     * Attempts to parse the script from the given File then compiles it and runs it.
  +     * Parses the script from the given File then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
        */
  -    public void runScript(File file, XMLOutput output) throws Exception {
  -        runScript(file.toURL(), output);
  +    public JellyContext runScript(File file, XMLOutput output) throws Exception {
  +        return runScript(file.toURL(), output);
       }
   
       /** 
  -     * Attempts to parse the script from the given URL then compiles it and runs it.
  +     * Parses the script from the given URL then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
        */
  -    public void runScript(URL url, XMLOutput output) throws Exception {
  +    public JellyContext runScript(URL url, XMLOutput output) throws Exception {
           Script script = compileScript(url);
           
           URL newJellyContextURL = getJellyContextURL(url);
           JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
           script.run(newJellyContext, output);
  +        return newJellyContext;
       }
   
       /** 
  -     * Attempts to parse the script from the given uri using the 
  +     * Parses the script from the given uri using the 
        * JellyContext.getResource() API then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
        */
  -    public void runScript(String uri, XMLOutput output) throws Exception {
  +    public JellyContext runScript(String uri, XMLOutput output) throws Exception {
           URL url = getResource(uri);
           if (url == null) {
               throw new JellyException("Could not find Jelly script: " + url);
  @@ -466,9 +473,16 @@
           URL newJellyContextURL = getJellyContextURL(url);
           JellyContext newJellyContext = new JellyContext(this, newJellyContextURL);
           script.run(newJellyContext, output);
  +        return newJellyContext;
       }
   
  -    public void runScript(String uri, XMLOutput output,
  +    /** 
  +     * Parses the script from the given uri using the 
  +     * JellyContext.getResource() API then compiles it and runs it.
  +     * 
  +     * @return the new child context that was used to run the script
  +     */
  +    public JellyContext runScript(String uri, XMLOutput output,
                             boolean export, boolean inherit) throws Exception {
           URL url = getResource(uri);
           if (url == null) {
  @@ -488,6 +502,7 @@
           }
   
           script.run(newJellyContext, output);
  +        return newJellyContext;
       }
   
       /**
  
  
  
  1.19      +0 -8      jakarta-commons-sandbox/jelly/xdocs/todo.xml
  
  Index: todo.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/xdocs/todo.xml,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- todo.xml	18 Jul 2002 09:47:50 -0000	1.18
  +++ todo.xml	22 Jul 2002 07:16:52 -0000	1.19
  @@ -30,9 +30,6 @@
   		</li>
   		<li>Write a JellyServlet so that Jelly can be used as a page templating system.
   		</li>
  -		<li>Implement a JellyUnit system so that Jelly cleanly integrates with the JUnit
framework
  -			and Maven's test plugin neatly so that unit tests can be written in jelly script if
required.
  -		</li>
   		<li>Implement a HTML parser for Jelly, probably using NeckoHTML so that non-XML
can be parsed
   			and tags with prefixes can be bound to Jelly tags.
   		</li>
  @@ -64,11 +61,6 @@
         
       <section name="Ideas for new tag libraries"> 
         <ul>
  -		<li>Add JUnit tag library along these lines...
  -<pre>&lt;junit:assert test="${foo == 22}"&gt;some description&lt;/junit:assert&gt;
  -&lt;junit:assertEquals value="${foo}" expected="${22}"&gt;some description&lt;/junit:assert&gt;
  -</pre>
  -		</li>
           <li>
           	An XSD tag library that can be used to parse XSD documents and create DynaBeans
from the complex types.
   <pre>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/junit/suite.jelly
  
  Index: suite.jelly
  ===================================================================
  <?xml version="1.0"?>
  <test:suite xmlns:j="jelly:core" xmlns:test="jelly:junit">
  
    <test:case name="assertTests">
    
      <test:assert test="${2 == 2}">This should never fail</test:assert>
      
      <j:catch var="ex">
  	  <test:assert test="${2 != 2}">This should always fail</test:assert>
  	</j:catch>    	
  	
  	<test:assert test="${ex != null}">We should have created an exception</test:assert>
  	
  	The exception was: ${ex.message}
    </test:case>
  
  
    <test:case name="failTests">
    
      <j:catch var="ex">
  	  <test:fail>This should always fail</test:fail>
  	</j:catch>    	
  	
  	<test:assert test="${ex != null}">We should have created an exception</test:assert>
  	
  	The exception was: ${ex.message}
  	
      <j:catch var="ex">
  	  <test:fail message="This should always fail"/>
  	</j:catch>    	
  	
  	<test:assert test="${ex != null}">We should have created an exception</test:assert>
  	
  	The exception was: ${ex.message}
    </test:case>
  
  	
    <test:case name="assertEqualTests">
    
      <j:set var="foo" value="abc"/>
      
      <test:assertEquals actual="${foo}" expected="abc">This should never fail</test:assertEquals>
      
      <j:catch var="ex">
        <test:assertEquals actual="${foo}" expected="def">This should always fail</test:assertEquals>
  	</j:catch>    	
  	
  	<test:assert test="${ex != null}">We should have created an exception</test:assert>
  	
  	The exception was: ${ex.message}
    </test:case>
  
  </test:suite>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/junit/runSuite.jelly
  
  Index: runSuite.jelly
  ===================================================================
  <?xml version="1.0"?>
  <j:jelly xmlns:j="jelly:core" xmlns:test="jelly:junit">
  
  <!-- lets define a test suite -->
  <test:suite var="suite"> 
    <j:include uri="suite.jelly"/>
  </test:suite>
  
  Lets run the test suite.
  
  <test:run test="${suite}"/>
  
  Tests finished.
  
  </j:jelly>
  
  
  
  1.1                  jakarta-commons-sandbox/jelly/src/test/org/apache/commons/jelly/junit/TestJUnit.java
  
  Index: TestJUnit.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-commons-sandbox/jelly/src/java/org/apache/commons/jelly/tags/core/JellyTestSuite.java,v
1.8 2002/07/06 13:53:39 dion Exp $
   * $Revision: 1.8 $
   * $Date: 2002/07/06 13:53:39 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-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 apache@apache.org.
   *
   * 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.8 2002/07/06 13:53:39 dion Exp $
   */
  package org.apache.commons.jelly.junit;
  
  import junit.framework.TestSuite;
  import junit.textui.TestRunner;
  
  import org.apache.commons.jelly.tags.junit.JellyTestSuite;
  
  /** 
   * A helper class to run jelly test cases as part of Ant's JUnit tests
   *
   * @author <a href="mailto:jstrachan@apache.org">James Strachan</a>
   * @version $Revision: 1.8 $
   */
  public class TestJUnit extends JellyTestSuite {
  
      public static void main( String[] args ) throws Exception {
          TestRunner.run( suite() );
      }
      
      public static TestSuite suite() throws Exception {
          return createTestSuite(TestJUnit.class, "suite.jelly");        
      }
  }
  
  
  
  1.10      +1 -1      jakarta-commons-sandbox/jelly/project.properties
  
  Index: project.properties
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/project.properties,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- project.properties	19 Jul 2002 22:07:34 -0000	1.9
  +++ project.properties	22 Jul 2002 07:16:52 -0000	1.10
  @@ -7,7 +7,7 @@
   maven.compile.deprecation = off
   
   maven.jarResources.basedir=${basedir}/src/java
  -maven.junit.usefile = false
  +maven.junit.usefile = true
    
   # Installation dir
   maven.dist.install.dir = /usr/local/jelly
  
  
  
  1.16      +30 -3     jakarta-commons-sandbox/jelly/maven.xml
  
  Index: maven.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/jelly/maven.xml,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- maven.xml	19 Jul 2002 23:03:00 -0000	1.15
  +++ maven.xml	22 Jul 2002 07:16:52 -0000	1.16
  @@ -1,7 +1,7 @@
   <project default="java:jar" xmlns:j="jelly:core">
   
     <!-- define jelly task -->	
  -  <goal name="jelly-task" prereqs="java:compile">
  +  <goal name="jelly-task" prereqs="java:compile, test:compile">
   	<path id="test.classpath">
   	    <pathelement path="${maven.build.dest}"/>
   	    <pathelement path="target/classes"/>
  @@ -66,9 +66,16 @@
     
     </preGoal>
   
  +
  +  <!-- ensure that the test jelly scripts are copied to the test-classes directory -->

  +  <preGoal name="test:test">
  +    <copy todir="${maven.test.dest}">
  +	  <fileset dir="${pom.build.unitTestSourceDirectory}" includes="**/*.jelly"/>
  +	</copy>
  +  </preGoal>
  +
     <!-- create the lib and bin directories in the binary distro -->  
  -  <preGoal
  -    name="dist:build">
  +  <preGoal name="dist:build">
   
       <echo>The POM is ${pom.build}</echo>
       <echo>About to create lib and bin directories in ${maven.dist.assembly.dir}</echo>
  @@ -207,6 +214,26 @@
       <java classname="org.apache.commons.jelly.Jelly" fork="yes">
         <classpath refid="test.classpath"/>
         <arg value="src/test/org/apache/commons/jelly/html/example2.jelly"/> 
  +    </java>
  +  </goal>
  +
  +  <goal name="demo:test" prereqs="jelly-task" 
  +	description="Runs a sample JUnit test suite via Jelly">
  +	
  +<!--	
  +	<jelly file="src/test/org/apache/commons/jelly/junit/testSuite.jelly"/> 
  +-->	
  +    <java classname="org.apache.commons.jelly.Jelly" fork="yes">
  +      <classpath refid="test.classpath"/>
  +      <arg value="src/test/org/apache/commons/jelly/junit/testSuite.jelly"/> 
  +    </java>
  +  </goal>
  +
  +  <goal name="demo:junit" prereqs="jelly-task" 
  +	description="Runs the Jelly JUnit test suite">
  +	
  +    <java classname="org.apache.commons.jelly.junit.TestJUnit" fork="yes">
  +      <classpath refid="test.classpath"/>
       </java>
     </goal>
   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message