1   /*$Id: WhileNestedFeatureTest.java,v 1.3 2005/07/27 15:35:08 clq2 Exp $
2    * Created on 09-Dec-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.applications.beans.v1.cea.castor.types.ExecutionPhase;
14  import org.astrogrid.workflow.beans.v1.Script;
15  import org.astrogrid.workflow.beans.v1.Sequence;
16  import org.astrogrid.workflow.beans.v1.Set;
17  import org.astrogrid.workflow.beans.v1.While;
18  import org.astrogrid.workflow.beans.v1.Workflow;
19  import org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord;
20  
21  /***
22   * @author Noel Winstanley nw@jb.man.ac.uk 09-Dec-2004
23   *
24   */
25  public class WhileNestedFeatureTest extends AbstractTestForFeature {
26  
27      /*** Construct a new WhileNestedFeatureTest
28       * @param name
29       */
30      public WhileNestedFeatureTest(String name) {
31          super(name);
32      }
33  
34      /***
35       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#buildWorkflow()
36       */
37      protected Workflow buildWorkflow() {
38          Workflow wf = super.createMinimalWorkflow();
39          Set x = new Set();
40          x.setVar("x");
41          x.setValue("${10}");
42          wf.getSequence().addActivity(x);
43          
44          
45          While w = new While();
46          w.setTest("${x > 0}");
47          wf.getSequence().addActivity(w);
48          
49          Sequence seq = new Sequence();
50          w.setActivity(seq);
51          
52          Set y = new Set();
53          y.setVar("y");
54          y.setValue("${3}");
55          seq.addActivity(y);
56          
57          While w1 = new While();
58          w1.setTest("${y>0}");
59          seq.addActivity(w1);
60          
61          Script inner = new Script();
62          inner.setBody("y=y-1");
63          w1.setActivity(inner);
64          
65          
66          Script sc = new Script();
67          sc.setBody("x=x-1");
68          seq.addActivity(sc);
69  
70          
71          Script end = new Script();
72          end.setBody("print (x == 0 && y == 0)");
73          wf.getSequence().addActivity(end);
74          return wf;
75      }
76  
77      /***
78       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
79       */
80      protected void verifyWorkflow(Workflow result) {
81          assertWorkflowCompleted(result);
82          Sequence seq= (Sequence)((While)result.getSequence().getActivity(1)).getActivity();
83          Script outerBody = (Script)seq.getActivity(2);
84  
85          assertEquals(10,outerBody.getStepExecutionRecordCount());
86          assertAllScriptRunsCompleted(outerBody);
87          
88          Script innerBody = (Script)((While)seq.getActivity(1)).getActivity();
89          assertEquals(30,innerBody.getStepExecutionRecordCount());
90          assertAllScriptRunsCompleted(innerBody);        
91          
92          Script end = (Script)result.getSequence().getActivity(2);
93          assertScriptCompletedWithMessage(end,"true");
94      }
95  
96  }
97  
98  
99  /* 
100 $Log: WhileNestedFeatureTest.java,v $
101 Revision 1.3  2005/07/27 15:35:08  clq2
102 jes_nww_review_unit_tests
103 
104 Revision 1.2.70.1  2005/07/19 15:38:06  nw
105 fixed unit tests -100% pass rate now.
106 
107 Revision 1.2  2004/12/09 16:39:12  clq2
108 nww_jes_panic
109 
110 Revision 1.1.2.1  2004/12/09 16:11:03  nw
111 fixed for and while loops
112  
113 */