tim@52: /** tim@52: * tim@52: */ tim@52: package de.intevation.gnv.artifacts; tim@52: tim@69: import java.io.ByteArrayInputStream; tim@58: import java.io.File; tim@69: import java.io.FileNotFoundException; tim@69: import java.io.FileOutputStream; tim@58: import java.io.IOException; tim@54: tim@58: import javax.xml.parsers.DocumentBuilder; tim@52: import javax.xml.parsers.DocumentBuilderFactory; tim@52: import javax.xml.parsers.ParserConfigurationException; tim@72: tim@72: import junit.framework.TestCase; tim@52: tim@52: import org.apache.log4j.BasicConfigurator; tim@52: import org.apache.log4j.Logger; tim@52: import org.w3c.dom.Document; tim@58: import org.xml.sax.SAXException; tim@52: tim@52: import de.intevation.artifactdatabase.Config; tim@117: import de.intevation.artifactdatabase.DefaultCallMeta; tim@117: import de.intevation.artifactdatabase.DefaultPreferredLocale; tim@52: import de.intevation.artifactdatabase.FactoryBootstrap; tim@52: import de.intevation.artifacts.Artifact; tim@52: import de.intevation.artifacts.ArtifactFactory; tim@102: import de.intevation.artifacts.CallContext; tim@117: import de.intevation.artifacts.CallMeta; tim@117: import de.intevation.artifacts.PreferredLocale; tim@52: import de.intevation.gnv.artifacts.context.GNVArtifactContext; tim@72: import de.intevation.gnv.utils.ArtifactXMLUtilities; tim@52: tim@52: /** tim@52: * @author Tim Englich tim@171: * tim@52: */ tim@52: public class GNVArtifactsTestCase extends TestCase { tim@52: tim@52: /** tim@52: * the logger, used to log exceptions and additonaly information tim@52: */ tim@52: private static Logger log = null; tim@171: tim@52: static { tim@52: BasicConfigurator.configure(); tim@52: log = Logger.getLogger(GNVArtifactContext.class); tim@52: } tim@171: tim@200: private String configurationDir = "doc/conf"; tim@171: tim@52: private FactoryBootstrap bootstrap = null; tim@171: tim@52: /** tim@52: * Constructor tim@171: * tim@52: * @param name tim@52: */ tim@52: public GNVArtifactsTestCase(String name) { tim@52: super(name); tim@52: } tim@52: tim@52: /** tim@52: * @see junit.framework.TestCase#setUp() tim@52: */ tim@52: protected void setUp() throws Exception { tim@52: log.debug("GNVArtifactsTestCase.setUp"); tim@52: super.setUp(); tim@171: log.info(Config.CONFIG_DIR + " ==> " + configurationDir); tim@69: System.setProperty(Config.CONFIG_DIR, configurationDir); tim@52: log.info("Bootstrap wird initialisiert."); tim@52: bootstrap = new FactoryBootstrap(); tim@52: bootstrap.boot(); tim@52: } tim@171: tim@171: public void testTimeSeriesArtifact() { tim@106: try { tim@106: log.debug("GNVArtifactsTestCase.testTimeSeriesArtifact"); tim@171: String artefactName = "fis_marnet"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@106: assertNotNull(artifactFactory); tim@106: log.debug("TimeSeries-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@106: assertNotNull(artifact); tim@106: log.debug("TimeSeries-Artifact is available"); tim@171: tim@117: CallContext cc = createCallContext(); tim@171: tim@106: // Erster Schritt tim@171: tim@222: Document describeDocument = this.readDocument("src/test/ressources/timeseries/timeseries_describe.xml"); tim@232: tim@232: int steps = 5; tim@232: tim@232: for (int i = 1; i <= steps; i++){ tim@232: tim@240: this.doNextStep( tim@171: artifact, tim@171: cc, tim@232: "src/test/ressources/timeseries/" + tim@232: "timeseries_step_0"+i+"_feed.xml", tim@232: "src/test/ressources/timeseries/" + tim@232: "timeseries_step_0"+i+"_advance.xml", tim@232: describeDocument); tim@232: } tim@232: tim@232: Document outputData = artifact.describe(describeDocument,cc); tim@106: FileOutputStream fos = null; tim@232: FileOutputStream fos2 = null; tim@232: FileOutputStream fos3 = null; tim@232: FileOutputStream fos4 = null; tim@171: try { tim@232: fos = new FileOutputStream("src/test/results/timeseries" tim@232: + System.currentTimeMillis() tim@232: + ".png"); tim@232: fos2 = new FileOutputStream("src/test/results/timeseries" tim@232: + System.currentTimeMillis() tim@232: + ".xml"); tim@232: fos3 = new FileOutputStream("src/test/results/timeseries" tim@232: + System.currentTimeMillis() tim@232: + ".csv"); tim@232: fos4 = new FileOutputStream("src/test/results/timeseries" tim@232: + System.currentTimeMillis() tim@232: + ".odv"); tim@232: tim@232: artifact.feed(this tim@232: .readDocument("src/test/ressources/timeseries/timeseries_step_06_feed.xml"), tim@232: cc); tim@232: artifact.out(this tim@232: .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_chart.xml"), tim@232: fos, cc); tim@232: artifact.out(this tim@232: .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_statistics.xml"), tim@232: fos2, cc); tim@232: artifact.out(this tim@232: .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_csv.xml"), tim@232: fos3, cc); tim@232: artifact.out(this tim@232: .readDocument("src/test/ressources/timeseries/timeseries_step_06_out_odv.xml"), tim@232: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@106: fail(); tim@171: } finally { tim@106: try { tim@106: fos.flush(); tim@106: fos.close(); tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@106: } tim@106: } tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@73: fail(); tim@73: } tim@52: } tim@109: tim@109: /** tim@117: * @return tim@117: */ tim@117: private CallContext createCallContext() { tim@171: CallMeta callMeta = new DefaultCallMeta( tim@171: new PreferredLocale[] { new DefaultPreferredLocale("de_DE", tim@171: 1.0f) }); tim@171: CallContext cc = new TestCallContext(bootstrap.getContext(), callMeta); tim@117: return cc; tim@117: } tim@117: tim@117: /** tim@109: * @param artifact tim@109: * @param cc tim@222: * @param describeDocument TODO tim@109: * @throws Exception tim@109: */ tim@171: private void doNextStep(Artifact artifact, CallContext cc, tim@222: String feedDocument, String advanceDocument, Document describeDocument) tim@171: throws Exception { tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@211: // this.writeDocument2Log(outputData); tim@111: outputData = artifact.feed(this.readDocument(feedDocument), cc); tim@111: this.check4ExceptionReport(outputData); tim@109: outputData = artifact.advance(this.readDocument(advanceDocument), cc); tim@211: // this.writeDocument2Log(outputData); tim@109: this.check4ExceptionReport(outputData); tim@171: tim@109: } tim@171: tim@171: public void testTimeSeriesMeshArtifact() { tim@107: try { tim@107: log.debug("GNVArtifactsTestCase.testTimeSeriesMeshArtifact"); tim@171: String artefactName = "fis_modeldata"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@107: assertNotNull(artifactFactory); tim@107: log.debug("TimeSeriesMesh-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@107: assertNotNull(artifact); tim@107: log.debug("TimeSeriesMesh-Artifact is available"); tim@171: tim@117: CallContext cc = createCallContext(); tim@171: tim@222: Document describeDocument = this.readDocument("src/test/ressources/timeseries_mesh/timeseries_describe.xml"); tim@240: tim@240: int steps = 7; tim@240: tim@240: for (int i = 1; i <= steps; i++){ tim@240: this.doNextStep( tim@171: artifact, tim@171: cc, tim@240: "src/test/ressources/timeseries_mesh/" + tim@240: "timeseries_step_0"+i+"_feed.xml", tim@240: "src/test/ressources/timeseries_mesh/" + tim@240: "timeseries_step_0"+i+"_advance.xml", tim@240: describeDocument); tim@240: } tim@229: // Achter Schritt tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@107: FileOutputStream fos = null; tim@107: FileOutputStream fos2 = null; tim@107: FileOutputStream fos3 = null; tim@240: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream("src/test/results/timeseries_mesh" tim@171: + System.currentTimeMillis() tim@171: + ".png"); tim@171: fos2 = new FileOutputStream("src/test/results/timeseries_mesh" tim@171: + System.currentTimeMillis() tim@171: + ".xml"); tim@171: fos3 = new FileOutputStream("src/test/results/timeseries_mesh" tim@171: + System.currentTimeMillis() tim@171: + ".csv"); tim@240: fos4 = new FileOutputStream("src/test/results/timeseries_mesh" tim@240: + System.currentTimeMillis() tim@240: + ".odv"); tim@171: artifact tim@171: .feed( tim@171: this tim@229: .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_feed.xml"), tim@171: cc); tim@171: artifact tim@171: .out( tim@171: this tim@229: .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_statistics.xml"), tim@171: fos2, cc); tim@171: artifact tim@171: .out( tim@171: this tim@229: .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_chart.xml"), tim@171: fos, cc); tim@171: artifact tim@171: .out( tim@171: this tim@229: .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_csv.xml"), tim@171: fos3, cc); tim@240: artifact tim@240: .out( tim@240: this tim@240: .readDocument("src/test/ressources/timeseries_mesh/timeseries_step_08_out_odv.xml"), tim@240: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@107: fail(); tim@171: } finally { tim@106: try { tim@106: fos.flush(); tim@106: fos.close(); tim@106: fos2.flush(); tim@106: fos2.close(); tim@106: fos3.flush(); tim@106: fos3.close(); tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@106: } tim@106: } tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@103: fail(); tim@103: } tim@103: } tim@171: tim@171: public void testVerticalProfileArtifact() { tim@106: try { tim@106: log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); tim@171: String artefactName = "fis_marnet"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@106: assertNotNull(artifactFactory); tim@106: log.debug("VerticalProfile-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@106: assertNotNull(artifact); tim@106: log.debug("VerticalProfile-Artifact is available"); tim@171: tim@117: CallContext cc = createCallContext(); tim@171: tim@222: Document describeDocument = this.readDocument("src/test/ressources/verticalprofile/verticalprofile_describe.xml"); tim@241: int steps = 5; tim@241: tim@241: for (int i = 1; i <= steps; i++){ tim@241: this.doNextStep( tim@171: artifact, tim@171: cc, tim@241: "src/test/ressources/verticalprofile/" + tim@241: "verticalprofile_step_0"+i+"_feed.xml", tim@241: "src/test/ressources/verticalprofile/" + tim@241: "verticalprofile_step_0"+i+"_advance.xml", tim@241: describeDocument); tim@241: } tim@171: tim@107: // Vierter Schritt tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@106: FileOutputStream fos = null; tim@106: FileOutputStream fos2 = null; tim@106: FileOutputStream fos3 = null; tim@241: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream("src/test/results/verticalprofile" tim@171: + System.currentTimeMillis() tim@171: + ".png"); tim@171: fos2 = new FileOutputStream("src/test/results/verticalprofile" tim@171: + System.currentTimeMillis() tim@171: + ".xml"); tim@171: fos3 = new FileOutputStream("src/test/results/verticalprofile" tim@171: + System.currentTimeMillis() tim@171: + ".csv"); tim@241: fos4 = new FileOutputStream("src/test/results/verticalprofile" tim@241: + System.currentTimeMillis() tim@241: + ".odv"); tim@241: artifact.feed(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile/" + tim@241: "verticalprofile_step_06_feed.xml"), tim@241: cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile/" + tim@241: "verticalprofile_step_06_out_statistics.xml"), tim@241: fos2, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile/" + tim@241: "verticalprofile_step_06_out_chart.xml"), tim@241: fos, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile/" + tim@241: "verticalprofile_step_06_out_csv.xml"), tim@241: fos3, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile/" + tim@241: "verticalprofile_step_06_out_odv.xml"), tim@241: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@106: fail(); tim@171: } finally { tim@106: try { tim@106: fos.flush(); tim@106: fos.close(); tim@106: fos2.flush(); tim@106: fos2.close(); tim@106: fos3.flush(); tim@106: fos3.close(); tim@241: fos4.flush(); tim@241: fos4.close(); tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@106: } tim@106: } tim@106: } catch (Exception e) { tim@171: log.error(e, e); tim@103: fail(); tim@103: } tim@103: } tim@171: tim@171: public void testVerticalProfileMeshArtifact() { tim@114: try { tim@171: log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); tim@171: String artefactName = "fis_modeldata"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@114: assertNotNull(artifactFactory); tim@114: log.debug("VerticalProfile-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@114: assertNotNull(artifact); tim@114: log.debug("VerticalProfile-Artifact is available"); tim@171: tim@117: CallContext cc = createCallContext(); tim@241: Document describeDocument = this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_describe.xml"); tim@241: tim@241: int steps = 9; tim@241: tim@241: for (int i = 1; i <= steps; i++){ tim@241: this.doNextStep( tim@171: artifact, tim@171: cc, tim@241: "src/test/ressources/verticalprofile_mesh/" + tim@241: "verticalprofile_step_0"+i+"_feed.xml", tim@241: "src/test/ressources/verticalprofile_mesh/" + tim@241: "verticalprofile_step_0"+i+"_advance.xml", tim@241: describeDocument); tim@241: } tim@229: // 10. Schritt tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@114: FileOutputStream fos = null; tim@114: FileOutputStream fos2 = null; tim@114: FileOutputStream fos3 = null; tim@241: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream( tim@171: "src/test/results/verticalprofile_mesh" tim@171: + System.currentTimeMillis() + ".png"); tim@171: fos2 = new FileOutputStream( tim@171: "src/test/results/verticalprofile_mesh" tim@171: + System.currentTimeMillis() + ".xml"); tim@171: fos3 = new FileOutputStream( tim@171: "src/test/results/verticalprofile_mesh" tim@171: + System.currentTimeMillis() + ".csv"); tim@241: fos4 = new FileOutputStream( tim@241: "src/test/results/verticalprofile_mesh" tim@241: + System.currentTimeMillis() + ".odv"); tim@241: artifact.feed(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_step_10_feed.xml"), tim@171: cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_step_10_out_statistics.xml"), tim@241: fos2, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_step_10_out_chart.xml"), tim@241: fos, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_step_10_out_csv.xml"), tim@241: fos3, cc); tim@241: artifact.out(this.readDocument("src/test/ressources/" + tim@241: "verticalprofile_mesh/" + tim@241: "verticalprofile_step_10_out_odv.xml"), tim@241: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@114: fail(); tim@171: } finally { tim@114: try { tim@114: fos.flush(); tim@114: fos.close(); tim@114: fos2.flush(); tim@114: fos2.close(); tim@114: fos3.flush(); tim@114: fos3.close(); tim@241: fos4.flush(); tim@241: fos4.close(); tim@114: } catch (Exception e) { tim@171: log.error(e, e); tim@114: } tim@114: } tim@114: } catch (Exception e) { tim@171: log.error(e, e); tim@114: fail(); tim@114: } tim@114: } tim@171: tim@171: public void testVerticalProfileInstantaneousPointArtifact() { tim@116: try { tim@171: log.debug("GNVArtifactsTestCase.testVerticalProfileArtifact"); tim@171: String artefactName = "fis_bsh_ctd"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@116: assertNotNull(artifactFactory); tim@116: log.debug("VerticalProfile-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@116: assertNotNull(artifact); tim@116: log.debug("VerticalProfile-Artifact is available"); tim@171: tim@117: CallContext cc = createCallContext(); tim@222: Document describeDocument = this.readDocument("src/test/ressources/verticalprofile_instantaneouspoint/verticalprofile_describe.xml"); tim@243: tim@243: int steps = 4; tim@243: tim@243: for (int i = 1; i <= steps; i++){ tim@243: this.doNextStep( tim@171: artifact, tim@171: cc, tim@243: "src/test/ressources/verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_0"+i+"_feed.xml", tim@243: "src/test/ressources/verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_0"+i+"_advance.xml", tim@243: describeDocument); tim@243: } tim@171: tim@116: // Vierter Schritt tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@116: FileOutputStream fos = null; tim@116: FileOutputStream fos2 = null; tim@116: FileOutputStream fos3 = null; tim@243: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream( tim@171: "src/test/results/verticalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".png"); tim@171: fos2 = new FileOutputStream( tim@171: "src/test/results/verticalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".xml"); tim@171: fos3 = new FileOutputStream( tim@171: "src/test/results/verticalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".csv"); tim@243: fos4 = new FileOutputStream( tim@243: "src/test/results/verticalprofile_instantaneouspoint" tim@243: + System.currentTimeMillis() + ".odv"); tim@243: artifact.feed(this.readDocument("src/test/ressources/" + tim@243: "verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_05_feed.xml"), tim@243: cc); tim@243: artifact.out(this.readDocument("src/test/ressources/" + tim@243: "verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_05_out_statistics.xml"), tim@243: fos2, cc); tim@243: artifact.out(this.readDocument("src/test/ressources/" + tim@243: "verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_05_out_chart.xml"), tim@243: fos, cc); tim@243: artifact.out(this.readDocument("src/test/ressources/" + tim@243: "verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_05_out_csv.xml"), tim@243: fos3, cc); tim@243: artifact.out(this.readDocument("src/test/ressources/" + tim@243: "verticalprofile_instantaneouspoint/" + tim@243: "verticalprofile_step_05_out_odv.xml"), tim@243: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@116: fail(); tim@171: } finally { tim@116: try { tim@116: fos.flush(); tim@116: fos.close(); tim@116: fos2.flush(); tim@116: fos2.close(); tim@116: fos3.flush(); tim@116: fos3.close(); tim@116: } catch (Exception e) { tim@171: log.error(e, e); tim@116: } tim@116: } tim@116: } catch (Exception e) { tim@171: log.error(e, e); tim@116: fail(); tim@116: } tim@116: } tim@171: tim@171: public void testHorizontalProfileInstantaneousPointArtifact() { tim@171: try { tim@244: log.debug("GNVArtifactsTestCase." + tim@244: "testHorizontalProfileInstantaneousPointArtifact"); tim@171: String artefactName = "fis_delphin"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@171: assertNotNull(artifactFactory); tim@171: log.debug("VerticalProfile-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@171: assertNotNull(artifact); tim@171: log.debug("VerticalProfile-Artifact is available"); tim@171: tim@171: CallContext cc = createCallContext(); tim@222: Document describeDocument = this.readDocument("src/test/ressources/horizontalProfile_instantaneouspoint/horizontalprofile_describe.xml"); tim@244: tim@244: int steps = 6; tim@244: tim@244: for (int i = 0; i < steps; i++){ tim@244: tim@244: this.doNextStep( tim@171: artifact, tim@171: cc, tim@244: "src/test/ressources/horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_0"+i+"_feed.xml", tim@244: "src/test/ressources/horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_0"+i+"_advance.xml", tim@244: describeDocument); tim@244: } tim@171: tim@222: Document outputData = artifact.describe(describeDocument, cc); tim@171: FileOutputStream fos = null; tim@171: FileOutputStream fos2 = null; tim@171: FileOutputStream fos3 = null; tim@244: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream( tim@171: "src/test/results/horizontalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".png"); tim@171: fos2 = new FileOutputStream( tim@171: "src/test/results/horizontalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".xml"); tim@171: fos3 = new FileOutputStream( tim@171: "src/test/results/horizontalprofile_instantaneouspoint" tim@171: + System.currentTimeMillis() + ".csv"); tim@244: fos4 = new FileOutputStream( tim@244: "src/test/results/horizontalprofile_instantaneouspoint" tim@244: + System.currentTimeMillis() + ".odv"); tim@244: artifact.feed(this.readDocument("src/test/ressources/" + tim@244: "horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_06_feed.xml"), tim@244: cc); tim@244: artifact.out(this.readDocument("src/test/ressources/" + tim@244: "horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_06_out_statistics.xml"), tim@244: fos2,cc); tim@244: artifact.out(this.readDocument("src/test/ressources/" + tim@244: "horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_06_out_chart.xml"), tim@244: fos,cc); tim@244: artifact.out(this.readDocument("src/test/ressources/" + tim@244: "horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_06_out_csv.xml"), tim@244: fos3,cc); tim@244: artifact.out(this.readDocument("src/test/ressources/" + tim@244: "horizontalProfile_instantaneouspoint/" + tim@244: "horizontalprofile_step_06_out_odv.xml"), tim@244: fos4,cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: fail(); tim@171: } finally { tim@171: try { tim@171: fos.flush(); tim@171: fos.close(); tim@171: fos2.flush(); tim@171: fos2.close(); tim@171: fos3.flush(); tim@171: fos3.close(); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: } tim@171: } tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: fail(); tim@171: } tim@171: } tim@171: tim@171: public void testHorizontalProfileMeshPointArtifact() { tim@171: try { tim@242: log.debug("GNVArtifactsTestCase." + tim@242: "testHorizontalProfileInstantaneousPointArtifact"); tim@171: String artefactName = "fis_modeldata"; tim@171: ArtifactFactory artifactFactory = this tim@171: .getArtifactFactory(artefactName); tim@171: assertNotNull(artifactFactory); tim@171: log.debug("VerticalProfile-ArtifactFactory is available"); tim@171: Artifact artifact = artifactFactory.createArtifact( tim@171: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@171: assertNotNull(artifact); tim@171: log.debug("VerticalProfile-Artifact is available"); tim@171: tim@171: CallContext cc = createCallContext(); tim@222: Document describeDocument = this.readDocument("src/test/ressources/horizontalProfile_mesh/horizontalprofile_describe.xml"); tim@242: tim@242: int steps = 9; tim@242: tim@242: for (int i = 1; i <= steps; i++){ tim@242: tim@242: this.doNextStep( tim@171: artifact, tim@171: cc, tim@242: "src/test/ressources/horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_0"+i+"_feed.xml", tim@242: "src/test/ressources/horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_0"+i+"_advance.xml", tim@242: describeDocument); tim@242: } tim@229: tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@171: FileOutputStream fos = null; tim@171: FileOutputStream fos2 = null; tim@171: FileOutputStream fos3 = null; tim@242: FileOutputStream fos4 = null; tim@171: try { tim@171: fos = new FileOutputStream( tim@171: "src/test/results/horizontalProfile_mesh" tim@171: + System.currentTimeMillis() + ".png"); tim@171: fos2 = new FileOutputStream( tim@171: "src/test/results/horizontalProfile_mesh" tim@171: + System.currentTimeMillis() + ".xml"); tim@171: fos3 = new FileOutputStream( tim@171: "src/test/results/horizontalProfile_mesh" tim@171: + System.currentTimeMillis() + ".csv"); tim@242: fos4 = new FileOutputStream( tim@242: "src/test/results/horizontalProfile_mesh" tim@242: + System.currentTimeMillis() + ".odv"); tim@242: artifact.feed(this.readDocument("src/test/ressources/" + tim@242: "horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_10_feed.xml"), tim@242: cc); tim@242: artifact.out(this.readDocument("src/test/ressources/" + tim@242: "horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_10_out_statistics.xml"), tim@242: fos2, cc); tim@242: artifact.out(this.readDocument("src/test/ressources/" + tim@242: "horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_10_out_chart.xml"), tim@171: fos, cc); tim@242: artifact.out(this.readDocument("src/test/ressources/" + tim@242: "horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_10_out_csv.xml"), tim@242: fos3, cc); tim@242: artifact.out(this.readDocument("src/test/ressources/" + tim@242: "horizontalProfile_mesh/" + tim@242: "horizontalprofile_step_10_out_odv.xml"), tim@242: fos4, cc); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: fail(); tim@171: } finally { tim@171: try { tim@171: fos.flush(); tim@171: fos.close(); tim@171: fos2.flush(); tim@171: fos2.close(); tim@171: fos3.flush(); tim@171: fos3.close(); tim@242: fos4.flush(); tim@242: fos4.close(); tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: } tim@171: } tim@171: } catch (Exception e) { tim@171: log.error(e, e); tim@171: fail(); tim@171: } tim@171: } tim@197: tim@219: public void testHorizontalCrossSectionMeshArtifact() { tim@219: try { tim@219: log.debug("GNVArtifactsTestCase.testHorizontalCrossSectionMeshArtifact"); tim@219: String artefactName = "fis_modeldata"; tim@219: ArtifactFactory artifactFactory = this tim@219: .getArtifactFactory(artefactName); tim@219: assertNotNull(artifactFactory); tim@219: log.debug("HorizontalCrossSectionMesh-ArtifactFactory is available"); tim@219: Artifact artifact = artifactFactory.createArtifact( tim@219: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@219: assertNotNull(artifact); tim@219: log.debug("HorizontalCrossSectionMesh-Artifact is available"); tim@219: tim@219: CallContext cc = createCallContext(); tim@222: Document describeDocument = this.readDocument("src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_describe.xml"); tim@219: // Erster Schritt tim@219: this tim@219: .doNextStep( tim@219: artifact, tim@219: cc, tim@219: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_01_feed.xml", tim@222: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_01_advance.xml", describeDocument); tim@219: tim@219: // Zweiter Schritt tim@219: this tim@219: .doNextStep( tim@219: artifact, tim@219: cc, tim@219: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_02_feed.xml", tim@222: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_02_advance.xml", describeDocument); tim@219: // Dritter Schritt tim@219: this tim@219: .doNextStep( tim@219: artifact, tim@219: cc, tim@219: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_03_feed.xml", tim@222: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_03_advance.xml", describeDocument); tim@219: // Vierter Schritt tim@219: this tim@219: .doNextStep( tim@219: artifact, tim@219: cc, tim@219: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_04_feed.xml", tim@222: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_04_advance.xml", describeDocument); tim@219: tim@229: // Fünfter Schritt tim@229: this tim@229: .doNextStep( tim@229: artifact, tim@229: cc, tim@229: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_05_feed.xml", tim@229: "src/test/ressources/horizontalcrosssection_mesh/horizontalcrosssection_step_05_advance.xml", describeDocument); tim@229: tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@219: FileOutputStream fos = null; tim@219: FileOutputStream fos2 = null; tim@219: FileOutputStream fos3 = null; tim@219: try { tim@219: fos = new FileOutputStream( tim@219: "src/test/results/horizontalcrosssection_mesh" tim@219: + System.currentTimeMillis() + ".png"); tim@219: fos2 = new FileOutputStream( tim@219: "src/test/results/horizontalcrosssection_mesh" tim@219: + System.currentTimeMillis() + ".xml"); tim@219: fos3 = new FileOutputStream( tim@219: "src/test/results/horizontalcrosssection_mesh" tim@219: + System.currentTimeMillis() + ".csv"); tim@219: artifact tim@219: .feed(this.readDocument("src/test/ressources/horizontal" + tim@229: "crosssection_mesh/horizontalcrosssection_step_06_feed.xml"), tim@219: cc); tim@219: artifact tim@219: .out(this.readDocument("src/test/ressources/horizontal" + tim@229: "crosssection_mesh/horizontalcrosssection_step_06_out_statistics.xml"), tim@219: fos2, cc); tim@219: artifact tim@219: .out(this.readDocument("src/test/ressources/horizontal" + tim@229: "crosssection_mesh/horizontalcrosssection_step_06_out_chart.xml"), tim@219: fos, cc); tim@219: artifact.out(this.readDocument("src/test/ressources/horizontal" + tim@229: "crosssection_mesh/horizontalcrosssection_step_06_out_csv.xml"), tim@219: fos3, tim@219: cc); tim@219: } catch (Exception e) { tim@219: log.error(e, e); tim@219: fail(); tim@219: } finally { tim@219: try { tim@219: fos.flush(); tim@219: fos.close(); tim@219: fos2.flush(); tim@219: fos2.close(); tim@219: fos3.flush(); tim@219: fos3.close(); tim@219: } catch (Exception e) { tim@219: log.error(e, e); tim@219: } tim@219: } tim@219: } catch (Exception e) { tim@219: log.error(e, e); tim@219: fail(); tim@219: } tim@219: } tim@219: tim@197: public void testVerticalCrossSectionMeshArtifact() { tim@197: try { tim@197: log.debug("GNVArtifactsTestCase.testHVerticalCrossSectionMeshArtifact"); tim@197: String artefactName = "fis_modeldata"; tim@197: ArtifactFactory artifactFactory = this tim@197: .getArtifactFactory(artefactName); tim@197: assertNotNull(artifactFactory); tim@197: log.debug("VerticalProfile-ArtifactFactory is available"); tim@197: Artifact artifact = artifactFactory.createArtifact( tim@197: "" + System.currentTimeMillis(), bootstrap.getContext()); tim@197: assertNotNull(artifact); tim@197: log.debug("VerticalProfile-Artifact is available"); tim@197: tim@197: CallContext cc = createCallContext(); tim@222: Document describeDocument = this.readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_describe.xml"); tim@197: // Erster Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_01_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_01_advance.xml", describeDocument); tim@197: tim@197: // Zweiter Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_02_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_02_advance.xml", describeDocument); tim@197: // Dritter Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_03_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_03_advance.xml", describeDocument); tim@197: // Vierter Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_04_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_04_advance.xml", describeDocument); tim@197: // Fünfter Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_05_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_05_advance.xml", describeDocument); tim@197: tim@197: // Sechster Schritt tim@197: this tim@197: .doNextStep( tim@197: artifact, tim@197: cc, tim@197: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_06_feed.xml", tim@222: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_06_advance.xml", describeDocument); tim@229: // Siebter Schritt tim@229: this tim@229: .doNextStep( tim@229: artifact, tim@229: cc, tim@229: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_feed.xml", tim@229: "src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_07_advance.xml", describeDocument); tim@197: tim@222: Document outputData = artifact.describe(describeDocument,cc); tim@197: FileOutputStream fos = null; tim@197: FileOutputStream fos2 = null; tim@197: FileOutputStream fos3 = null; tim@197: try { tim@197: fos = new FileOutputStream( tim@197: "src/test/results/verticalcrosssection_mesh" tim@197: + System.currentTimeMillis() + ".png"); tim@197: fos2 = new FileOutputStream( tim@197: "src/test/results/verticalcrosssection_mesh" tim@197: + System.currentTimeMillis() + ".xml"); tim@197: fos3 = new FileOutputStream( tim@197: "src/test/results/verticalcrosssection_mesh" tim@197: + System.currentTimeMillis() + ".csv"); tim@197: artifact tim@197: .feed( tim@197: this tim@229: .readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_feed.xml"), tim@197: cc); tim@197: artifact tim@197: .out( tim@197: this tim@229: .readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_out_statistics.xml"), tim@197: fos2, cc); tim@197: artifact tim@197: .out( tim@197: this tim@229: .readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_out_chart.xml"), tim@197: fos, cc); tim@229: artifact.out(this.readDocument("src/test/ressources/verticalcrosssection_mesh/verticalcrosssection_step_08_out_csv.xml"), tim@197: fos3, tim@197: cc); tim@197: } catch (Exception e) { tim@197: log.error(e, e); tim@197: fail(); tim@197: } finally { tim@197: try { tim@197: fos.flush(); tim@197: fos.close(); tim@197: fos2.flush(); tim@197: fos2.close(); tim@197: fos3.flush(); tim@197: fos3.close(); tim@197: } catch (Exception e) { tim@197: log.error(e, e); tim@197: } tim@197: } tim@197: } catch (Exception e) { tim@197: log.error(e, e); tim@197: fail(); tim@197: } tim@197: } tim@171: tim@171: protected void createFile(byte[] content, String fileName) { tim@52: try { tim@69: FileOutputStream fos = new FileOutputStream(new File(fileName)); tim@69: ByteArrayInputStream bis = new ByteArrayInputStream(content); tim@69: byte[] buf = new byte[4096]; tim@171: while (bis.read(buf) > 0) { tim@171: fos.write(buf); tim@69: } tim@69: fos.flush(); tim@69: fos.close(); tim@69: } catch (FileNotFoundException e) { tim@171: log.error(e, e); tim@69: } catch (IOException e) { tim@171: log.error(e, e); tim@52: } tim@52: } tim@52: tim@52: /** tim@52: * @param artefactName tim@52: */ tim@171: private ArtifactFactory getArtifactFactory(String artefactName) { tim@52: log.debug("GNVArtifactsTestCase.getArtifactFactory"); tim@52: ArtifactFactory[] artifactFactories = bootstrap.getArtifactFactories(); tim@171: for (int i = 0; i < artifactFactories.length; i++) { tim@171: if (artifactFactories[i].getName().equals(artefactName)) { tim@52: log.debug("ArtifactFactory wurde gefunden."); tim@52: return artifactFactories[i]; tim@52: } tim@52: } tim@52: return null; tim@52: } tim@171: tim@171: protected void writeDocument2Log(Document document) { tim@72: log.debug(new ArtifactXMLUtilities().writeDocument2String(document)); tim@54: } tim@171: tim@171: protected Document readDocument(String fileName) { tim@58: Document returnValue = null; tim@58: try { tim@171: DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory tim@171: .newInstance(); tim@58: DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); tim@171: returnValue = docBuilder.parse(new File(fileName)); tim@58: } catch (ParserConfigurationException e) { tim@171: log.error(e, e); tim@58: } catch (SAXException e) { tim@171: log.error(e, e); tim@58: } catch (IOException e) { tim@171: log.error(e, e); tim@58: } tim@58: return returnValue; tim@58: } tim@52: tim@171: private void check4ExceptionReport(Document document) throws Exception { tim@106: document = new ArtifactXMLUtilities().reInitDocument(document); tim@171: String message = Config.getStringXPath(document, tim@171: "/exceptionreport/exception"); tim@171: if (message != null) { tim@106: throw new Exception(message); tim@106: } tim@106: } tim@244: }