craigmcc 01/08/17 13:37:01 Modified: workflow build.xml workflow/src/java/org/apache/commons/workflow/base BaseActivity.java workflow/src/test/org/apache/commons/workflow/base BaseContextTestCase.java Added: workflow/src/test/org/apache/commons/workflow/base BaseActivityTestCase.java TestStep.java Log: Add test for BaseActivity (and related management of the associated Steps). Testing step execution will be its own test suite. Revision Changes Path 1.3 +13 -1 jakarta-commons-sandbox/workflow/build.xml Index: build.xml =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/workflow/build.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- build.xml 2001/08/17 05:15:48 1.2 +++ build.xml 2001/08/17 20:37:00 1.3 @@ -3,7 +3,7 @@ <!-- "Workflow" component of the Jakarta Commons Subproject - $Id: build.xml,v 1.2 2001/08/17 05:15:48 craigmcc Exp $ + $Id: build.xml,v 1.3 2001/08/17 20:37:00 craigmcc Exp $ --> @@ -238,9 +238,21 @@ <target name="test" depends="compile.tests, + test.BaseActivity, test.BaseContext" description="Run all unit test cases"> </target> + + + <target name="test.BaseActivity"> + <echo message="Running BaseActivity tests ..."/> + <java classname="${test.runner}" fork="yes" + failonerror="${test.failonerror}"> + <arg value="org.apache.commons.workflow.base.BaseActivityTestCase"/> + <classpath refid="test.classpath"/> + </java> + </target> + <target name="test.BaseContext"> <echo message="Running BaseContext tests ..."/> 1.3 +12 -4 jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java Index: BaseActivity.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BaseActivity.java 2001/08/13 23:15:23 1.2 +++ BaseActivity.java 2001/08/17 20:37:00 1.3 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java,v 1.2 2001/08/13 23:15:23 craigmcc Exp $ - * $Revision: 1.2 $ - * $Date: 2001/08/13 23:15:23 $ + * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/java/org/apache/commons/workflow/base/BaseActivity.java,v 1.3 2001/08/17 20:37:00 craigmcc Exp $ + * $Revision: 1.3 $ + * $Date: 2001/08/17 20:37:00 $ * * ==================================================================== * @@ -73,7 +73,7 @@ * management of the static relationships of Steps to each other as part * of an owning Activity.</p> * - * @version $Revision: 1.2 $ $Date: 2001/08/13 23:15:23 $ + * @version $Revision: 1.3 $ $Date: 2001/08/17 20:37:00 $ * @author Craig R. McClanahan */ @@ -129,6 +129,7 @@ */ public void addStep(Step step) { + step.setActivity(this); if (firstStep == null) { step.setPreviousStep(null); step.setNextStep(null); @@ -149,6 +150,13 @@ */ public void clear() { + Step current = firstStep; + while (current != null) { + Step next = current.getNextStep(); + current.setPreviousStep(null); + current.setNextStep(null); + current = next; + } firstStep = null; lastStep = null; 1.2 +5 -5 jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java Index: BaseContextTestCase.java =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- BaseContextTestCase.java 2001/08/17 05:15:48 1.1 +++ BaseContextTestCase.java 2001/08/17 20:37:00 1.2 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v 1.1 2001/08/17 05:15:48 craigmcc Exp $ - * $Revision: 1.1 $ - * $Date: 2001/08/17 05:15:48 $ + * $Header: /home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseContextTestCase.java,v 1.2 2001/08/17 20:37:00 craigmcc Exp $ + * $Revision: 1.2 $ + * $Date: 2001/08/17 20:37:00 $ * * ==================================================================== * @@ -76,7 +76,7 @@ * functions that are not dependent upon an associated Activity.</p> * * @author Craig R. McClanahan - * @version $Revision: 1.1 $ $Date: 2001/08/17 05:15:48 $ + * @version $Revision: 1.2 $ $Date: 2001/08/17 20:37:00 $ */ public class BaseContextTestCase extends TestCase { @@ -86,7 +86,7 @@ /** - * The digester instance we will be processing. + * The context instance we will be testing. */ protected Context context = null; 1.1 jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/BaseActivityTestCase.java Index: BaseActivityTestCase.java =================================================================== /* * $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 $ * * ==================================================================== * * 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.Scope; import org.apache.commons.workflow.Step; /** * <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/17 20:37:00 $ */ public class BaseActivityTestCase extends TestCase { // ----------------------------------------------------- Instance Variables /** * The digester instance we will be testing. */ protected Activity activity = null; // ----------------------------------------------------------- Constructors /** * Construct a new instance of this test case. * * @param name Name of the test case */ public BaseActivityTestCase(String name) { super(name); } // --------------------------------------------------- Overall Test Methods /** * Set up instance variables required by this test case. */ public void setUp() { activity = new BaseActivity(); } /** * Return the tests included in this test suite. */ public static Test suite() { return (new TestSuite(BaseActivityTestCase.class)); } /** * Tear down instance variables required by this test case. */ public void tearDown() { activity = null; } // ------------------------------------------------ Individual Test Methods /** * Test default properties upon creation time. */ public void testDefaultProperties() { assertNull("firstStep should be null", activity.getFirstStep()); assertNull("lastStep should be null", activity.getLastStep()); Step steps[] = activity.getSteps(); if (steps == null) assertNotNull("steps[] should be not null", steps); else assertEquals("steps[] should be zero length", 0, steps.length); } /** * Test adding a group of steps. */ public void testGroupSteps() { Step step0 = new TestStep("Step 0"); Step step1 = new TestStep("Step 1"); Step step2 = new TestStep("Step 2"); Step steps[] = new Step[] { step0, step1, step2 }; activity.setSteps(steps); assertEquals("step0 belongs to activity", step0.getActivity(), activity); assertEquals("step1 belongs to activity", step1.getActivity(), activity); assertEquals("step2 belongs to activity", step2.getActivity(), activity); assertEquals("firstStep should be step 0", step0, activity.getFirstStep()); assertEquals("lastStep should be step 2", step2, activity.getLastStep()); assertNull("step0 previous step should be null", step0.getPreviousStep()); assertEquals("step0 next step should be step 1", step1, step0.getNextStep()); assertEquals("step1 previous step should be step 0", step0, step1.getPreviousStep()); assertEquals("step1 next step should be step2", step2, step1.getNextStep()); assertEquals("step2 previous step should be step1", step1, step2.getPreviousStep()); assertNull("step2 next step should be null", step2.getNextStep()); steps = activity.getSteps(); assertEquals("steps.length should be 3", 3, steps.length); assertEquals("steps[0] should be step 0", step0, steps[0]); assertEquals("steps[1] should be step 1", step1, steps[1]); assertEquals("steps[2] should be step 2", step2, steps[2]); activity.clear(); assertNull("firstStep should be null", activity.getFirstStep()); assertNull("lastStep should be null", activity.getLastStep()); steps = activity.getSteps(); assertEquals("steps.length should be zero", 0, steps.length); } /** * Test adding individual steps. */ public void testIndividualSteps() { Step steps[] = null; Step step0 = new TestStep("Step 0"); activity.addStep(step0); assertEquals("step0 belongs to activity", step0.getActivity(), activity); assertEquals("firstStep should be step 0", step0, activity.getFirstStep()); assertEquals("lastStep should be step 0", step0, activity.getLastStep()); assertNull("step0 previous step should be null", step0.getPreviousStep()); assertNull("step0 next step should be null", step0.getNextStep()); steps = activity.getSteps(); assertEquals("steps.length should be 1", 1, steps.length); assertEquals("steps[0] should be step 0", step0, steps[0]); Step step1 = new TestStep("Step 1"); activity.addStep(step1); assertEquals("step1 belongs to activity", step1.getActivity(), activity); assertEquals("firstStep should be step 0", step0, activity.getFirstStep()); assertEquals("lastStep should be step 1", step1, activity.getLastStep()); assertNull("step0 previous step should be null", step0.getPreviousStep()); assertEquals("step0 next step should be step 1", step1, step0.getNextStep()); assertEquals("step1 previous step should be step 0", step0, step1.getPreviousStep()); assertNull("step1 next step should be null", step1.getNextStep()); steps = activity.getSteps(); assertEquals("steps.length should be 2", 2, steps.length); assertEquals("steps[0] should be step 0", step0, steps[0]); assertEquals("steps[1] should be step 1", step1, steps[1]); Step step2 = new TestStep("Step 2"); activity.addStep(step2); assertEquals("step2 belongs to activity", step2.getActivity(), activity); assertEquals("firstStep should be step 0", step0, activity.getFirstStep()); assertEquals("lastStep should be step 2", step2, activity.getLastStep()); assertNull("step0 previous step should be null", step0.getPreviousStep()); assertEquals("step0 next step should be step 1", step1, step0.getNextStep()); assertEquals("step1 previous step should be step 0", step0, step1.getPreviousStep()); assertEquals("step1 next step should be step2", step2, step1.getNextStep()); assertEquals("step2 previous step should be step1", step1, step2.getPreviousStep()); assertNull("step2 next step should be null", step2.getNextStep()); steps = activity.getSteps(); assertEquals("steps.length should be 3", 3, steps.length); assertEquals("steps[0] should be step 0", step0, steps[0]); assertEquals("steps[1] should be step 1", step1, steps[1]); assertEquals("steps[2] should be step 2", step2, steps[2]); activity.clear(); assertNull("firstStep should be null", activity.getFirstStep()); assertNull("lastStep should be null", activity.getLastStep()); steps = activity.getSteps(); assertEquals("steps.length should be zero", 0, steps.length); } } 1.1 jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/base/TestStep.java Index: TestStep.java =================================================================== /* * $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 $ * * ==================================================================== * * 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 org.apache.commons.workflow.Context; import org.apache.commons.workflow.StepException; /** * Test implementation of the <code>Step</code> interface. * * @author Craig R. McClanahan * @version $Revision: 1.1 $ $Date: 2001/08/17 20:37:00 $ */ public class TestStep extends BaseStep { // ----------------------------------------------------------- Constructors /** * Construct a TestStep instance with default property values (required * by the API contract for Step implementations. */ public TestStep() { super(); } /** * Construct a TestStep instance with the specified property values. * * @param id Identifier of this step */ public TestStep(String id) { this(id, false); } /** * Construct a TestStep instance with the specified property values. * * @param id Identifier of this step * @param fail Should we always throw a StepException? */ public TestStep(String id, boolean fail) { super(); setId(id); setFail(fail); } // ------------------------------------------------------------- Properties /** * Should our execute() method always fail and throw an exception? */ protected boolean fail = false; public boolean getFail() { return (this.fail); } public void setFail(boolean fail) { this.fail = fail; } // --------------------------------------------------------- Public Methods /** * Perform the executable actions related to this Step, in the context of * the specified Context. * * @param context The Context that is tracking our execution state * * @exception StepException if a processing error has occurred */ 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('/'); } // --------------------------------------------------------- Static Methods /** * An accumulator for execution trace results. */ protected static StringBuffer results = new StringBuffer(); /** * Clear the results accumulator. */ public static void clearResults() { results = new StringBuffer(); } /** * Return the accumulated execution results string. */ public static String getResults() { return (results.toString()); } }