Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java @ 52:4d6a82b96059
First Implementation of the GNV-Artifacts
gnv-artifacts/trunk@32 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Mon, 07 Sep 2009 15:29:24 +0000 |
parents | |
children | 09b4bf848c7b |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java Mon Sep 07 15:29:24 2009 +0000 @@ -0,0 +1,112 @@ +/** + * + */ +package de.intevation.gnv.artifacts; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.apache.log4j.BasicConfigurator; +import org.apache.log4j.Logger; +import org.w3c.dom.Document; + +import de.intevation.artifactdatabase.Config; +import de.intevation.artifactdatabase.FactoryBootstrap; +import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.ArtifactFactory; +import de.intevation.gnv.artifacts.context.GNVArtifactContext; +import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory; +import junit.framework.TestCase; + +/** + * @author Tim Englich <tim.englich@intevation.de> + * + */ +public class GNVArtifactsTestCase extends TestCase { + + /** + * the logger, used to log exceptions and additonaly information + */ + private static Logger log = null; + + static { + BasicConfigurator.configure(); + log = Logger.getLogger(GNVArtifactContext.class); + } + + private String configurationFile = "src/test/ressources/GNVArtifactsTestCase_Configuration.xml"; + + private FactoryBootstrap bootstrap = null; + /** + * Constructor + * @param name + */ + public GNVArtifactsTestCase(String name) { + super(name); + } + + /** + * @see junit.framework.TestCase#setUp() + */ + protected void setUp() throws Exception { + log.debug("GNVArtifactsTestCase.setUp"); + super.setUp(); + log.info(Config.CONFIG_PROPERTY + " ==> "+configurationFile); + System.setProperty(Config.CONFIG_PROPERTY, configurationFile); + log.info("Bootstrap wird initialisiert."); + bootstrap = new FactoryBootstrap(); + bootstrap.boot(); + } + + public void testTimeSeriesArtifact(){ + log.debug("GNVArtifactsTestCase.testTimeSeriesArtifact"); + String artefactName = "timeSeries"; + ArtifactFactory artifactFactory = this.getArtifactFactory(artefactName); + assertNotNull(artifactFactory); + log.debug("TimeSeries-ArtifactFactory is available"); + Artifact artifact = artifactFactory.createArtifact(""+System.currentTimeMillis(),bootstrap.getContext()); + assertNotNull(artifact); + log.debug("TimeSeries-Artifact is available"); + + Document indata = this.getDocument(); + Document outData = this.createOutputDocument(); + artifact.feed(indata, bootstrap.getContext()); + artifact.advance(outData, bootstrap.getContext()); + Document outputData = artifact.describe(bootstrap.getContext()); + + + + } + private Document getDocument(){ + return this.createOutputDocument(); + } + + private Document createOutputDocument(){ + try { + return DocumentBuilderFactory + .newInstance() + .newDocumentBuilder() + .newDocument(); + } + catch (ParserConfigurationException e) { + log.error(e,e); + } + return null; + } + + /** + * @param artefactName + */ + private ArtifactFactory getArtifactFactory(String artefactName){ + log.debug("GNVArtifactsTestCase.getArtifactFactory"); + ArtifactFactory[] artifactFactories = bootstrap.getArtifactFactories(); + for (int i = 0; i < artifactFactories.length; i++){ + if (artifactFactories[i].getName().equals(artefactName)){ + log.debug("ArtifactFactory wurde gefunden."); + return artifactFactories[i]; + } + } + return null; + } + +}