1   /*$Id: IfThenElseTrueFeatureTest.java,v 1.2 2004/12/09 16:39:12 clq2 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.Else;
14  import org.astrogrid.workflow.beans.v1.If;
15  import org.astrogrid.workflow.beans.v1.Script;
16  import org.astrogrid.workflow.beans.v1.Set;
17  import org.astrogrid.workflow.beans.v1.Then;
18  import org.astrogrid.workflow.beans.v1.Workflow;
19  
20  /*** test if statement, when test is true, and there are both then and else branches.
21   * @author Noel Winstanley nw@jb.man.ac.uk 05-Aug-2004
22   *
23   */
24  public class IfThenElseTrueFeatureTest extends AbstractTestForFeature {
25  
26      /*** Construct a new IfThenElseTrueFeatureTest
27       * @param name
28       */
29      public IfThenElseTrueFeatureTest(String name) {
30          super(name);
31      }
32      /***
33       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#buildWorkflow()
34       */
35      protected Workflow buildWorkflow() {
36          Workflow wf = super.createMinimalWorkflow();
37          Set x = new Set();
38          x.setVar("x");
39          x.setValue("${true}");
40          If i = new If();
41          i.setTest("${x}"); // don't need anything more complex - we knoow
42          
43          Then then = new Then();
44          i.setThen(then);
45          
46          Else el = new Else();
47          i.setElse(el);
48          
49          Script sc = new Script();
50          sc.setBody("x=!x;"); // check we can access variables defined outside.        
51          then.setActivity(sc);
52          
53          Script elScript = new Script();
54          elScript.setBody("print(x)");
55          el.setActivity(elScript);
56          
57          Script endScript = new Script();
58          endScript.setBody("print (!x )"); // check we can see variables defined within if block.
59          
60          wf.getSequence().addActivity(x);
61          wf.getSequence().addActivity(i);
62          wf.getSequence().addActivity(endScript);
63          return wf;
64      }
65  
66      /***
67       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
68       */
69      protected void verifyWorkflow(Workflow result) {
70          assertWorkflowCompleted(result);
71          Script end = (Script)result.getSequence().getActivity(2);
72          assertScriptCompletedWithMessage(end,"true");
73      }
74  
75  }
76  
77  
78  /* 
79  $Log: IfThenElseTrueFeatureTest.java,v $
80  Revision 1.2  2004/12/09 16:39:12  clq2
81  nww_jes_panic
82  
83  Revision 1.1.76.1  2004/12/09 14:42:54  nw
84  made more robust.
85  still got looping bug though.
86  
87  Revision 1.1  2004/08/05 09:59:46  nw
88  tests for if construct
89   
90  */