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.image;
018:
019: import java.io.File;
020: import java.io.FileNotFoundException;
021: import java.io.IOException;
022: import java.util.logging.Logger;
023:
024: import junit.textui.TestRunner;
025:
026: import org.geotools.coverage.grid.GridCoverage2D;
027: import org.geotools.test.TestData;
028:
029: /**
030: * TestCase subclass for testing readingb capabilities
031: *
032: * @author Simone Giannecchini
033: * @author Alessio Fabiani
034: * @author rgould
035: * @source $URL:
036: * http://svn.geotools.org/geotools/branches/2.4.x/modules/plugin/image/src/test/java/org/geotools/gce/image/WorldImageReaderTest.java $
037: */
038: public class WorldImageReaderTest extends WorldImageBaseTestCase {
039:
040: private WorldImageReader wiReader;
041:
042: private Logger logger = org.geotools.util.logging.Logging
043: .getLogger(WorldImageReaderTest.class.toString());
044:
045: /**
046: * Constructor for WorldImageReaderTest.
047: *
048: * @param arg0
049: */
050: public WorldImageReaderTest(String arg0) {
051: super (arg0);
052: }
053:
054: /*
055: * Can't test this, as these files aren't actually expected to exist. The
056: * constructor tries to create an inputStream and then throws an exception.
057: * Re-enable this if that behaviour changes, or if you feel like writing a
058: * windows-only test.
059: */
060: // public void testSource() throws Exception {
061: // URL altDrive = new URL("file://E:/somedir/foo.tif");
062: // WorldImageReader r = new WorldImageReader(altDrive);
063: // File result = (File) r.getSource();
064: // String s1 = result.getAbsolutePath();
065: // String s2 = "E:\\somedir\\foo.tif";
066: // assertTrue(s1.equals(s2));
067: //
068: // URL networkShare = new URL("file://borkServer/somedir/foo.tif");
069: // r = new WorldImageReader(networkShare);
070: // result = (File) r.getSource();
071: // s1 = result.getAbsolutePath();
072: // s2 = "\\\\borkServer\\somedir\\foo.tif";
073: // assertTrue(s1.equals(s2));
074: // }
075: /*
076: * @see TestCase#setUp()
077: */
078: protected void setUp() throws Exception {
079: super .setUp();
080: }
081:
082: public void testRead() throws IOException {
083:
084: // set up
085: Object in;
086:
087: // checking test data directory for all kind of inputs
088: final File test_data_dir = TestData.file(this , null);
089: final String[] fileList = test_data_dir
090: .list(new MyFileFilter());
091: final int length = fileList.length;
092: for (int i = 0; i < length; i++) {
093: // file
094: in = TestData.file(this , fileList[i]);
095: this .read(in);
096:
097: }
098:
099: // checking a WMS get map
100: // URL url = new URL(
101: // "http://wms.jpl.nasa.gov/wms.cgi?bbox=9,43,12,45&styles=&Format=image/png&request=GetMap&layers=global_mosaic&width=100&height=100&srs=EPSG:4326");
102: // // checking that we have an internet connection active and that the
103: // // website is up
104: // if (url.openConnection() == null)
105: // return;
106: // this.read(url);
107: }
108:
109: /**
110: * Read, test and show a coverage from the supplied source.
111: *
112: * @param source
113: * Object
114: *
115: * @throws FileNotFoundException
116: * DOCUMENT ME!
117: * @throws IOException
118: * DOCUMENT ME!
119: * @throws IllegalArgumentException
120: * DOCUMENT ME!
121: */
122: private void read(Object source) throws FileNotFoundException,
123: IOException, IllegalArgumentException {
124:
125: // can we read it?
126: assertTrue(new WorldImageFormat().accepts(source));
127:
128: logger.info(((File) source).getAbsolutePath());
129:
130: // get a reader
131: wiReader = new WorldImageReader(source);
132:
133: // get the coverage
134: final GridCoverage2D coverage = (GridCoverage2D) wiReader
135: .read(null);
136:
137: // test the coverage
138: assertNotNull(coverage);
139: assertNotNull((coverage).getRenderedImage());
140: assertNotNull(coverage.getEnvelope());
141:
142: // log some information
143: if (TestData.isInteractiveTest()) {
144: logger
145: .info(coverage.getCoordinateReferenceSystem()
146: .toWKT());
147: logger.info(coverage.getEnvelope().toString());
148: }
149: // show it, but only if tests are interactive
150: if (TestData.isInteractiveTest())
151: coverage.show();
152: else
153: coverage.getRenderedImage().getData();
154: }
155:
156: public static void main(String[] args) {
157: TestRunner.run(WorldImageReaderTest.class);
158: }
159: }
|