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 java.math.BigDecimal;
21: import com.vividsolutions.jts.geom.Coordinate;
22: import com.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory;
23: import org.geotools.xml.ElementInstance;
24: import org.geotools.xml.Node;
25: import org.geotools.xs.bindings.XS;
26:
27: public class GMLCoordTypeBindingTest extends AbstractGMLBindingTest {
28: ElementInstance x;
29: ElementInstance y;
30: ElementInstance z;
31: ElementInstance coordinate;
32: MutablePicoContainer container;
33:
34: protected void setUp() throws Exception {
35: super .setUp();
36:
37: x = createElement(GML.NAMESPACE, "X", XS.DECIMAL, "12.34");
38: y = createElement(GML.NAMESPACE, "Y", XS.DECIMAL, "56.78");
39: z = createElement(GML.NAMESPACE, "Z", XS.DECIMAL, "910.11");
40: coordinate = createElement(GML.NAMESPACE, "myCoordinate",
41: GML.COORDTYPE, null);
42:
43: container = new DefaultPicoContainer();
44: container
45: .registerComponentInstance(CoordinateArraySequenceFactory
46: .instance());
47: container
48: .registerComponentImplementation(GMLCoordTypeBinding.class);
49: }
50:
51: public void testParse1D() throws Exception {
52: Node node = createNode(coordinate, new ElementInstance[] { x },
53: new Object[] { new BigDecimal(12.34) }, null, null);
54:
55: GMLCoordTypeBinding strategy = (GMLCoordTypeBinding) container
56: .getComponentInstanceOfType(GMLCoordTypeBinding.class);
57:
58: Coordinate c = (Coordinate) strategy.parse(coordinate, node,
59: null);
60: assertNotNull(c);
61: assertEquals(c.x, 12.34, 0d);
62: }
63:
64: public void testParse2D() throws Exception {
65: Node node = createNode(coordinate,
66: new ElementInstance[] { x, y }, new Object[] {
67: new BigDecimal(12.34), new BigDecimal(56.78) },
68: null, null);
69:
70: GMLCoordTypeBinding strategy = (GMLCoordTypeBinding) container
71: .getComponentInstanceOfType(GMLCoordTypeBinding.class);
72:
73: Coordinate c = (Coordinate) strategy.parse(coordinate, node,
74: null);
75: assertNotNull(c);
76: assertEquals(c.x, 12.34, 0d);
77: assertEquals(c.y, 56.78, 0d);
78: }
79:
80: public void testParse3D() throws Exception {
81: Node node = createNode(coordinate, new ElementInstance[] { x,
82: y, z }, new Object[] { new BigDecimal(12.34),
83: new BigDecimal(56.78), new BigDecimal(910.11) }, null,
84: null);
85: GMLCoordTypeBinding strategy = (GMLCoordTypeBinding) container
86: .getComponentInstanceOfType(GMLCoordTypeBinding.class);
87:
88: Coordinate c = (Coordinate) strategy.parse(coordinate, node,
89: null);
90: assertNotNull(c);
91: assertEquals(c.x, 12.34, 0d);
92: assertEquals(c.y, 56.78, 0d);
93: assertEquals(c.z, 910.11, 0d);
94: }
95: }
|