01: /**
02: *
03: */package org.geotools.gce.gtopo30;
04:
05: import java.io.File;
06: import java.util.logging.Logger;
07:
08: import junit.framework.TestCase;
09:
10: import org.geotools.coverage.grid.GridCoverage2D;
11: import org.geotools.resources.TestData;
12:
13: /**
14: * @author Simone Giannecchini
15: *
16: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/gtopo30/src/test/java/org/geotools/gce/gtopo30/GT30TestBase.java $
17: */
18: public abstract class GT30TestBase extends TestCase {
19:
20: protected GridCoverage2D gc;
21:
22: protected Logger logger = org.geotools.util.logging.Logging
23: .getLogger(GT30ReaderWriterTest.class.toString());
24:
25: protected File newDir;
26:
27: protected String fileName = "W002N52";
28:
29: /**
30: *
31: */
32: public GT30TestBase() {
33: super ();
34: }
35:
36: /**
37: * @param arg0
38: */
39: public GT30TestBase(String arg0) {
40: super (arg0);
41:
42: }
43:
44: public abstract void test() throws Exception;
45:
46: /**
47: * Unpack the gtopo files from the supplied zip file.
48: *
49: * @throws Exception
50: */
51: protected void unpackGTOPO() throws Exception {
52: // check that it exisits
53: File file = TestData.file(this , fileName + ".zip");
54: assertTrue(file.exists());
55:
56: // unzip it
57: TestData.unzipFile(this , fileName + ".zip");
58: }
59:
60: /**
61: * Deleting all the file we created during tests. Since gtopo files are big
62: * we try to save space on the disk!!!
63: *
64: * @param file
65: */
66: protected void deleteAll(File file) {
67: final File[] fileList = file.listFiles();
68: final int length = fileList.length;
69: for (int i = 0; i < length; i++) {
70: if (fileList[i].isDirectory()) {
71: deleteAll(fileList[i]);
72: fileList[i].delete();
73:
74: continue;
75: }
76:
77: if (!fileList[i].getName().endsWith("zip")
78: && !fileList[i].getName().startsWith("W002N52")) {
79: fileList[i].delete();
80: }
81: }
82: }
83:
84: protected void setUp() throws Exception {
85: super .setUp();
86: this .unpackGTOPO();
87: }
88:
89: /*
90: * @see TestCase#tearDown()
91: */
92: protected void tearDown() throws Exception {
93: deleteAll(TestData.file(this , ""));
94: super.tearDown();
95: }
96: }
|