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.bindings;
17:
18: import org.picocontainer.defaults.DefaultPicoContainer;
19: import com.vividsolutions.jts.geom.Coordinate;
20: import com.vividsolutions.jts.geom.GeometryFactory;
21: import com.vividsolutions.jts.geom.MultiPoint;
22: import com.vividsolutions.jts.geom.Point;
23: import org.geotools.xml.ElementInstance;
24: import org.geotools.xml.Node;
25:
26: public class GMLMultiPointTypeBindingTest extends
27: AbstractGMLBindingTest {
28: ElementInstance mp;
29: ElementInstance point1;
30: ElementInstance point2;
31: GeometryFactory gf;
32:
33: protected void setUp() throws Exception {
34: super .setUp();
35:
36: point1 = createElement(GML.NAMESPACE, "myPoint",
37: GML.POINTMEMBERTYPE, null);
38: point2 = createElement(GML.NAMESPACE, "myPoint",
39: GML.POINTMEMBERTYPE, null);
40: mp = createElement(GML.NAMESPACE, "myMultiPoint",
41: GML.MULTIPOINTTYPE, null);
42:
43: container = new DefaultPicoContainer();
44: container
45: .registerComponentImplementation(GeometryFactory.class);
46: container
47: .registerComponentImplementation(GMLGeometryCollectionTypeBinding.class);
48: container
49: .registerComponentImplementation(GMLMultiPointTypeBinding.class);
50: }
51:
52: public void test() throws Exception {
53: Node node = createNode(mp, new ElementInstance[] { point1,
54: point2 },
55: new Object[] {
56: new GeometryFactory()
57: .createPoint(new Coordinate(0, 0)),
58: new GeometryFactory()
59: .createPoint(new Coordinate(1, 1)) },
60: null, null);
61:
62: GMLGeometryCollectionTypeBinding s1 = (GMLGeometryCollectionTypeBinding) container
63: .getComponentInstanceOfType(GMLGeometryCollectionTypeBinding.class);
64: GMLMultiPointTypeBinding s2 = (GMLMultiPointTypeBinding) container
65: .getComponentInstanceOfType(GMLMultiPointTypeBinding.class);
66:
67: MultiPoint mpoint = (MultiPoint) s2.parse(mp, node, s1.parse(
68: mp, node, null));
69:
70: assertNotNull(mpoint);
71: assertEquals(mpoint.getNumGeometries(), 2);
72:
73: assertEquals(((Point) mpoint.getGeometryN(0)).getX(), 0d, 0d);
74: assertEquals(((Point) mpoint.getGeometryN(0)).getY(), 0d, 0d);
75: assertEquals(((Point) mpoint.getGeometryN(1)).getX(), 1d, 0d);
76: assertEquals(((Point) mpoint.getGeometryN(1)).getY(), 1d, 0d);
77: }
78: }
|