001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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.xml;
017:
018: import java.io.File;
019: import java.io.IOException;
020: import java.net.URI;
021: import java.util.logging.Level;
022:
023: import junit.framework.TestCase;
024:
025: import org.geotools.data.FeatureReader;
026: import org.geotools.feature.Feature;
027: import org.geotools.TestData;
028: import org.geotools.xml.gml.FCBuffer;
029:
030: /**
031: * <p>
032: * DOCUMENT ME!
033: * </p>
034: * @
035: *
036: * @author dzwiers www.refractions.net
037: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/GMLStreamingParserStressTest.java $
038: */
039: public class GMLStreamingParserStressTest extends TestCase {
040:
041: // public void testOSDNFFeatures() throws SAXException, IOException {
042: // FeatureReader fr = null;
043: // try {
044: //
045: // String path = "/home/dzwiers/testData/sample-master-map.xml";
046: // File f = new File(path);
047: // URI u = f.toURI();
048: //
049: // XMLSAXHandler.setLogLevel(Level.FINEST);
050: // XSISAXHandler.setLogLevel(Level.FINEST);
051: // XMLElementHandler.setLogLevel(Level.FINEST);
052: // XSIElementHandler.setLogLevel(Level.FINEST);
053: // fr = FCBuffer.getFeatureReader(u,10,100000);
054: //
055: // assertNotNull("FeatureReader missing", fr);
056: //
057: // int i=0;
058: // for(;fr.hasNext();i++){
059: // System.out.println(fr.next());
060: // }
061: //
062: // assertTrue("# features = "+i,i==70);
063: //
064: // } catch (Throwable e) {
065: // e.printStackTrace();
066: // fail(e.toString());
067: // } finally {
068: // if(fr!=null){
069: // ((FCBuffer)fr).stop();
070: // }
071: // }
072: // }
073:
074: public void skippedtestGTRoadsFeatures() throws IOException {
075: if (!TestData.isExtensiveTest())
076: return;
077: FeatureReader fr = null;
078: try {
079:
080: String path = "xml/geoserver/roads.xml";
081: File f = TestData.copy(this , path);
082: TestData.copy(this , "xml/wfs/WFS-basic.xsd");
083: TestData.copy(this , "xml/geoserver/roadSchema.xsd");
084: URI u = f.toURI();
085:
086: XMLSAXHandler.setLogLevel(Level.FINEST);
087: XSISAXHandler.setLogLevel(Level.FINEST);
088: XMLElementHandler.setLogLevel(Level.FINEST);
089: XSIElementHandler.setLogLevel(Level.FINEST);
090: fr = FCBuffer.getFeatureReader(u, 10, 10000);
091:
092: assertNotNull("FeatureReader missing", fr);
093:
094: int i = 0;
095: for (; fr.hasNext(); i++) {
096: // System.out.println(fr.next());
097: fr.next();
098: }
099:
100: assertTrue("# features = " + i, i == 70);
101:
102: } catch (Throwable e) {
103: e.printStackTrace();
104: fail(e.toString());
105: } finally {
106: if (fr != null) {
107: ((FCBuffer) fr).close();
108: }
109: }
110: }
111:
112: public void testFMERoadsFeatures() throws IOException {
113: if (!TestData.isExtensiveTest())
114: return;
115: FeatureReader fr = null;
116: try {
117: String path = "xml/fme/roads/roads.xml";
118: File f = TestData.copy(this , path);
119: TestData.copy(this , "xml/fme/roads/roads.xsd");
120: URI u = f.toURI();
121:
122: fr = FCBuffer.getFeatureReader(u, 10, 10000);
123:
124: assertNotNull("FeatureReader missing", fr);
125:
126: int i = 0;
127: for (; fr.hasNext(); i++) {
128: // System.out.println(fr.next());
129: fr.next();
130: }
131:
132: assertTrue("# features " + i, i > 20);
133: System.out.println("\n # Features = " + i);
134:
135: } catch (Throwable e) {
136: e.printStackTrace();
137: fail(e.toString());
138: } finally {
139: if (fr != null) {
140: ((FCBuffer) fr).close();
141: }
142: }
143: }
144:
145: public void testFMELakesFeatures() throws IOException {
146: if (!TestData.isExtensiveTest())
147: return;
148: FeatureReader fr = null;
149: try {
150: String path = "xml/fme/lakes/lakes.xml";
151: File f = TestData.copy(this , path);
152: TestData.copy(this , "xml/fme/lakes/lakes.xsd");
153: URI u = f.toURI();
154:
155: fr = FCBuffer.getFeatureReader(u, 10, 10000);
156:
157: assertNotNull("FeatureReader missing", fr);
158:
159: int i = 0;
160: for (; fr.hasNext(); i++) {
161: // System.out.println(fr.next());
162: fr.next();
163: }
164:
165: assertTrue("# features" + i, i > 20);
166: System.out.println("\n # Features = " + i);
167:
168: } catch (Throwable e) {
169: e.printStackTrace();
170: fail(e.toString());
171: } finally {
172: if (fr != null) {
173: ((FCBuffer) fr).close();
174: }
175: }
176: }
177:
178: public void testFME2StreamsFeatures() throws IOException {
179: if (!TestData.isExtensiveTest())
180: return;
181: FeatureReader fr1 = null;
182: FeatureReader fr2 = null;
183: try {
184: String path = "xml/fme/lakes/lakes.xml";
185: File f = TestData.copy(this , path);
186: TestData.copy(this , "xml/fme/lakes/lakes.xsd");
187: URI u1 = f.toURI();
188:
189: path = "xml/fme/roads/roads.xml";
190: f = TestData.copy(this , path);
191: TestData.copy(this , "xml/geoserver/roadSchema.xsd");
192: URI u2 = f.toURI();
193:
194: fr1 = FCBuffer.getFeatureReader(u1, 10, 10000);
195: fr2 = FCBuffer.getFeatureReader(u2, 10, 10000);
196:
197: assertNotNull("FeatureReader missing", fr1);
198: assertNotNull("FeatureReader missing", fr2);
199:
200: boolean cont = true;
201: int count1, count2;
202: count1 = count2 = 0;
203: while (cont) {
204: cont = false;
205: for (int i = 0; i < 10 && fr1.hasNext(); i++) {
206: Feature ftr = fr1.next();
207: assertTrue("Feature Null", ftr != null);
208: // System.out.println(ftr);
209: cont = true;
210: count1++;
211: }
212: for (int i = 0; i < 10 && fr2.hasNext(); i++) {
213: Feature ftr = fr2.next();
214: assertTrue("Feature Null", ftr != null);
215: // System.out.println(ftr);
216: cont = true;
217: count2++;
218: }
219: }
220: assertTrue("Must have used both readers",
221: (count1 > 20 && count2 > 20));
222: System.out.println("\n# Features: " + count1 + " , "
223: + count2);
224:
225: } catch (Throwable e) {
226: e.printStackTrace();
227: fail(e.toString());
228: } finally {
229: if (fr1 != null) {
230: ((FCBuffer) fr1).close();
231: }
232: if (fr2 != null) {
233: ((FCBuffer) fr2).close();
234: }
235: }
236: }
237: }
|