craigmcc    01/08/18 13:30:52

  Modified:    workflow build.xml
               workflow/src/test/org/apache/commons/workflow/base
                        BaseActivityTestCase.java TestStep.java
  Added:       workflow/src/test/org/apache/commons/workflow/base
                        BaseExecuteTestCase.java
  Log:
  Add basic test for executing an Activity.
  
  Revision  Changes    Path
  1.4       +12 -2     jakarta-commons-sandbox/workflow/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/workflow/build.xml,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- build.xml 2001/08/17 20:37:00     1.3
  +++ build.xml 2001/08/18 20:30:52     1.4
  @@ -3,7 +3,7 @@
   
   <!--
           "Workflow" component of the Jakarta Commons Subproject
  -        $Id: build.xml,v 1.3 2001/08/17 20:37:00 craigmcc Exp $
  +        $Id: build.xml,v 1.4 2001/08/18 20:30:52 craigmcc Exp $
   -->
   
   
  @@ -239,7 +239,8 @@
   
     <target name="test"  depends="compile.tests,
                                   test.BaseActivity,
  -                                test.BaseContext"
  +                                test.BaseContext,
  +                                test.BaseExecute"
      description="Run all unit test cases">
     </target>
   
  @@ -259,6 +260,15 @@
       <java classname="${test.runner}" fork="yes"
           failonerror="${test.failonerror}">
         <arg value="org.apache.commons.workflow.base.BaseContextTestCase"/>
  +      <classpath refid="test.classpath"/>
  +    </java>
  +  </target>
  +
  +  <target name="test.BaseExecute">
  +    <echo message="Running BaseExecute tests ..."/>
  +    <java classname="${test.runner}" fork="yes"
  +        failonerror="${test.failonerror}">
  +      <arg value="org.apache.commons.workflow.base.BaseExecuteTestCase"/>
         <classpath refid="test.classpath"/>
       </java>
     </target>
  
  
  
  1.2       +4 -4      
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseActivityTestCase.java
  
  Index: BaseActivityTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseActivityTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BaseActivityTestCase.java 2001/08/17 20:37:00     1.1
  +++ BaseActivityTestCase.java 2001/08/18 20:30:52     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseActivityTestCase.java,v
 1.1 2001/08/17 20:37:00 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/17 20:37:00 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseActivityTestCase.java,v
 1.2 2001/08/18 20:30:52 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/08/18 20:30:52 $
    *
    * ====================================================================
    *
  @@ -78,7 +78,7 @@
    * Step execution (and therefore require a Context).</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/08/17 20:37:00 $
  + * @version $Revision: 1.2 $ $Date: 2001/08/18 20:30:52 $
    */
   
   public class BaseActivityTestCase extends TestCase {
  @@ -88,7 +88,7 @@
   
   
       /**
  -     * The digester instance we will be testing.
  +     * The activity instance we will be testing.
        */
       protected Activity activity = null;
   
  
  
  
  1.2       +7 -7      
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/TestStep.java
  
  Index: TestStep.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/TestStep.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- TestStep.java     2001/08/17 20:37:00     1.1
  +++ TestStep.java     2001/08/18 20:30:52     1.2
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/TestStep.java,v
 1.1 2001/08/17 20:37:00 craigmcc Exp $
  - * $Revision: 1.1 $
  - * $Date: 2001/08/17 20:37:00 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/TestStep.java,v
 1.2 2001/08/18 20:30:52 craigmcc Exp $
  + * $Revision: 1.2 $
  + * $Date: 2001/08/18 20:30:52 $
    *
    * ====================================================================
    *
  @@ -71,7 +71,7 @@
    * Test implementation of the <code>Step</code> interface.
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.1 $ $Date: 2001/08/17 20:37:00 $
  + * @version $Revision: 1.2 $ $Date: 2001/08/18 20:30:52 $
    */
   
   public class TestStep extends BaseStep {
  @@ -148,13 +148,13 @@
        */
       public void execute(Context context) throws StepException {
   
  -        // Throw an exception if we are configured to do so
  -        if (fail)
  -            throw new StepException("StepException[" + id + "]", this);
  -
           // Record the execution of this Step in the execution trace
           results.append(id);
           results.append('/');
  +
  +        // Throw an exception if we are configured to do so
  +        if (fail)
  +            throw new StepException("StepException[" + id + "]", this);
   
       }
   
  
  
  
  1.1                  
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseExecuteTestCase.java
  
  Index: BaseExecuteTestCase.java
  ===================================================================
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseExecuteTestCase.java,v
 1.1 2001/08/18 20:30:52 craigmcc Exp $
   * $Revision: 1.1 $
   * $Date: 2001/08/18 20:30:52 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 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.workflow.base;
  
  
  import java.util.EmptyStackException;
  import junit.framework.Test;
  import junit.framework.TestCase;
  import junit.framework.TestSuite;
  import org.apache.commons.workflow.Activity;
  import org.apache.commons.workflow.Context;
  import org.apache.commons.workflow.Scope;
  import org.apache.commons.workflow.Step;
  import org.apache.commons.workflow.StepException;
  
  
  /**
   * <p>Test Case for the BaseActivity class.  These tests exercise those
   * features of Activity and Step implementations that do not perform any
   * Step execution (and therefore require a Context).</p>
   *
   * @author Craig R. McClanahan
   * @version $Revision: 1.1 $ $Date: 2001/08/18 20:30:52 $
   */
  
  public class BaseExecuteTestCase extends TestCase {
  
  
      // ----------------------------------------------------- Instance Variables
  
  
      /**
       * The activity instance we will be testing.
       */
      protected Activity activity = null;
  
  
      /**
       * The context instance we will be testing.
       */
      protected Context context = null;
  
  
      // ----------------------------------------------------------- Constructors
  
  
      /**
       * Construct a new instance of this test case.
       *
       * @param name Name of the test case
       */
      public BaseExecuteTestCase(String name) {
  
          super(name);
  
      }
  
  
      // --------------------------------------------------- Overall Test Methods
  
  
      /**
       * Set up instance variables required by this test case.
       */
      public void setUp() {
  
          activity = new BaseActivity();
          context = new BaseContext();
  
      }
  
  
      /**
       * Return the tests included in this test suite.
       */
      public static Test suite() {
  
          return (new TestSuite(BaseExecuteTestCase.class));
  
      }
  
  
      /**
       * Tear down instance variables required by this test case.
       */
      public void tearDown() {
  
          context = null;
          activity = null;
  
      }
  
  
      // ------------------------------------------------ Individual Test Methods
  
  
      /**
       * Negative test (should throw StepException).
       */
      public void testBaseNegative() {
  
          activity.addStep(new TestStep("Step 0", false));
          activity.addStep(new TestStep("Step 1", true));
          activity.addStep(new TestStep("Step 2", false));
          context.setActivity(activity);
  
          TestStep.clearResults();
          try {
              context.execute();
              fail("Should have thrown StepException");
          } catch (StepException e) {
              assertEquals("Executed step 0-1", "Step 0/Step 1/",
                           TestStep.getResults());
              assertEquals("Exception thrown by step 1", "Step 1",
                           e.getStep().getId());
                           
          }
  
      }
  
  
      /**
       * Positive test (should execute the entire Activity).
       */
      public void testBasePositive() {
  
          activity.addStep(new TestStep("Step 0", false));
          activity.addStep(new TestStep("Step 1", false));
          activity.addStep(new TestStep("Step 2", false));
          context.setActivity(activity);
  
          TestStep.clearResults();
          try {
              context.execute();
              assertEquals("Executed step 0-2", "Step 0/Step 1/Step 2/",
                           TestStep.getResults());
          } catch (StepException e) {
              fail("Threw StepException");
          }
  
      }
  
  
  }
  
  
  

Reply via email to