1   /*$Id: ForSingletonFeatureTest.java,v 1.1 2004/08/05 14:38:30 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.applications.beans.v1.cea.castor.types.ExecutionPhase;
14  import org.astrogrid.workflow.beans.v1.For;
15  import org.astrogrid.workflow.beans.v1.Script;
16  import org.astrogrid.workflow.beans.v1.Set;
17  import org.astrogrid.workflow.beans.v1.Workflow;
18  import org.astrogrid.workflow.beans.v1.execution.StepExecutionRecord;
19  
20  /***
21   * @author Noel Winstanley nw@jb.man.ac.uk 05-Aug-2004
22   *
23   */
24  public class ForSingletonFeatureTest extends AbstractTestForFeature {
25  
26      /*** Construct a new ForSingletonFeatureTest
27       * @param name
28       */
29      public ForSingletonFeatureTest(String name) {
30          super(name);
31      }
32  
33      /***
34       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#buildWorkflow()
35       */
36      protected Workflow buildWorkflow() {
37          Workflow wf = super.createMinimalWorkflow();
38          Set acc = new Set();
39          acc.setVar("acc");
40          acc.setValue("${0}");
41          wf.getSequence().addActivity(acc);
42          
43          For f = new For();
44          f.setVar("i");
45          f.setItems("${[1]}");
46          
47          Script sc = new Script();
48          sc.setBody("acc = acc + i");
49          f.setActivity(sc);
50          
51          wf.getSequence().addActivity(f);
52          
53          Script end = new Script();
54          end.setBody("print (acc == 1)"); 
55          wf.getSequence().addActivity(end);
56          
57          return wf;
58      }
59  
60      /***
61       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
62       */
63      protected void verifyWorkflow(Workflow result) {
64          assertWorkflowCompleted(result);
65          Script body = (Script)((For)result.getSequence().getActivity(1)).getActivity();
66          assertEquals(1,body.getStepExecutionRecordCount());
67          for (int i = 0; i < body.getStepExecutionRecordCount(); i++) {
68              StepExecutionRecord rec = body.getStepExecutionRecord(i);
69              assertEquals(ExecutionPhase.COMPLETED,rec.getStatus());
70              assertTrue(rec.getMessageCount() > 0);        
71          }
72          
73          Script end = (Script)result.getSequence().getActivity(2);
74          assertScriptCompletedWithMessage(end,"true");        
75      }
76  
77  
78  }
79  
80  
81  /* 
82  $Log: ForSingletonFeatureTest.java,v $
83  Revision 1.1  2004/08/05 14:38:30  nw
84  tests for sequential for construct
85   
86  */