1
2
3
4
5
6
7
8
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
101
102
103
104
105
106
107
108
109
110
111
112
113