Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java @ 262:8b634333f935
merged gnv-artifacts/0.2
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:44 +0200 |
parents | 008709f79611 |
children | 251f16a083f8 |
comparison
equal
deleted
inserted
replaced
169:6cf73f5ea4a9 | 262:8b634333f935 |
---|---|
1 /** | |
2 * | |
3 */ | |
4 package de.intevation.gnv.artifacts; | |
5 | |
6 import java.io.ByteArrayInputStream; | |
7 import java.io.File; | |
8 import java.io.FileNotFoundException; | |
9 import java.io.FileOutputStream; | |
10 import java.io.IOException; | |
11 | |
12 import javax.xml.parsers.DocumentBuilder; | |
13 import javax.xml.parsers.DocumentBuilderFactory; | |
14 import javax.xml.parsers.ParserConfigurationException; | |
15 | |
16 import junit.framework.TestCase; | |
17 | |
18 import org.apache.log4j.BasicConfigurator; | |
19 import org.apache.log4j.Logger; | |
20 import org.w3c.dom.Document; | |
21 import org.xml.sax.SAXException; | |
22 | |
23 import de.intevation.artifactdatabase.Config; | |
24 import de.intevation.artifactdatabase.DefaultCallMeta; | |
25 import de.intevation.artifactdatabase.DefaultPreferredLocale; | |
26 import de.intevation.artifactdatabase.FactoryBootstrap; | |
27 import de.intevation.artifacts.Artifact; | |
28 import de.intevation.artifacts.ArtifactFactory; | |
29 import de.intevation.artifacts.CallContext; | |
30 import de.intevation.artifacts.CallMeta; | |
31 import de.intevation.artifacts.PreferredLocale; | |
32 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | |
33 import de.intevation.gnv.utils.ArtifactXMLUtilities; | |
34 | |
35 /** | |
36 * @author Tim Englich <tim.englich@intevation.de> | |
37 * | |
38 */ | |
39 public class GNVArtifactsTestCase extends TestCase { | |
40 | |
41 /** | |
42 * the logger, used to log exceptions and additonaly information | |
43 */ | |
44 private static Logger log = null; | |
45 | |
46 static { | |
47 BasicConfigurator.configure(); | |
48 log = Logger.getLogger(GNVArtifactContext.class); | |
49 } | |
50 | |
51 private String configurationDir = "doc/conf"; | |
52 | |
53 private FactoryBootstrap bootstrap = null; | |
54 | |
55 /** | |
56 * Constructor | |
57 * | |
58 * @param name | |
59 */ | |
60 public GNVArtifactsTestCase(String name) { | |
61 super(name); | |
62 } | |
63 | |
64 /** | |
65 * @see junit.framework.TestCase#setUp() | |
66 */ | |
67 protected void setUp() throws Exception { | |
68 log.debug("GNVArtifactsTestCase.setUp"); | |
69 super.setUp(); | |
70 log.info(Config.CONFIG_DIR + " ==> " + configurationDir); | |
71 System.setProperty(Config.CONFIG_DIR, configurationDir); | |
72 log.info("Bootstrap wird initialisiert."); | |
73 bootstrap = new FactoryBootstrap(); | |
74 bootstrap.boot(); | |
75 } | |
76 | |
77 public void testTimeSeriesArtifact() { | |
78 try { | |
79 log.debug("GNVArtifactsTestCase.testTimeSeriesArtifact"); | |
80 String artefactName = "fis_marnet"; | |
81 ArtifactFactory artifactFactory = this | |
82 .getArtifactFactory(artefactName); | |
83 assertNotNull(artifactFactory); | |
84 log.debug("TimeSeries-ArtifactFactory is available"); | |
85 Artifact artifact = artifactFactory.createArtifact( | |
86 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
87 assertNotNull(artifact); | |
88 log.debug("TimeSeries-Artifact is available"); | |
89 | |
90 CallContext cc = createCallContext(); | |
91 | |
92 // Erster Schritt | |
93 | |
94 Document describeDocument = this.readDocument("src/test/ressources/timeseries/timeseries_describe.xml"); | |
95 | |
96 int steps = 5; | |
97 | |
98 for (int i = 1; i <= steps; i++){ | |
99 | |
100 this.doNextStep( | |
101 artifact, | |
102 cc, | |
103 "src/test/ressources/timeseries/" + | |
104 "timeseries_step_0"+i+"_feed.xml", | |
105 "src/test/ressources/timeseries/" + | |
106 "timeseries_step_0"+i+"_advance.xml", | |
107 describeDocument); | |
108 } | |
109 | |
110 Document outputData = artifact.describe(describeDocument,cc); | |
111 FileOutputStream fos = null; | |
112 FileOutputStream fos2 = null; | |
113 FileOutputStream fos3 = null; | |
114 FileOutputStream fos4 = null; | |
115 try { | |
116 fos = new FileOutputStream("src/test/results/timeseries" | |
117 + System.currentTimeMillis() | |
118 + ".png"); | |
119 fos2 = new FileOutputStream("src/test/results/timeseries" | |
120 + System.currentTimeMillis() | |
121 + ".xml"); | |
122 fos3 = new FileOutputStream("src/test/results/timeseries" | |
123 + System.currentTimeMillis() | |
124 + ".csv"); | |
125 fos4 = new FileOutputStream("src/test/results/timeseries" | |
126 + System.currentTimeMillis() | |
127 + ".odv"); | |
128 | |
129 artifact.feed(this | |
130 .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), | |
131 cc); | |
132 artifact.out(this | |
133 .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_chart.xml"), | |
134 fos, cc); | |
135 artifact.out(this | |
136 .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml"), | |
137 fos2, cc); | |
138 artifact.out(this | |
139 .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_csv.xml"), | |
140 fos3, cc); | |
141 artifact.out(this | |
142 .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_odv.xml"), | |
143 fos4, cc); | |
144 } catch (Exception e) { | |
145 log.error(e, e); | |
146 fail(); | |
147 } finally { | |
148 try { | |
149 fos.flush(); | |
150 fos.close(); | |
151 } catch (Exception e) { | |
152 log.error(e, e); | |
153 } | |
154 } | |
155 } catch (Exception e) { | |
156 log.error(e, e); | |
157 fail(); | |
158 } | |
159 } | |
160 | |
161 /** | |
162 * @return | |
163 */ | |
164 private CallContext createCallContext() { | |
165 CallMeta callMeta = new DefaultCallMeta( | |
166 new PreferredLocale[] { new DefaultPreferredLocale("de_DE", | |
167 1.0f) }); | |
168 CallContext cc = new TestCallContext(bootstrap.getContext(), callMeta); | |
169 return cc; | |
170 } | |
171 | |
172 /** | |
173 * @param artifact | |
174 * @param cc | |
175 * @param describeDocument TODO | |
176 * @throws Exception | |
177 */ | |
178 private void doNextStep(Artifact artifact, CallContext cc, | |
179 String feedDocument, String advanceDocument, Document describeDocument) | |
180 throws Exception { | |
181 Document outputData = artifact.describe(describeDocument,cc); | |
182 // this.writeDocument2Log(outputData); | |
183 outputData = artifact.feed(this.readDocument(feedDocument), cc); | |
184 this.check4ExceptionReport(outputData); | |
185 outputData = artifact.advance(this.readDocument(advanceDocument), cc); | |
186 // this.writeDocument2Log(outputData); | |
187 this.check4ExceptionReport(outputData); | |
188 | |
189 } | |
190 | |
191 public void testTimeSeriesMeshArtifact() { | |
192 try { | |
193 log.debug("GNVArtifactsTestCase.testTimeSeriesMeshArtifact"); | |
194 String artefactName = "fis_modeldata"; | |
195 ArtifactFactory artifactFactory = this | |
196 .getArtifactFactory(artefactName); | |
197 assertNotNull(artifactFactory); | |
198 log.debug("TimeSeriesMesh-ArtifactFactory is available"); | |
199 Artifact artifact = artifactFactory.createArtifact( | |
200 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
201 assertNotNull(artifact); | |
202 log.debug("TimeSeriesMesh-Artifact is available"); | |
203 | |
204 CallContext cc = createCallContext(); | |
205 | |
206 Document describeDocument = this.readDocument("src/test/ressources/timeseries_mesh/timeseries_describe.xml"); | |
207 | |
208 int steps = 7; | |
209 | |
210 for (int i = 1; i <= steps; i++){ | |
211 this.doNextStep( | |
212 artifact, | |
213 cc, | |
214 "src/test/ressources/timeseries_mesh/" + | |
215 "timeseries_step_0"+i+"_feed.xml", | |
216 "src/test/ressources/timeseries_mesh/" + | |
217 "timeseries_step_0"+i+"_advance.xml", | |
218 describeDocument); | |
219 } | |
220 // Achter Schritt | |
221 Document outputData = artifact.describe(describeDocument,cc); | |
222 FileOutputStream fos = null; | |
223 FileOutputStream fos2 = null; | |
224 FileOutputStream fos3 = null; | |
225 FileOutputStream fos4 = null; | |
226 try { | |
227 fos = new FileOutputStream("src/test/results/timeseries_mesh" | |
228 + System.currentTimeMillis() | |
229 + ".png"); | |
230 fos2 = new FileOutputStream("src/test/results/timeseries_mesh" | |
231 + System.currentTimeMillis() | |
232 + ".xml"); | |
233 fos3 = new FileOutputStream("src/test/results/timeseries_mesh" | |
234 + System.currentTimeMillis() | |
235 + ".csv"); | |
236 fos4 = new FileOutputStream("src/test/results/timeseries_mesh" | |
237 + System.currentTimeMillis() | |
238 + ".odv"); | |
239 artifact | |
240 .feed( | |
241 this | |
242 .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_feed.xml"), | |
243 cc); | |
244 artifact | |
245 .out( | |
246 this | |
247 .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_statistics.xml"), | |
248 fos2, cc); | |
249 artifact | |
250 .out( | |
251 this | |
252 .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_chart.xml"), | |
253 fos, cc); | |
254 artifact | |
255 .out( | |
256 this | |
257 .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_csv.xml"), | |
258 fos3, cc); | |
259 artifact | |
260 .out( | |
261 this | |
262 .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_odv.xml"), | |
263 fos4, cc); | |
264 } catch (Exception e) { | |
265 log.error(e, e); | |
266 fail(); | |
267 } finally { | |
268 try { | |
269 fos.flush(); | |
270 fos.close(); | |
271 fos2.flush(); | |
272 fos2.close(); | |
273 fos3.flush(); | |
274 fos3.close(); | |
275 } catch (Exception e) { | |
276 log.error(e, e); | |
277 } | |
278 } | |
279 } catch (Exception e) { | |
280 log.error(e, e); | |
281 fail(); | |
282 } | |
283 } | |
284 | |
285 public void testVerticalProfileArtifact() { | |
286 try { | |
287 log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); | |
288 String artefactName = "fis_marnet"; | |
289 ArtifactFactory artifactFactory = this | |
290 .getArtifactFactory(artefactName); | |
291 assertNotNull(artifactFactory); | |
292 log.debug("VerticalProfile-ArtifactFactory is available"); | |
293 Artifact artifact = artifactFactory.createArtifact( | |
294 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
295 assertNotNull(artifact); | |
296 log.debug("VerticalProfile-Artifact is available"); | |
297 | |
298 CallContext cc = createCallContext(); | |
299 | |
300 Document describeDocument = this.readDocument("src/test/ressources/verticalprofile/verticalprofile_describe.xml"); | |
301 int steps = 5; | |
302 | |
303 for (int i = 1; i <= steps; i++){ | |
304 this.doNextStep( | |
305 artifact, | |
306 cc, | |
307 "src/test/ressources/verticalprofile/" + | |
308 "verticalprofile_step_0"+i+"_feed.xml", | |
309 "src/test/ressources/verticalprofile/" + | |
310 "verticalprofile_step_0"+i+"_advance.xml", | |
311 describeDocument); | |
312 } | |
313 | |
314 // Vierter Schritt | |
315 Document outputData = artifact.describe(describeDocument,cc); | |
316 FileOutputStream fos = null; | |
317 FileOutputStream fos2 = null; | |
318 FileOutputStream fos3 = null; | |
319 FileOutputStream fos4 = null; | |
320 try { | |
321 fos = new FileOutputStream("src/test/results/verticalprofile" | |
322 + System.currentTimeMillis() | |
323 + ".png"); | |
324 fos2 = new FileOutputStream("src/test/results/verticalprofile" | |
325 + System.currentTimeMillis() | |
326 + ".xml"); | |
327 fos3 = new FileOutputStream("src/test/results/verticalprofile" | |
328 + System.currentTimeMillis() | |
329 + ".csv"); | |
330 fos4 = new FileOutputStream("src/test/results/verticalprofile" | |
331 + System.currentTimeMillis() | |
332 + ".odv"); | |
333 artifact.feed(this.readDocument("src/test/ressources/" + | |
334 "verticalprofile/" + | |
335 "verticalprofile_step_06_feed.xml"), | |
336 cc); | |
337 artifact.out(this.readDocument("src/test/ressources/" + | |
338 "verticalprofile/" + | |
339 "verticalprofile_step_06_out_statistics.xml"), | |
340 fos2, cc); | |
341 artifact.out(this.readDocument("src/test/ressources/" + | |
342 "verticalprofile/" + | |
343 "verticalprofile_step_06_out_chart.xml"), | |
344 fos, cc); | |
345 artifact.out(this.readDocument("src/test/ressources/" + | |
346 "verticalprofile/" + | |
347 "verticalprofile_step_06_out_csv.xml"), | |
348 fos3, cc); | |
349 artifact.out(this.readDocument("src/test/ressources/" + | |
350 "verticalprofile/" + | |
351 "verticalprofile_step_06_out_odv.xml"), | |
352 fos4, cc); | |
353 } catch (Exception e) { | |
354 log.error(e, e); | |
355 fail(); | |
356 } finally { | |
357 try { | |
358 fos.flush(); | |
359 fos.close(); | |
360 fos2.flush(); | |
361 fos2.close(); | |
362 fos3.flush(); | |
363 fos3.close(); | |
364 fos4.flush(); | |
365 fos4.close(); | |
366 } catch (Exception e) { | |
367 log.error(e, e); | |
368 } | |
369 } | |
370 } catch (Exception e) { | |
371 log.error(e, e); | |
372 fail(); | |
373 } | |
374 } | |
375 | |
376 public void testVerticalProfileMeshArtifact() { | |
377 try { | |
378 log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); | |
379 String artefactName = "fis_modeldata"; | |
380 ArtifactFactory artifactFactory = this | |
381 .getArtifactFactory(artefactName); | |
382 assertNotNull(artifactFactory); | |
383 log.debug("VerticalProfile-ArtifactFactory is available"); | |
384 Artifact artifact = artifactFactory.createArtifact( | |
385 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
386 assertNotNull(artifact); | |
387 log.debug("VerticalProfile-Artifact is available"); | |
388 | |
389 CallContext cc = createCallContext(); | |
390 Document describeDocument = this.readDocument("src/test/ressources/" + | |
391 "verticalprofile_mesh/" + | |
392 "verticalprofile_describe.xml"); | |
393 | |
394 int steps = 9; | |
395 | |
396 for (int i = 1; i <= steps; i++){ | |
397 this.doNextStep( | |
398 artifact, | |
399 cc, | |
400 "src/test/ressources/verticalprofile_mesh/" + | |
401 "verticalprofile_step_0"+i+"_feed.xml", | |
402 "src/test/ressources/verticalprofile_mesh/" + | |
403 "verticalprofile_step_0"+i+"_advance.xml", | |
404 describeDocument); | |
405 } | |
406 // 10. Schritt | |
407 Document outputData = artifact.describe(describeDocument,cc); | |
408 FileOutputStream fos = null; | |
409 FileOutputStream fos2 = null; | |
410 FileOutputStream fos3 = null; | |
411 FileOutputStream fos4 = null; | |
412 try { | |
413 fos = new FileOutputStream( | |
414 "src/test/results/verticalprofile_mesh" | |
415 + System.currentTimeMillis() + ".png"); | |
416 fos2 = new FileOutputStream( | |
417 "src/test/results/verticalprofile_mesh" | |
418 + System.currentTimeMillis() + ".xml"); | |
419 fos3 = new FileOutputStream( | |
420 "src/test/results/verticalprofile_mesh" | |
421 + System.currentTimeMillis() + ".csv"); | |
422 fos4 = new FileOutputStream( | |
423 "src/test/results/verticalprofile_mesh" | |
424 + System.currentTimeMillis() + ".odv"); | |
425 artifact.feed(this.readDocument("src/test/ressources/" + | |
426 "verticalprofile_mesh/" + | |
427 "verticalprofile_step_10_feed.xml"), | |
428 cc); | |
429 artifact.out(this.readDocument("src/test/ressources/" + | |
430 "verticalprofile_mesh/" + | |
431 "verticalprofile_step_10_out_statistics.xml"), | |
432 fos2, cc); | |
433 artifact.out(this.readDocument("src/test/ressources/" + | |
434 "verticalprofile_mesh/" + | |
435 "verticalprofile_step_10_out_chart.xml"), | |
436 fos, cc); | |
437 artifact.out(this.readDocument("src/test/ressources/" + | |
438 "verticalprofile_mesh/" + | |
439 "verticalprofile_step_10_out_csv.xml"), | |
440 fos3, cc); | |
441 artifact.out(this.readDocument("src/test/ressources/" + | |
442 "verticalprofile_mesh/" + | |
443 "verticalprofile_step_10_out_odv.xml"), | |
444 fos4, cc); | |
445 } catch (Exception e) { | |
446 log.error(e, e); | |
447 fail(); | |
448 } finally { | |
449 try { | |
450 fos.flush(); | |
451 fos.close(); | |
452 fos2.flush(); | |
453 fos2.close(); | |
454 fos3.flush(); | |
455 fos3.close(); | |
456 fos4.flush(); | |
457 fos4.close(); | |
458 } catch (Exception e) { | |
459 log.error(e, e); | |
460 } | |
461 } | |
462 } catch (Exception e) { | |
463 log.error(e, e); | |
464 fail(); | |
465 } | |
466 } | |
467 | |
468 public void testVerticalProfileInstantaneousPointArtifact() { | |
469 try { | |
470 log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); | |
471 String artefactName = "fis_bsh_ctd"; | |
472 ArtifactFactory artifactFactory = this | |
473 .getArtifactFactory(artefactName); | |
474 assertNotNull(artifactFactory); | |
475 log.debug("VerticalProfile-ArtifactFactory is available"); | |
476 Artifact artifact = artifactFactory.createArtifact( | |
477 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
478 assertNotNull(artifact); | |
479 log.debug("VerticalProfile-Artifact is available"); | |
480 | |
481 CallContext cc = createCallContext(); | |
482 Document describeDocument = this.readDocument("src/test/ressources/verticalprofile_instantaneouspoint/verticalprofile_describe.xml"); | |
483 | |
484 int steps = 4; | |
485 | |
486 for (int i = 1; i <= steps; i++){ | |
487 this.doNextStep( | |
488 artifact, | |
489 cc, | |
490 "src/test/ressources/verticalprofile_instantaneouspoint/" + | |
491 "verticalprofile_step_0"+i+"_feed.xml", | |
492 "src/test/ressources/verticalprofile_instantaneouspoint/" + | |
493 "verticalprofile_step_0"+i+"_advance.xml", | |
494 describeDocument); | |
495 } | |
496 | |
497 // Vierter Schritt | |
498 Document outputData = artifact.describe(describeDocument,cc); | |
499 FileOutputStream fos = null; | |
500 FileOutputStream fos2 = null; | |
501 FileOutputStream fos3 = null; | |
502 FileOutputStream fos4 = null; | |
503 try { | |
504 fos = new FileOutputStream( | |
505 "src/test/results/verticalprofile_instantaneouspoint" | |
506 + System.currentTimeMillis() + ".png"); | |
507 fos2 = new FileOutputStream( | |
508 "src/test/results/verticalprofile_instantaneouspoint" | |
509 + System.currentTimeMillis() + ".xml"); | |
510 fos3 = new FileOutputStream( | |
511 "src/test/results/verticalprofile_instantaneouspoint" | |
512 + System.currentTimeMillis() + ".csv"); | |
513 fos4 = new FileOutputStream( | |
514 "src/test/results/verticalprofile_instantaneouspoint" | |
515 + System.currentTimeMillis() + ".odv"); | |
516 artifact.feed(this.readDocument("src/test/ressources/" + | |
517 "verticalprofile_instantaneouspoint/" + | |
518 "verticalprofile_step_05_feed.xml"), | |
519 cc); | |
520 artifact.out(this.readDocument("src/test/ressources/" + | |
521 "verticalprofile_instantaneouspoint/" + | |
522 "verticalprofile_step_05_out_statistics.xml"), | |
523 fos2, cc); | |
524 artifact.out(this.readDocument("src/test/ressources/" + | |
525 "verticalprofile_instantaneouspoint/" + | |
526 "verticalprofile_step_05_out_chart.xml"), | |
527 fos, cc); | |
528 artifact.out(this.readDocument("src/test/ressources/" + | |
529 "verticalprofile_instantaneouspoint/" + | |
530 "verticalprofile_step_05_out_csv.xml"), | |
531 fos3, cc); | |
532 artifact.out(this.readDocument("src/test/ressources/" + | |
533 "verticalprofile_instantaneouspoint/" + | |
534 "verticalprofile_step_05_out_odv.xml"), | |
535 fos4, cc); | |
536 } catch (Exception e) { | |
537 log.error(e, e); | |
538 fail(); | |
539 } finally { | |
540 try { | |
541 fos.flush(); | |
542 fos.close(); | |
543 fos2.flush(); | |
544 fos2.close(); | |
545 fos3.flush(); | |
546 fos3.close(); | |
547 } catch (Exception e) { | |
548 log.error(e, e); | |
549 } | |
550 } | |
551 } catch (Exception e) { | |
552 log.error(e, e); | |
553 fail(); | |
554 } | |
555 } | |
556 | |
557 public void testHorizontalProfileInstantaneousPointArtifact() { | |
558 try { | |
559 log.debug("GNVArtifactsTestCase." + | |
560 "testHorizontalProfileInstantaneousPointArtifact"); | |
561 String artefactName = "fis_delphin"; | |
562 ArtifactFactory artifactFactory = this | |
563 .getArtifactFactory(artefactName); | |
564 assertNotNull(artifactFactory); | |
565 log.debug("VerticalProfile-ArtifactFactory is available"); | |
566 Artifact artifact = artifactFactory.createArtifact( | |
567 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
568 assertNotNull(artifact); | |
569 log.debug("VerticalProfile-Artifact is available"); | |
570 | |
571 CallContext cc = createCallContext(); | |
572 Document describeDocument = this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_describe.xml"); | |
573 | |
574 int steps = 6; | |
575 | |
576 for (int i = 0; i < steps; i++){ | |
577 | |
578 this.doNextStep( | |
579 artifact, | |
580 cc, | |
581 "src/test/ressources/horizontalProfile_instantaneouspoint/" + | |
582 "horizontalprofile_step_0"+i+"_feed.xml", | |
583 "src/test/ressources/horizontalProfile_instantaneouspoint/" + | |
584 "horizontalprofile_step_0"+i+"_advance.xml", | |
585 describeDocument); | |
586 } | |
587 | |
588 Document outputData = artifact.describe(describeDocument, cc); | |
589 FileOutputStream fos = null; | |
590 FileOutputStream fos2 = null; | |
591 FileOutputStream fos3 = null; | |
592 FileOutputStream fos4 = null; | |
593 try { | |
594 fos = new FileOutputStream( | |
595 "src/test/results/horizontalprofile_instantaneouspoint" | |
596 + System.currentTimeMillis() + ".png"); | |
597 fos2 = new FileOutputStream( | |
598 "src/test/results/horizontalprofile_instantaneouspoint" | |
599 + System.currentTimeMillis() + ".xml"); | |
600 fos3 = new FileOutputStream( | |
601 "src/test/results/horizontalprofile_instantaneouspoint" | |
602 + System.currentTimeMillis() + ".csv"); | |
603 fos4 = new FileOutputStream( | |
604 "src/test/results/horizontalprofile_instantaneouspoint" | |
605 + System.currentTimeMillis() + ".odv"); | |
606 artifact.feed(this.readDocument("src/test/ressources/" + | |
607 "horizontalProfile_instantaneouspoint/" + | |
608 "horizontalprofile_step_06_feed.xml"), | |
609 cc); | |
610 artifact.out(this.readDocument("src/test/ressources/" + | |
611 "horizontalProfile_instantaneouspoint/" + | |
612 "horizontalprofile_step_06_out_statistics.xml"), | |
613 fos2,cc); | |
614 artifact.out(this.readDocument("src/test/ressources/" + | |
615 "horizontalProfile_instantaneouspoint/" + | |
616 "horizontalprofile_step_06_out_chart.xml"), | |
617 fos,cc); | |
618 artifact.out(this.readDocument("src/test/ressources/" + | |
619 "horizontalProfile_instantaneouspoint/" + | |
620 "horizontalprofile_step_06_out_csv.xml"), | |
621 fos3,cc); | |
622 artifact.out(this.readDocument("src/test/ressources/" + | |
623 "horizontalProfile_instantaneouspoint/" + | |
624 "horizontalprofile_step_06_out_odv.xml"), | |
625 fos4,cc); | |
626 } catch (Exception e) { | |
627 log.error(e, e); | |
628 fail(); | |
629 } finally { | |
630 try { | |
631 fos.flush(); | |
632 fos.close(); | |
633 fos2.flush(); | |
634 fos2.close(); | |
635 fos3.flush(); | |
636 fos3.close(); | |
637 } catch (Exception e) { | |
638 log.error(e, e); | |
639 } | |
640 } | |
641 } catch (Exception e) { | |
642 log.error(e, e); | |
643 fail(); | |
644 } | |
645 } | |
646 | |
647 public void testHorizontalProfileMeshPointArtifact() { | |
648 try { | |
649 log.debug("GNVArtifactsTestCase." + | |
650 "testHorizontalProfileInstantaneousPointArtifact"); | |
651 String artefactName = "fis_modeldata"; | |
652 ArtifactFactory artifactFactory = this | |
653 .getArtifactFactory(artefactName); | |
654 assertNotNull(artifactFactory); | |
655 log.debug("VerticalProfile-ArtifactFactory is available"); | |
656 Artifact artifact = artifactFactory.createArtifact( | |
657 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
658 assertNotNull(artifact); | |
659 log.debug("VerticalProfile-Artifact is available"); | |
660 | |
661 CallContext cc = createCallContext(); | |
662 Document describeDocument = this.readDocument("src/test/ressources/horizontalProfile_mesh/horizontalprofile_describe.xml"); | |
663 | |
664 int steps = 9; | |
665 | |
666 for (int i = 1; i <= steps; i++){ | |
667 | |
668 this.doNextStep( | |
669 artifact, | |
670 cc, | |
671 "src/test/ressources/horizontalProfile_mesh/" + | |
672 "horizontalprofile_step_0"+i+"_feed.xml", | |
673 "src/test/ressources/horizontalProfile_mesh/" + | |
674 "horizontalprofile_step_0"+i+"_advance.xml", | |
675 describeDocument); | |
676 } | |
677 | |
678 Document outputData = artifact.describe(describeDocument,cc); | |
679 FileOutputStream fos = null; | |
680 FileOutputStream fos2 = null; | |
681 FileOutputStream fos3 = null; | |
682 FileOutputStream fos4 = null; | |
683 try { | |
684 fos = new FileOutputStream( | |
685 "src/test/results/horizontalProfile_mesh" | |
686 + System.currentTimeMillis() + ".png"); | |
687 fos2 = new FileOutputStream( | |
688 "src/test/results/horizontalProfile_mesh" | |
689 + System.currentTimeMillis() + ".xml"); | |
690 fos3 = new FileOutputStream( | |
691 "src/test/results/horizontalProfile_mesh" | |
692 + System.currentTimeMillis() + ".csv"); | |
693 fos4 = new FileOutputStream( | |
694 "src/test/results/horizontalProfile_mesh" | |
695 + System.currentTimeMillis() + ".odv"); | |
696 artifact.feed(this.readDocument("src/test/ressources/" + | |
697 "horizontalProfile_mesh/" + | |
698 "horizontalprofile_step_10_feed.xml"), | |
699 cc); | |
700 artifact.out(this.readDocument("src/test/ressources/" + | |
701 "horizontalProfile_mesh/" + | |
702 "horizontalprofile_step_10_out_statistics.xml"), | |
703 fos2, cc); | |
704 artifact.out(this.readDocument("src/test/ressources/" + | |
705 "horizontalProfile_mesh/" + | |
706 "horizontalprofile_step_10_out_chart.xml"), | |
707 fos, cc); | |
708 artifact.out(this.readDocument("src/test/ressources/" + | |
709 "horizontalProfile_mesh/" + | |
710 "horizontalprofile_step_10_out_csv.xml"), | |
711 fos3, cc); | |
712 artifact.out(this.readDocument("src/test/ressources/" + | |
713 "horizontalProfile_mesh/" + | |
714 "horizontalprofile_step_10_out_odv.xml"), | |
715 fos4, cc); | |
716 } catch (Exception e) { | |
717 log.error(e, e); | |
718 fail(); | |
719 } finally { | |
720 try { | |
721 fos.flush(); | |
722 fos.close(); | |
723 fos2.flush(); | |
724 fos2.close(); | |
725 fos3.flush(); | |
726 fos3.close(); | |
727 fos4.flush(); | |
728 fos4.close(); | |
729 } catch (Exception e) { | |
730 log.error(e, e); | |
731 } | |
732 } | |
733 } catch (Exception e) { | |
734 log.error(e, e); | |
735 fail(); | |
736 } | |
737 } | |
738 | |
739 public void testHorizontalCrossSectionMeshArtifact() { | |
740 try { | |
741 log.debug("GNVArtifactsTestCase.testHorizontalCrossSectionMeshArtifact"); | |
742 String artefactName = "fis_modeldata"; | |
743 ArtifactFactory artifactFactory = this | |
744 .getArtifactFactory(artefactName); | |
745 assertNotNull(artifactFactory); | |
746 log.debug("HorizontalCrossSectionMesh-ArtifactFactory is available"); | |
747 Artifact artifact = artifactFactory.createArtifact( | |
748 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
749 assertNotNull(artifact); | |
750 log.debug("HorizontalCrossSectionMesh-Artifact is available"); | |
751 | |
752 CallContext cc = createCallContext(); | |
753 Document describeDocument = this.readDocument("src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_describe.xml"); | |
754 int steps = 5; | |
755 | |
756 for (int i = 1; i <= steps; i++){ | |
757 this.doNextStep( | |
758 artifact, | |
759 cc, | |
760 "src/test/ressources/horizontalcrosssection_mesh/" + | |
761 "horizontalcrosssection_step_0"+i+"_feed.xml", | |
762 "src/test/ressources/horizontalcrosssection_mesh/" + | |
763 "horizontalcrosssection_step_0"+i+"_advance.xml", | |
764 describeDocument); | |
765 } | |
766 | |
767 Document outputData = artifact.describe(describeDocument,cc); | |
768 FileOutputStream fos = null; | |
769 FileOutputStream fos2 = null; | |
770 FileOutputStream fos3 = null; | |
771 try { | |
772 fos = new FileOutputStream( | |
773 "src/test/results/horizontalcrosssection_mesh" | |
774 + System.currentTimeMillis() + ".png"); | |
775 | |
776 fos2 = new FileOutputStream( | |
777 "src/test/results/horizontalcrosssection_mesh" | |
778 + System.currentTimeMillis() + ".csv"); | |
779 fos3 = new FileOutputStream( | |
780 "src/test/results/horizontalcrosssection_mesh" | |
781 + System.currentTimeMillis() + ".odv"); | |
782 artifact.feed(this.readDocument("src/test/ressources/" + | |
783 "horizontalcrosssection_mesh/" + | |
784 "horizontalcrosssection_step_06_feed.xml"), | |
785 cc); | |
786 artifact.out(this.readDocument("src/test/ressources/" + | |
787 "horizontalcrosssection_mesh/" + | |
788 "horizontalcrosssection_step_06_out_chart.xml"), | |
789 fos, cc); | |
790 artifact.out(this.readDocument("src/test/ressources/" + | |
791 "horizontalcrosssection_mesh/" + | |
792 "horizontalcrosssection_step_06_out_csv.xml"), | |
793 fos2,cc); | |
794 artifact.out(this.readDocument("src/test/ressources/" + | |
795 "horizontalcrosssection_mesh/" + | |
796 "horizontalcrosssection_step_06_out_odv.xml"), | |
797 fos3,cc); | |
798 } catch (Exception e) { | |
799 log.error(e, e); | |
800 fail(); | |
801 } finally { | |
802 try { | |
803 fos.flush(); | |
804 fos.close(); | |
805 fos2.flush(); | |
806 fos2.close(); | |
807 fos3.flush(); | |
808 fos3.close(); | |
809 } catch (Exception e) { | |
810 log.error(e, e); | |
811 } | |
812 } | |
813 } catch (Exception e) { | |
814 log.error(e, e); | |
815 fail(); | |
816 } | |
817 } | |
818 | |
819 public void testVerticalCrossSectionMeshArtifact() { | |
820 try { | |
821 log.debug("GNVArtifactsTestCase." + | |
822 "testHVerticalCrossSectionMeshArtifact"); | |
823 String artefactName = "fis_modeldata"; | |
824 ArtifactFactory artifactFactory = this | |
825 .getArtifactFactory(artefactName); | |
826 assertNotNull(artifactFactory); | |
827 log.debug("VerticalProfile-ArtifactFactory is available"); | |
828 Artifact artifact = artifactFactory.createArtifact( | |
829 "" + System.currentTimeMillis(), bootstrap.getContext()); | |
830 assertNotNull(artifact); | |
831 log.debug("VerticalProfile-Artifact is available"); | |
832 | |
833 CallContext cc = createCallContext(); | |
834 Document describeDocument = this.readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_describe.xml"); | |
835 | |
836 int steps = 7; | |
837 | |
838 for (int i = 1; i <= steps; i++){ | |
839 | |
840 this.doNextStep( | |
841 artifact, | |
842 cc, | |
843 "src/test/ressources/verticalcrosssection_mesh/" + | |
844 "verticalcrosssection_step_0"+i+"_feed.xml", | |
845 "src/test/ressources/verticalcrosssection_mesh/" + | |
846 "verticalcrosssection_step_0"+i+"_advance.xml", | |
847 describeDocument); | |
848 } | |
849 | |
850 Document outputData = artifact.describe(describeDocument,cc); | |
851 FileOutputStream fos = null; | |
852 FileOutputStream fos2 = null; | |
853 FileOutputStream fos3 = null; | |
854 try { | |
855 fos = new FileOutputStream( | |
856 "src/test/results/verticalcrosssection_mesh" | |
857 + System.currentTimeMillis() + ".png"); | |
858 | |
859 fos2 = new FileOutputStream( | |
860 "src/test/results/verticalcrosssection_mesh" | |
861 + System.currentTimeMillis() + ".csv"); | |
862 fos3 = new FileOutputStream( | |
863 "src/test/results/verticalcrosssection_mesh" | |
864 + System.currentTimeMillis() + ".odv"); | |
865 artifact.feed(this.readDocument("src/test/ressources/" + | |
866 "verticalcrosssection_mesh/" + | |
867 "verticalcrosssection_step_08_feed.xml"), | |
868 cc); | |
869 artifact.out(this.readDocument("src/test/ressources/" + | |
870 "verticalcrosssection_mesh/" + | |
871 "verticalcrosssection_step_08_out_chart.xml"), | |
872 fos, cc); | |
873 artifact.out(this.readDocument("src/test/ressources/" + | |
874 "verticalcrosssection_mesh/" + | |
875 "verticalcrosssection_step_08_out_csv.xml"), | |
876 fos2,cc); | |
877 artifact.out(this.readDocument("src/test/ressources/" + | |
878 "verticalcrosssection_mesh/" + | |
879 "verticalcrosssection_step_08_out_odv.xml"), | |
880 fos3,cc); | |
881 | |
882 } catch (Exception e) { | |
883 log.error(e, e); | |
884 fail(); | |
885 } finally { | |
886 try { | |
887 fos.flush(); | |
888 fos.close(); | |
889 fos2.flush(); | |
890 fos2.close(); | |
891 fos3.flush(); | |
892 fos3.close(); | |
893 } catch (Exception e) { | |
894 log.error(e, e); | |
895 } | |
896 } | |
897 } catch (Exception e) { | |
898 log.error(e, e); | |
899 fail(); | |
900 } | |
901 } | |
902 | |
903 protected void createFile(byte[] content, String fileName) { | |
904 try { | |
905 FileOutputStream fos = new FileOutputStream(new File(fileName)); | |
906 ByteArrayInputStream bis = new ByteArrayInputStream(content); | |
907 byte[] buf = new byte[4096]; | |
908 while (bis.read(buf) > 0) { | |
909 fos.write(buf); | |
910 } | |
911 fos.flush(); | |
912 fos.close(); | |
913 } catch (FileNotFoundException e) { | |
914 log.error(e, e); | |
915 } catch (IOException e) { | |
916 log.error(e, e); | |
917 } | |
918 } | |
919 | |
920 /** | |
921 * @param artefactName | |
922 */ | |
923 private ArtifactFactory getArtifactFactory(String artefactName) { | |
924 log.debug("GNVArtifactsTestCase.getArtifactFactory"); | |
925 ArtifactFactory[] artifactFactories = bootstrap.getArtifactFactories(); | |
926 for (int i = 0; i < artifactFactories.length; i++) { | |
927 if (artifactFactories[i].getName().equals(artefactName)) { | |
928 log.debug("ArtifactFactory wurde gefunden."); | |
929 return artifactFactories[i]; | |
930 } | |
931 } | |
932 return null; | |
933 } | |
934 | |
935 protected void writeDocument2Log(Document document) { | |
936 log.debug(new ArtifactXMLUtilities().writeDocument2String(document)); | |
937 } | |
938 | |
939 protected Document readDocument(String fileName) { | |
940 Document returnValue = null; | |
941 try { | |
942 DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory | |
943 .newInstance(); | |
944 DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); | |
945 returnValue = docBuilder.parse(new File(fileName)); | |
946 } catch (ParserConfigurationException e) { | |
947 log.error(e, e); | |
948 } catch (SAXException e) { | |
949 log.error(e, e); | |
950 } catch (IOException e) { | |
951 log.error(e, e); | |
952 } | |
953 return returnValue; | |
954 } | |
955 | |
956 private void check4ExceptionReport(Document document) throws Exception { | |
957 document = new ArtifactXMLUtilities().reInitDocument(document); | |
958 String message = Config.getStringXPath(document, | |
959 "/exceptionreport/exception"); | |
960 if (message != null) { | |
961 throw new Exception(message); | |
962 } | |
963 } | |
964 } |