001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, 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; either
009: * version 2.1 of the License, or (at your option) any later version.
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: package org.geotools.data;
017:
018: import java.io.IOException;
019: import java.util.NoSuchElementException;
020:
021: import org.geotools.feature.Feature;
022: import org.geotools.feature.IllegalAttributeException;
023: import org.opengis.filter.Filter;
024:
025: /**
026: * Test FilteredFeatureReader for conformance.
027: *
028: * @author Jody Garnett, Refractions Research
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/data/FilteringFeatureReaderTest.java $
030: */
031: public class FilteringFeatureReaderTest extends DataTestCase {
032: FeatureReader roadReader;
033: FeatureReader riverReader;
034:
035: /**
036: * Constructor for FilteringFeatureReaderTest.
037: * @param arg0
038: */
039: public FilteringFeatureReaderTest(String arg0) {
040: super (arg0);
041: }
042:
043: /*
044: * @see TestCase#setUp()
045: */
046: protected void setUp() throws Exception {
047: super .setUp();
048: roadReader = DataUtilities.reader(roadFeatures);
049: riverReader = DataUtilities.reader(riverFeatures);
050: }
051:
052: /*
053: * @see TestCase#tearDown()
054: */
055: protected void tearDown() throws Exception {
056: super .tearDown();
057: roadReader.close();
058: roadReader = null;
059: riverReader.close();
060: riverReader = null;
061: }
062:
063: public void testFilteringFeatureReaderALL() throws IOException {
064: FeatureReader reader;
065:
066: reader = new FilteringFeatureReader(DataUtilities
067: .reader(roadFeatures), Filter.EXCLUDE);
068: try {
069: assertFalse(reader.hasNext());
070: } finally {
071: reader.close();
072: }
073: reader = new FilteringFeatureReader(DataUtilities
074: .reader(roadFeatures), Filter.EXCLUDE);
075: assertEquals(0, count(reader));
076:
077: reader = new FilteringFeatureReader(DataUtilities
078: .reader(roadFeatures), Filter.EXCLUDE);
079: assertContents(new Feature[0], reader);
080: }
081:
082: public void testFilteringFeatureReaderNONE() throws IOException {
083: FeatureReader reader;
084: reader = new FilteringFeatureReader(DataUtilities
085: .reader(roadFeatures), Filter.INCLUDE);
086: try {
087: assertTrue(reader.hasNext());
088: } finally {
089: reader.close();
090: }
091: reader = DataUtilities.reader(roadFeatures);
092: assertEquals(roadFeatures.length, count(reader));
093:
094: reader = new FilteringFeatureReader(DataUtilities
095: .reader(roadFeatures), Filter.INCLUDE);
096: assertEquals(roadFeatures.length, count(reader));
097:
098: reader = new FilteringFeatureReader(DataUtilities
099: .reader(roadFeatures), Filter.INCLUDE);
100: assertContents(roadFeatures, reader);
101: }
102:
103: void assertContents(Feature expected[], FeatureReader reader)
104: throws IOException {
105: assertNotNull(reader);
106: assertNotNull(expected);
107: Feature feature;
108: int count = 0;
109: try {
110: for (int i = 0; i < expected.length; i++) {
111: assertTrue(reader.hasNext());
112: feature = reader.next();
113: assertNotNull(feature);
114: assertEquals(expected[i], feature);
115: count++;
116: }
117: assertFalse(reader.hasNext());
118: } catch (NoSuchElementException e) {
119: // bad dog!
120: throw new DataSourceException("hasNext() lied to me at:"
121: + count, e);
122: } catch (IllegalAttributeException e) {
123: throw new DataSourceException(
124: "next() could not understand feature at:" + count,
125: e);
126: } finally {
127: reader.close();
128: }
129: }
130:
131: public void testNext() {
132: }
133:
134: public void testClose() {
135: }
136:
137: public void testGetFeatureType() {
138: }
139:
140: public void testHasNext() {
141: }
142:
143: }
|