1   /*$Id: WhileOnceFeatureTest.java,v 1.1 2004/08/05 10:57:03 nw Exp $
2    * Created on 05-Aug-2004
3    *
4    * Copyright (C) AstroGrid. All rights reserved.
5    *
6    * This software is published under the terms of the AstroGrid 
7    * Software License version 1.2, a copy of which has been included 
8    * with this distribution in the LICENSE.txt file.  
9    *
10  **/
11  package org.astrogrid.jes.jobscheduler.impl.groovy;
12  
13  import org.astrogrid.workflow.beans.v1.Script;
14  import org.astrogrid.workflow.beans.v1.Set;
15  import org.astrogrid.workflow.beans.v1.While;
16  import org.astrogrid.workflow.beans.v1.Workflow;
17  
18  /*** test behaviour of the while loop.
19   * @author Noel Winstanley nw@jb.man.ac.uk 05-Aug-2004
20   *
21   */
22  public class WhileOnceFeatureTest extends AbstractTestForFeature {
23  
24      /*** Construct a new WhileTrueFeatureTest
25       * @param name
26       */
27      public WhileOnceFeatureTest(String name) {
28          super(name);
29      }
30      /***
31       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#buildWorkflow()
32       */
33      protected Workflow buildWorkflow() {
34          Workflow wf = super.createMinimalWorkflow();
35          Set x = new Set();
36          x.setVar("x");
37          x.setValue("${true}");
38          wf.getSequence().addActivity(x);
39          
40          While w = new While();
41          w.setTest("${x}");
42          Script sc = new Script();
43          sc.setBody("x=!x");
44          w.setActivity(sc);
45          wf.getSequence().addActivity(w);
46          
47          Script end = new Script();
48          end.setBody("print (!x)");
49          wf.getSequence().addActivity(end);
50          return wf;
51      }
52  
53      /***
54       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
55       */
56      protected void verifyWorkflow(Workflow result) {
57          assertWorkflowCompleted(result);
58          Script body = (Script)((While)result.getSequence().getActivity(1)).getActivity();
59          assertScriptCompleted(body);
60          assertEquals(1,body.getStepExecutionRecordCount());
61          
62          Script end = (Script)result.getSequence().getActivity(2);
63          assertScriptCompletedWithMessage(end,"true");
64      }
65  }
66  
67  
68  /* 
69  $Log: WhileOnceFeatureTest.java,v $
70  Revision 1.1  2004/08/05 10:57:03  nw
71  tests for while construct
72   
73  */