001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, Geotools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: */
017: package org.geotools.gce.arcgrid;
018:
019: import java.io.File;
020: import java.io.FileFilter;
021: import java.io.PrintWriter;
022: import java.io.StringWriter;
023: import java.util.logging.Logger;
024:
025: import javax.imageio.ImageIO;
026: import javax.media.jai.JAI;
027:
028: import junit.framework.TestCase;
029:
030: import org.geotools.TestData;
031:
032: /**
033: * @author Giannecchini
034: *
035: * @source $URL:
036: */
037: public abstract class ArcGridBaseTestCase extends TestCase {
038:
039: protected final static Logger LOGGER = org.geotools.util.logging.Logging
040: .getLogger(ArcGridBaseTestCase.class.toString());
041:
042: protected File[] testFiles;
043:
044: public ArcGridBaseTestCase(String name) {
045:
046: super (name);
047:
048: }
049:
050: protected void setUp() throws Exception {
051: super .setUp();
052:
053: ImageIO.setUseCache(false);
054: JAI.getDefaultInstance().getTileCache().setMemoryCapacity(
055: 10 * 1024 * 1024);
056: JAI.getDefaultInstance().getTileCache()
057: .setMemoryThreshold(1.0f);
058:
059: JAI.getDefaultInstance().getTileScheduler().setParallelism(50);
060: JAI.getDefaultInstance().getTileScheduler()
061: .setPrefetchParallelism(50);
062: JAI.getDefaultInstance().getTileScheduler()
063: .setPrefetchPriority(5);
064: JAI.getDefaultInstance().getTileScheduler().setPriority(5);
065:
066: // check that it exisits
067: File file = TestData.copy(this , "arcgrid/arcgrid.zip");
068: assertTrue(file.exists());
069:
070: // unzip it
071: TestData.unzipFile(this , "arcgrid/arcgrid.zip");
072:
073: testFiles = TestData.file(this , "arcgrid/").listFiles(
074: new FileFilter() {
075:
076: public boolean accept(File pathname) {
077:
078: return new ArcGridFormat().accepts(pathname);
079: }
080: });
081: }
082:
083: protected void tearDown() throws Exception {
084: final File[] fileList = TestData.file(this , "").listFiles();
085: final int length = fileList.length;
086: for (int i = 0; i < length; i++) {
087: if (fileList[i].isDirectory()) {
088: fileList[i].delete();
089:
090: continue;
091: }
092:
093: if (!fileList[i].getName().endsWith("zip")) {
094: fileList[i].delete();
095: }
096: }
097: super .tearDown();
098: }
099:
100: public void testAll() throws Exception {
101:
102: final StringBuffer errors = new StringBuffer();
103: final int length = testFiles.length;
104: for (int i = 0; i < length; i++) {
105:
106: try {
107: runMe(testFiles[i]);
108:
109: } catch (Exception e) {
110: // e.printStackTrace();
111: final StringWriter writer = new StringWriter();
112: e.printStackTrace(new PrintWriter(writer));
113: errors.append("\nFile ").append(
114: testFiles[i].getAbsolutePath()).append(" :\n")
115: .append(e.getMessage()).append("\n").append(
116: writer.toString());
117: }
118: }
119:
120: if (errors.length() > 0) {
121: fail(errors.toString());
122: }
123: }
124:
125: public abstract void runMe(File file) throws Exception;
126: }
|