01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation;
09: * version 2.1 of the License.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: */
16: package org.geotools.gml2;
17:
18: import junit.framework.TestCase;
19: import java.io.InputStream;
20: import com.vividsolutions.jts.geom.LineString;
21: import com.vividsolutions.jts.geom.Point;
22: import com.vividsolutions.jts.geom.Polygon;
23: import org.geotools.xml.Configuration;
24: import org.geotools.xml.StreamingParser;
25:
26: public class GMLGeometryStreamingTest extends TestCase {
27: public void testStreamByXpath() throws Exception {
28: Configuration configuration = new GMLConfiguration();
29: InputStream input = getClass().getResourceAsStream(
30: "geometry.xml");
31: String xpath = "/pointMember | /lineStringMember | /polygonMember";
32:
33: //String xpath = "/child::*";
34: StreamingParser parser = new StreamingParser(configuration,
35: input, xpath);
36:
37: makeAssertions(parser);
38: }
39:
40: // public void testStreamByType() throws Exception {
41: // Configuration configuration = new GMLConfiguration();
42: // InputStream input = getClass().getResourceAsStream("geometry.xml");
43: // StreamingParser parser = new StreamingParser(configuration, input , Geometry.class );
44: //
45: // makeAssertions( parser );
46: // }
47: private void makeAssertions(StreamingParser parser) {
48: Object o = parser.parse();
49: assertNotNull(o);
50: assertTrue(o instanceof Point);
51:
52: o = parser.parse();
53: assertNotNull(o);
54: assertTrue(o instanceof LineString);
55:
56: o = parser.parse();
57: assertNotNull(o);
58: assertTrue(o instanceof Polygon);
59:
60: o = parser.parse();
61: assertNull(o);
62: }
63: }
|