comparison 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
comparison
equal deleted inserted replaced
51:71788b63b146 52:4d6a82b96059
1 /**
2 *
3 */
4 package de.intevation.gnv.artifacts;
5
6 import javax.xml.parsers.DocumentBuilderFactory;
7 import javax.xml.parsers.ParserConfigurationException;
8
9 import org.apache.log4j.BasicConfigurator;
10 import org.apache.log4j.Logger;
11 import org.w3c.dom.Document;
12
13 import de.intevation.artifactdatabase.Config;
14 import de.intevation.artifactdatabase.FactoryBootstrap;
15 import de.intevation.artifacts.Artifact;
16 import de.intevation.artifacts.ArtifactFactory;
17 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
18 import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory;
19 import junit.framework.TestCase;
20
21 /**
22 * @author Tim Englich <tim.englich@intevation.de>
23 *
24 */
25 public class GNVArtifactsTestCase extends TestCase {
26
27 /**
28 * the logger, used to log exceptions and additonaly information
29 */
30 private static Logger log = null;
31
32 static {
33 BasicConfigurator.configure();
34 log = Logger.getLogger(GNVArtifactContext.class);
35 }
36
37 private String configurationFile = "src/test/ressources/GNVArtifactsTestCase_Configuration.xml";
38
39 private FactoryBootstrap bootstrap = null;
40 /**
41 * Constructor
42 * @param name
43 */
44 public GNVArtifactsTestCase(String name) {
45 super(name);
46 }
47
48 /**
49 * @see junit.framework.TestCase#setUp()
50 */
51 protected void setUp() throws Exception {
52 log.debug("GNVArtifactsTestCase.setUp");
53 super.setUp();
54 log.info(Config.CONFIG_PROPERTY + " ==> "+configurationFile);
55 System.setProperty(Config.CONFIG_PROPERTY, configurationFile);
56 log.info("Bootstrap wird initialisiert.");
57 bootstrap = new FactoryBootstrap();
58 bootstrap.boot();
59 }
60
61 public void testTimeSeriesArtifact(){
62 log.debug("GNVArtifactsTestCase.testTimeSeriesArtifact");
63 String artefactName = "timeSeries";
64 ArtifactFactory artifactFactory = this.getArtifactFactory(artefactName);
65 assertNotNull(artifactFactory);
66 log.debug("TimeSeries-ArtifactFactory is available");
67 Artifact artifact = artifactFactory.createArtifact(""+System.currentTimeMillis(),bootstrap.getContext());
68 assertNotNull(artifact);
69 log.debug("TimeSeries-Artifact is available");
70
71 Document indata = this.getDocument();
72 Document outData = this.createOutputDocument();
73 artifact.feed(indata, bootstrap.getContext());
74 artifact.advance(outData, bootstrap.getContext());
75 Document outputData = artifact.describe(bootstrap.getContext());
76
77
78
79 }
80 private Document getDocument(){
81 return this.createOutputDocument();
82 }
83
84 private Document createOutputDocument(){
85 try {
86 return DocumentBuilderFactory
87 .newInstance()
88 .newDocumentBuilder()
89 .newDocument();
90 }
91 catch (ParserConfigurationException e) {
92 log.error(e,e);
93 }
94 return null;
95 }
96
97 /**
98 * @param artefactName
99 */
100 private ArtifactFactory getArtifactFactory(String artefactName){
101 log.debug("GNVArtifactsTestCase.getArtifactFactory");
102 ArtifactFactory[] artifactFactories = bootstrap.getArtifactFactories();
103 for (int i = 0; i < artifactFactories.length; i++){
104 if (artifactFactories[i].getName().equals(artefactName)){
105 log.debug("ArtifactFactory wurde gefunden.");
106 return artifactFactories[i];
107 }
108 }
109 return null;
110 }
111
112 }

http://dive4elements.wald.intevation.org