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 javax.xml.namespace.QName;
21: import com.vividsolutions.jts.geom.Point;
22: import org.geotools.feature.Feature;
23: import org.geotools.gml2.bindings.GML;
24: import org.geotools.xml.StreamingParser;
25:
26: public class GMLFeatureStreamingTest extends TestCase {
27: public void testStreamByXpath() throws Exception {
28: InputStream in = getClass().getResourceAsStream("feature.xml");
29: String xpath = "/featureMember/TestFeature";
30:
31: StreamingParser parser = new StreamingParser(
32: new TestConfiguration(), in, xpath);
33: makeAssertions(parser);
34:
35: in.close();
36: }
37:
38: public void testStreamByElementName() throws Exception {
39: InputStream in = getClass().getResourceAsStream("feature.xml");
40:
41: StreamingParser parser = new StreamingParser(
42: new TestConfiguration(), in, new QName(GML.NAMESPACE,
43: "featureMember"));
44: makeAssertions(parser);
45:
46: in.close();
47: }
48:
49: private void makeAssertions(StreamingParser parser) {
50: for (int i = 0; i < 3; i++) {
51: Feature f = (Feature) parser.parse();
52: assertNotNull(f);
53:
54: assertEquals(i + "", f.getID());
55: assertEquals(i, ((Point) f.getDefaultGeometry()).getX(), 0d);
56: assertEquals(i, ((Point) f.getDefaultGeometry()).getY(), 0d);
57: assertEquals(i, ((Integer) f.getAttribute("count"))
58: .intValue());
59: }
60:
61: assertNull(parser.parse());
62: }
63: }
|