comparison gnv-artifacts/src/test/java/de/intevation/gnv/artifacts/GNVArtifactsTestCase.java @ 69:f24c825144bc

TestCase Refactored to the new Folder-Based Configuration. Also added further steps to the Testcase. gnv-artifacts/trunk@56 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Thu, 10 Sep 2009 07:57:30 +0000
parents 9f57053d0384
children 1fece4da4f2f
comparison
equal deleted inserted replaced
68:d117fd4b82e5 69:f24c825144bc
1 /** 1 /**
2 * 2 *
3 */ 3 */
4 package de.intevation.gnv.artifacts; 4 package de.intevation.gnv.artifacts;
5 5
6 import java.io.ByteArrayInputStream;
6 import java.io.File; 7 import java.io.File;
8 import java.io.FileNotFoundException;
9 import java.io.FileOutputStream;
7 import java.io.IOException; 10 import java.io.IOException;
8 import java.io.StringWriter; 11 import java.io.StringWriter;
9 12
10 import javax.xml.parsers.DocumentBuilder; 13 import javax.xml.parsers.DocumentBuilder;
11 import javax.xml.parsers.DocumentBuilderFactory; 14 import javax.xml.parsers.DocumentBuilderFactory;
26 import de.intevation.artifactdatabase.Config; 29 import de.intevation.artifactdatabase.Config;
27 import de.intevation.artifactdatabase.FactoryBootstrap; 30 import de.intevation.artifactdatabase.FactoryBootstrap;
28 import de.intevation.artifacts.Artifact; 31 import de.intevation.artifacts.Artifact;
29 import de.intevation.artifacts.ArtifactFactory; 32 import de.intevation.artifacts.ArtifactFactory;
30 import de.intevation.gnv.artifacts.context.GNVArtifactContext; 33 import de.intevation.gnv.artifacts.context.GNVArtifactContext;
31 import de.intevation.gnv.artifacts.context.GNVArtifactContextFactory;
32 import junit.framework.TestCase; 34 import junit.framework.TestCase;
33 35
34 /** 36 /**
35 * @author Tim Englich <tim.englich@intevation.de> 37 * @author Tim Englich <tim.englich@intevation.de>
36 * 38 *
45 static { 47 static {
46 BasicConfigurator.configure(); 48 BasicConfigurator.configure();
47 log = Logger.getLogger(GNVArtifactContext.class); 49 log = Logger.getLogger(GNVArtifactContext.class);
48 } 50 }
49 51
50 private String configurationFile = "src/test/ressources/GNVArtifactsTestCase_Configuration.xml"; 52 private String configurationDir = "src/test/ressources/";
51 53
52 private FactoryBootstrap bootstrap = null; 54 private FactoryBootstrap bootstrap = null;
53 /** 55 /**
54 * Constructor 56 * Constructor
55 * @param name 57 * @param name
62 * @see junit.framework.TestCase#setUp() 64 * @see junit.framework.TestCase#setUp()
63 */ 65 */
64 protected void setUp() throws Exception { 66 protected void setUp() throws Exception {
65 log.debug("GNVArtifactsTestCase.setUp"); 67 log.debug("GNVArtifactsTestCase.setUp");
66 super.setUp(); 68 super.setUp();
67 log.info(Config.CONFIG_PROPERTY + " ==> "+configurationFile); 69 log.info(Config.CONFIG_DIR + " ==> "+configurationDir);
68 System.setProperty(Config.CONFIG_PROPERTY, configurationFile); 70 System.setProperty(Config.CONFIG_DIR, configurationDir);
69 log.info("Bootstrap wird initialisiert."); 71 log.info("Bootstrap wird initialisiert.");
70 bootstrap = new FactoryBootstrap(); 72 bootstrap = new FactoryBootstrap();
71 bootstrap.boot(); 73 bootstrap.boot();
72 } 74 }
73 75
110 outputData = artifact.advance(this.readDocument("src/test/ressources/timeseries/timeseries_step_04_advance.xml"), bootstrap.getContext()); 112 outputData = artifact.advance(this.readDocument("src/test/ressources/timeseries/timeseries_step_04_advance.xml"), bootstrap.getContext());
111 this.writeDocument2Log(outputData); 113 this.writeDocument2Log(outputData);
112 114
113 // Fünfter Schritt 115 // Fünfter Schritt
114 outputData = artifact.describe(bootstrap.getContext()); 116 outputData = artifact.describe(bootstrap.getContext());
115 this.writeDocument2Log(outputData); 117 artifact.feed(this.readDocument("src/test/ressources/timeseries/timeseries_step_05_feed.xml"), bootstrap.getContext());
116 118 byte[] result = artifact.out(this.readDocument("src/test/ressources/timeseries/timeseries_step_05_out.xml"), bootstrap.getContext());
117 } 119 this.createFile(result, "src/test/results/timeseriesdiagramm"+System.currentTimeMillis()+".png");
118 private Document getDocument(){
119 return this.createOutputDocument();
120 } 120 }
121 121
122 private Document createOutputDocument(){ 122 protected void createFile(byte[] content, String fileName){
123 try { 123 try {
124 return DocumentBuilderFactory 124 FileOutputStream fos = new FileOutputStream(new File(fileName));
125 .newInstance() 125 ByteArrayInputStream bis = new ByteArrayInputStream(content);
126 .newDocumentBuilder() 126 byte[] buf = new byte[4096];
127 .newDocument(); 127 while (bis.read(buf) > 0){
128 } 128 fos.write(buf);
129 catch (ParserConfigurationException e) { 129 }
130 fos.flush();
131 fos.close();
132 } catch (FileNotFoundException e) {
133 log.error(e,e);
134 } catch (IOException e) {
130 log.error(e,e); 135 log.error(e,e);
131 } 136 }
132 return null;
133 } 137 }
138
134 139
135 /** 140 /**
136 * @param artefactName 141 * @param artefactName
137 */ 142 */
138 private ArtifactFactory getArtifactFactory(String artefactName){ 143 private ArtifactFactory getArtifactFactory(String artefactName){

http://dive4elements.wald.intevation.org