1   /*$Id: IfThenTrueFeatureTest.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.If;
14  import org.astrogrid.workflow.beans.v1.Script;
15  import org.astrogrid.workflow.beans.v1.Set;
16  import org.astrogrid.workflow.beans.v1.Then;
17  import org.astrogrid.workflow.beans.v1.Workflow;
18  
19  /*** Test if statement, when no else, and test evaluates to true.
20   * @author Noel Winstanley nw@jb.man.ac.uk 05-Aug-2004
21   *
22   */
23  public class IfThenTrueFeatureTest extends AbstractTestForFeature {
24  
25      /*** Construct a new IfThenTrueFeatureTest
26       * @param name
27       */
28      public IfThenTrueFeatureTest(String name) {
29          super(name);
30      }
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          Script sc = new Script();
47          sc.setBody("x=!x;"); // check we can access variables defined outside.        
48          then.setActivity(sc);
49          
50          Script endScript = new Script();
51          endScript.setBody("print (!x)"); // check we can see variables defined within if block.
52          
53          wf.getSequence().addActivity(x);
54          wf.getSequence().addActivity(i);
55          wf.getSequence().addActivity(endScript);
56          return wf;
57      }
58  
59      /***
60       * @see org.astrogrid.jes.jobscheduler.impl.groovy.AbstractTestForFeature#verifyWorkflow(org.astrogrid.workflow.beans.v1.Workflow)
61       */
62      protected void verifyWorkflow(Workflow result) {
63          assertWorkflowCompleted(result);
64          Script end = (Script)result.getSequence().getActivity(2);
65          assertScriptCompletedWithMessage(end,"true");
66      }
67  
68  }
69  
70  
71  /* 
72  $Log: IfThenTrueFeatureTest.java,v $
73  Revision 1.2  2004/12/09 16:39:12  clq2
74  nww_jes_panic
75  
76  Revision 1.1.76.1  2004/12/09 14:42:54  nw
77  made more robust.
78  still got looping bug though.
79  
80  Revision 1.1  2004/08/05 09:59:46  nw
81  tests for if construct
82   
83  */