1
2
3
4
5
6
7
8
9 package net.kwfgrid.gworkflowdl;
10
11 import junit.framework.Assert;
12 import junit.framework.Test;
13 import junit.framework.TestSuite;
14 import net.kwfgrid.gworkflowdl.structure.*;
15
16 import java.io.IOException;
17
18 /***
19 * a "realistic" looking createDataToken for grid workflow.
20 */
21 final class Example {
22
23 private Example() {
24 }
25
26 public static Workflow make() throws WorkflowFormatException {
27
28
29
30 Place begin = Factory.newPlace();
31 begin.setID("begin");
32
33
34
35
36
37
38
39 Token mm5j = TokenTest.createDataToken("grigftp:first.fraunhofer.de/lotto/mm5input.dat");
40
41 boolean test = true;
42 try {
43
44 begin.addToken(mm5j);
45 ;
46 } catch (CapacityException e) {
47 test = false;
48 }
49 Assert.assertTrue(test);
50
51 Place weatherModelOutput = Factory.newPlace();
52
53 try {
54
55 weatherModelOutput.setCapacity(4);
56 ;
57 } catch (CapacityException e) {
58 test = false;
59 }
60
61 weatherModelOutput.setID("weatherModelOutput");
62 GenericProperties gp = Factory.newProperties();
63 gp.put("key1", "val1");
64 gp.put("abrakadabra", "simsalabim");
65 weatherModelOutput.setProperties(gp);
66
67 Place end = Factory.newPlace();
68 end.setID("end");
69
70
71
72 OperationCandidate mm5_first = Factory.newOperationCandidate();
73 mm5_first.setType("gs");
74
75
76 mm5_first.setSelected(true);
77
78 OperationCandidate mm5_cyfronet = Factory.newOperationCandidate();
79 mm5_cyfronet.setType("gs");
80
81
82
83 OperationCandidate mm5_savba = Factory.newOperationCandidate();
84 mm5_savba.setType("gs");
85
86
87 mm5_savba.setResourceName("myWsdl");
88
89 OperationCandidate[] wsops = {mm5_first, mm5_cyfronet, mm5_savba};
90
91
92 OperationClass mm5 = Factory.newOperationClass();
93
94
95 mm5.setOperationCandidates(wsops);
96
97
98 Operation weatherModel = Factory.newOperation();
99
100
101 weatherModel.set(mm5);
102
103
104 Operation visualization = Factory.newOperation();
105
106
107
108 OperationCandidate pex0 = Factory.newOperationCandidate();
109
110 pex0.setType("commandLine");
111 pex0.setResourceName("cyrano");
112 pex0.setOperationName("Mac OS X");
113 pex0.setQuality(0.9f);
114 pex0.setSelected(true);
115
116 OperationCandidate pex1 = Factory.newOperationCandidate();
117
118 pex1.setType("ws");
119 pex1.setResourceName("bb");
120 pex1.setOperationName("linux");
121 pex1.setQuality(0.8f);
122
123 OperationClass pcex = Factory.newOperationClass();
124 pcex.setName("Hansi and Klausi software");
125
126
127 OperationCandidate[] pexs = {pex0, pex1};
128 pcex.setOperationCandidates(pexs);
129
130 visualization.set(pcex);
131
132
133 Transition weatherModelRun = Factory.newTransition();
134 weatherModelRun.setID("weatherModel");
135 weatherModelRun.setDescription("fine weather model");
136 weatherModelRun.setOperation(weatherModel);
137 weatherModelRun.addCondition("4711 == 4711");
138 weatherModelRun.addCondition("1 != 2");
139
140 Edge wine = Factory.newEdge();
141 wine.setPlace(begin);
142 wine.setExpression("input");
143 weatherModelRun.addInEdge(wine);
144
145 Edge woute = Factory.newEdge();
146 woute.setPlace(weatherModelOutput);
147 woute.setExpression("output");
148 weatherModelRun.addOutEdge(woute);
149
150
151 Transition visualizationRun = Factory.newTransition();
152 visualizationRun.getProperties().put("today", "tomorrow");
153 visualizationRun.setID("visualisation");
154 visualizationRun.setDescription("Visualisation of weather");
155 visualizationRun.setOperation(visualization);
156
157 Edge vine = Factory.newEdge();
158 vine.setPlace(weatherModelOutput);
159 vine.setExpression("input");
160 visualizationRun.addInEdge(vine);
161
162
163 Edge voute = Factory.newEdge();
164 voute.setPlace(end);
165 voute.setExpression("output");
166 visualizationRun.addOutEdge(voute);
167
168
169
170 Workflow wf = Factory.newWorkflow();
171 String[] os = new String[2];
172 os[0] = "anton";
173 os[1] = "berta";
174
175 wf.addPlace(begin);
176 wf.addPlace(weatherModelOutput);
177 wf.addPlace(end);
178 wf.addTransition(weatherModelRun);
179 wf.addTransition(visualizationRun);
180 wf.getProperties().put("gestern", "vorgestern und vorvorgestern");
181 wf.getProperties().put("heute", "morgen");
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202 return wf;
203 }
204 }
205
206 public final class WeatherForecast extends AbstractTestCase {
207
208 /***
209 * Create the test case
210 *
211 * @param testName name of the test case
212 */
213 public WeatherForecast(String testName) {
214 super(testName);
215 System.setProperty("gworkflowdl.xml.validation","true");
216 }
217
218 /***
219 * @return the suite of tests being tested
220 */
221 public static Test suite() {
222 return new TestSuite(WeatherForecast.class);
223 }
224
225 /***
226 * Rigourous Test :-)
227 */
228 public void testApp() throws WorkflowFormatException {
229
230 Workflow wf1 = Example.make();
231 boolean test = true;
232
233 String s1 = null;
234 try {
235 s1 = JdomString.workflow2string(wf1);
236 } catch (IOException e) {
237 test = false;
238 }
239 Assert.assertTrue(test);
240
241 System.out.println(s1);
242
243
244
245
246
247
248
249
250
251
252
253 Workflow wf2 = null;
254 try {
255 wf2 = JdomString.string2workflow(s1);
256
257
258
259
260
261
262
263
264
265 } catch (CapacityException e) {
266 test = false;
267
268 } catch (WorkflowFormatException e) {
269 e.printStackTrace();
270 test = false;
271 }
272 Assert.assertTrue(test);
273
274 String s2 = null;
275
276 try {
277 s2 = JdomString.workflow2string(wf2);
278 } catch (IOException e) {
279 test = false;
280 }
281 System.out.println(s2);
282
283 Assert.assertTrue(test);
284 Assert.assertEquals("workflow xml",s1,s2);
285
286 }
287 }