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.MutablePicoContainer;
19: import org.picocontainer.defaults.DefaultPicoContainer;
20: import com.vividsolutions.jts.geom.Coordinate;
21: import com.vividsolutions.jts.geom.GeometryFactory;
22: import com.vividsolutions.jts.geom.Point;
23: import org.geotools.xml.ElementInstance;
24: import org.geotools.xml.Node;
25:
26: public class GMLPointTypeBindingTest extends AbstractGMLBindingTest {
27: MutablePicoContainer container;
28: ElementInstance point;
29: ElementInstance coord;
30: ElementInstance coords;
31:
32: protected void setUp() throws Exception {
33: super .setUp();
34:
35: point = createElement(GML.NAMESPACE, "myPoint", GML.POINTTYPE,
36: null);
37: coord = createElement(GML.NAMESPACE, "coord", GML.COORDTYPE,
38: null);
39: coords = createElement(GML.NAMESPACE, "coordinates",
40: GML.COORDINATESTYPE, null);
41:
42: container = new DefaultPicoContainer();
43: container
44: .registerComponentImplementation(GeometryFactory.class);
45: container
46: .registerComponentImplementation(GMLPointTypeBinding.class);
47: }
48:
49: public void testParseCoordinate() throws Exception {
50: Node node = createNode(point, new ElementInstance[] { coord },
51: new Object[] { new Coordinate(12.34, 56.78) }, null,
52: null);
53:
54: GMLPointTypeBinding strategy = (GMLPointTypeBinding) container
55: .getComponentInstanceOfType(GMLPointTypeBinding.class);
56:
57: Point p = (Point) strategy.parse(point, node, null);
58: assertNotNull(p);
59: assertEquals(p.getX(), 12.34, 0d);
60: assertEquals(p.getY(), 56.78, 0d);
61: }
62:
63: public void testParseCoordinates() throws Exception {
64: Node node = createNode(point, new ElementInstance[] { coords },
65: new Object[] { createCoordinateSequence(new Coordinate(
66: 12.34, 56.78)) }, null, null);
67:
68: GMLPointTypeBinding strategy = (GMLPointTypeBinding) container
69: .getComponentInstanceOfType(GMLPointTypeBinding.class);
70:
71: Point p = (Point) strategy.parse(point, node, null);
72: assertNotNull(p);
73: assertEquals(p.getX(), 12.34, 0d);
74: assertEquals(p.getY(), 56.78, 0d);
75: }
76:
77: public void testParseMultiCoordinates() throws Exception {
78: Node node = createNode(
79: point,
80: new ElementInstance[] { coords },
81: new Object[] { createCoordinateSequence(new Coordinate[] {
82: new Coordinate(12.34, 56.78),
83: new Coordinate(9.10, 11.12) }) }, null, null);
84:
85: GMLPointTypeBinding strategy = (GMLPointTypeBinding) container
86: .getComponentInstanceOfType(GMLPointTypeBinding.class);
87:
88: try {
89: Point p = (Point) strategy.parse(point, node, null);
90: fail("Should have thrown an exception");
91: } catch (RuntimeException e) {
92: //ok
93: }
94: }
95: }
|