1   /*$Id: WhileMultipleFeatureTest.java,v 1.2 2004/12/09 16:39:12 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 WhileMultipleFeatureTest extends AbstractTestForFeature {
26  
27      /*** Construct a new WhileMultipleFeatureTest
28       * @param name
29       */
30      public WhileMultipleFeatureTest(String name) {
31          super(name);
32      }
33      protected Workflow buildWorkflow() {
34          Workflow wf = super.createMinimalWorkflow();
35          Set x = new Set();
36          x.setVar("x");
37          x.setValue("${10}");
38          wf.getSequence().addActivity(x);
39          
40          While w = new While();
41          w.setTest("${x > 0}");
42          wf.getSequence().addActivity(w);
43          
44          Sequence whileBody = new Sequence();
45          w.setActivity(whileBody);
46          
47          Script sc = new Script();
48          sc.setBody("x=x-1");
49          whileBody.addActivity(sc);
50  
51          
52          Script sc1 = new Script();
53          sc1.setBody("x=x+1");
54          whileBody.addActivity(sc1);
55          
56          
57          Script sc2 = new Script();
58          sc2.setBody("x=x-2");
59          whileBody.addActivity(sc2);        
60          
61          Script end = new Script();
62          end.setBody("print (x == 0)");
63          wf.getSequence().addActivity(end);
64          return wf;
65      }
66  
67      /***
68       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
69       */
70      protected void verifyWorkflow(Workflow result) {
71          assertWorkflowCompleted(result);
72          Script body = (Script)((Sequence)((While)result.getSequence().getActivity(1)).getActivity()).getActivity(2);
73  
74          assertEquals(5,body.getStepExecutionRecordCount());
75          for (int i = 0; i < body.getStepExecutionRecordCount(); i++) {
76              StepExecutionRecord rec = body.getStepExecutionRecord(i);
77              assertEquals(ExecutionPhase.COMPLETED,rec.getStatus());
78              assertTrue(rec.getMessageCount() > 0);        
79          }
80          
81          Script end = (Script)result.getSequence().getActivity(2);
82          assertScriptCompletedWithMessage(end,"true");
83      }
84  
85  }
86  
87  
88  /* 
89  $Log: WhileMultipleFeatureTest.java,v $
90  Revision 1.2  2004/12/09 16:39:12  clq2
91  nww_jes_panic
92  
93  Revision 1.1.2.1  2004/12/09 16:11:03  nw
94  fixed for and while loops
95   
96  */