craigmcc    01/08/21 20:37:10

  Modified:    workflow/src/test/org/apache/commons/workflow/core
                        CoreExecuteTestCase.java
  Log:
  Flesh out the tests for the remaining CORE steps:  get, put, and remove.
  
  Revision  Changes    Path
  1.3       +275 -4    
jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java
  
  Index: CoreExecuteTestCase.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CoreExecuteTestCase.java  2001/08/22 01:38:12     1.2
  +++ CoreExecuteTestCase.java  2001/08/22 03:37:10     1.3
  @@ -1,7 +1,7 @@
   /*
  - * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
 1.2 2001/08/22 01:38:12 craigmcc Exp $
  - * $Revision: 1.2 $
  - * $Date: 2001/08/22 01:38:12 $
  + * $Header: 
/home/cvs/jakarta-commons-sandbox/workflow/src/test/org/apache/commons/workflow/core/CoreExecuteTestCase.java,v
 1.3 2001/08/22 03:37:10 craigmcc Exp $
  + * $Revision: 1.3 $
  + * $Date: 2001/08/22 03:37:10 $
    *
    * ====================================================================
    *
  @@ -76,6 +76,7 @@
   import org.apache.commons.workflow.StepException;
   import org.apache.commons.workflow.base.BaseActivity;
   import org.apache.commons.workflow.base.BaseContext;
  +import org.apache.commons.workflow.base.BaseScope;
   
   
   /**
  @@ -83,7 +84,7 @@
    * implementations.</p>
    *
    * @author Craig R. McClanahan
  - * @version $Revision: 1.2 $ $Date: 2001/08/22 01:38:12 $
  + * @version $Revision: 1.3 $ $Date: 2001/08/22 03:37:10 $
    */
   
   public class CoreExecuteTestCase extends TestCase
  @@ -233,6 +234,274 @@
   
   
       /**
  +     * Test access to variables in various scopes.
  +     */
  +    public void testScopeAccess() {
  +
  +        // Configure an extra scope and put one object in each scope
  +        Scope extra = new BaseScope();
  +        context.addScope(Context.LOCAL_SCOPE + 1, "extra", extra);
  +        context.put("local0", "This is local0");
  +        context.put("extra0", "This is extra0", Context.LOCAL_SCOPE + 1);
  +
  +        // Configure the steps in this activity
  +        activity.addStep(new GetStep("01", "local0", "local", null));
  +        activity.addStep(new GetStep("02", "extra0", "extra", null));
  +        activity.addStep(new SuspendStep("03"));
  +        // NOTE: test will clear the stack
  +        activity.addStep(new GetStep("04", null, null, "local0"));
  +        activity.addStep(new GetStep("05", null, null, "extra/extra0"));
  +        activity.addStep(new SuspendStep("06"));
  +        // NOTE: test will clear the stack
  +        activity.addStep(new StringStep("07", "New local0"));
  +        activity.addStep(new PutStep("08", "local0", "local", null));
  +        activity.addStep(new StringStep("09", "New extra0"));
  +        activity.addStep(new PutStep("10", "extra0", "extra", null));
  +        activity.addStep(new GetStep("11", "local0", "local", null));
  +        activity.addStep(new GetStep("12", "extra0", "extra", null));
  +        activity.addStep(new SuspendStep("13"));
  +        // NOTE: test will clear the stack
  +        activity.addStep(new GetStep("14", null, null, "local0"));
  +        activity.addStep(new GetStep("15", null, null, "extra/extra0"));
  +        activity.addStep(new SuspendStep("16"));
  +        // NOTE: test will clear the stack
  +        activity.addStep(new RemoveStep("17", "local0", "local"));
  +        activity.addStep(new RemoveStep("18", "extra0", "extra"));
  +        activity.addStep(new GetStep("19", "local0", "local", null));
  +        // NOTE: previous step should throw StepException
  +        activity.addStep(new GetStep("20", "extra0", "local", null));
  +        // NOTE: previous step should throw StepException
  +        activity.addStep(new GetStep("21", null, null, "local0"));
  +        // NOTE: previous step should throw StepException
  +        activity.addStep(new GetStep("22", null, null, "extra/extra0"));
  +        // NOTE: previous step should throw StepException
  +
  +        // Execute the activity and validate results #1
  +        try {
  +            context.execute();
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(01)/afterStep(01)/" +
  +                         "beforeStep(02)/afterStep(02)/" +
  +                         "beforeStep(03)/afterStep(03)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'This is extra0'",
  +                         "This is extra0",
  +                         (String) context.pop());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'This is local0'",
  +                         "This is local0",
  +                         (String) context.pop());
  +            assertTrue("Stack is empty",
  +                       context.isEmpty());
  +            assertTrue("Context was suspended",
  +                       context.getSuspend());
  +        } catch (StepException e) {
  +            e.printStackTrace(System.out);
  +            if (e.getCause() != null) {
  +                System.out.println("ROOT CAUSE");
  +                e.getCause().printStackTrace(System.out);
  +            }
  +            fail("Threw StepException " + e);
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #2
  +        try {
  +            context.execute();
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(04)/afterStep(04)/" +
  +                         "beforeStep(05)/afterStep(05)/" +
  +                         "beforeStep(06)/afterStep(06)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'This is extra0'",
  +                         "This is extra0",
  +                         (String) context.pop());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'This is local0'",
  +                         "This is local0",
  +                         (String) context.pop());
  +            assertTrue("Stack is empty",
  +                       context.isEmpty());
  +            assertTrue("Context was suspended",
  +                       context.getSuspend());
  +        } catch (StepException e) {
  +            e.printStackTrace(System.out);
  +            if (e.getCause() != null) {
  +                System.out.println("ROOT CAUSE");
  +                e.getCause().printStackTrace(System.out);
  +            }
  +            fail("Threw StepException " + e);
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #3
  +        try {
  +            context.execute();
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(07)/afterStep(07)/" +
  +                         "beforeStep(08)/afterStep(08)/" +
  +                         "beforeStep(09)/afterStep(09)/" +
  +                         "beforeStep(10)/afterStep(10)/" +
  +                         "beforeStep(11)/afterStep(11)/" +
  +                         "beforeStep(12)/afterStep(12)/" +
  +                         "beforeStep(13)/afterStep(13)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'New extra0'",
  +                         "New extra0",
  +                         (String) context.pop());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'New local0'",
  +                         "New local0",
  +                         (String) context.pop());
  +            assertTrue("Stack is empty",
  +                       context.isEmpty());
  +            assertTrue("Context was suspended",
  +                       context.getSuspend());
  +        } catch (StepException e) {
  +            e.printStackTrace(System.out);
  +            if (e.getCause() != null) {
  +                System.out.println("ROOT CAUSE");
  +                e.getCause().printStackTrace(System.out);
  +            }
  +            fail("Threw StepException " + e);
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #4
  +        try {
  +            context.execute();
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(14)/afterStep(14)/" +
  +                         "beforeStep(15)/afterStep(15)/" +
  +                         "beforeStep(16)/afterStep(16)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'New extra0'",
  +                         "New extra0",
  +                         (String) context.pop());
  +            assertTrue("Stack is not empty",
  +                       !context.isEmpty());
  +            assertEquals("Popped value is 'New local0'",
  +                         "New local0",
  +                         (String) context.pop());
  +            assertTrue("Stack is empty",
  +                       context.isEmpty());
  +            assertTrue("Context was suspended",
  +                       context.getSuspend());
  +        } catch (StepException e) {
  +            e.printStackTrace(System.out);
  +            if (e.getCause() != null) {
  +                System.out.println("ROOT CAUSE");
  +                e.getCause().printStackTrace(System.out);
  +            }
  +            fail("Threw StepException " + e);
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #5
  +        try {
  +            context.execute();
  +            fail("Should have thrown StepException");
  +        } catch (StepException e) {
  +            // Expected result
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(17)/afterStep(17)/" +
  +                         "beforeStep(18)/afterStep(18)/" +
  +                         "beforeStep(19)/afterStep(19)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Context was not suspended",
  +                       !context.getSuspend());
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #6
  +        try {
  +            context.execute();
  +            fail("Should have thrown StepException");
  +        } catch (StepException e) {
  +            // Expected result
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(20)/afterStep(20)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Context was not suspended",
  +                       !context.getSuspend());
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #7
  +        try {
  +            context.execute();
  +            fail("Should have thrown StepException");
  +        } catch (StepException e) {
  +            // Expected result
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(21)/afterStep(21)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Context was not suspended",
  +                       !context.getSuspend());
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +        // Execute the activity and validate results #8
  +        try {
  +            context.execute();
  +            fail("Should have thrown StepException");
  +        } catch (StepException e) {
  +            // Expected result
  +            assertEquals("Trail contents",
  +                         "beforeActivity()/" +
  +                         "beforeStep(22)/afterStep(22)/" +
  +                         "afterActivity()/",
  +                         trail.toString());
  +            assertTrue("Context was not suspended",
  +                       !context.getSuspend());
  +        } catch (Throwable e) {
  +            e.printStackTrace();
  +            fail("Threw exception " + e);
  +        }
  +
  +    }
  +
  +
  +    /**
        * Simplest possible activity execution.
        */
       public void testSimplestPossible() {
  @@ -342,11 +611,13 @@
           trail.append("afterStep(");
           trail.append(event.getStep().getId());
           trail.append(")");
  +        /*
           StepException exception = event.getException();
           if (exception != null) {
               trail.append("-");
               trail.append(exception.toString());
           }
  +        */
           trail.append("/");
   
       }
  
  
  

Reply via email to