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.CoordinateSequence;
22: import com.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory;
23: import org.geotools.xml.AttributeInstance;
24: import org.geotools.xml.ElementInstance;
25: import org.geotools.xml.Node;
26: import org.geotools.xs.bindings.XS;
27:
28: public class GMLCoordinatesTypeBindingTest extends
29: AbstractGMLBindingTest {
30: AttributeInstance decimal;
31: AttributeInstance ts;
32: AttributeInstance cs;
33: ElementInstance coordinates;
34: MutablePicoContainer container;
35:
36: protected void setUp() throws Exception {
37: super .setUp();
38:
39: decimal = createAtribute(GML.NAMESPACE, "decimal", XS.STRING,
40: ".");
41: ts = createAtribute(GML.NAMESPACE, "ts", XS.STRING, null);
42: cs = createAtribute(GML.NAMESPACE, "cs", XS.STRING, null);
43: coordinates = createElement(GML.NAMESPACE, "myCoordinates",
44: GML.COORDTYPE, null);
45: container = new DefaultPicoContainer();
46: container
47: .registerComponentInstance(CoordinateArraySequenceFactory
48: .instance());
49: container
50: .registerComponentImplementation(GMLCoordinatesTypeBinding.class);
51: }
52:
53: /*
54: * Test method for 'org.geotools.gml2.strategies.GMLCoordinatesTypeBinding.parse(Element, Node[], Node[], Object)'
55: */
56: public void testParseDefaults() throws Exception {
57: coordinates.setText("12.34,56.78 9.10,11.12 13.14,15.16");
58:
59: Node node = createNode(coordinates, null, null, null, null);
60: GMLCoordinatesTypeBinding strategy = (GMLCoordinatesTypeBinding) container
61: .getComponentInstanceOfType(GMLCoordinatesTypeBinding.class);
62:
63: CoordinateSequence c = (CoordinateSequence) strategy.parse(
64: coordinates, node, null);
65: assertNotNull(c);
66: assertEquals(3, c.size());
67: assertEquals(c.getCoordinate(0), new Coordinate(12.34, 56.78));
68: assertEquals(c.getCoordinate(1), new Coordinate(9.10, 11.12));
69: assertEquals(c.getCoordinate(2), new Coordinate(13.14, 15.16));
70: }
71:
72: public void testParseNonDefaults() throws Exception {
73: coordinates.setText("12.34:56.78;9.10:11.12;13.14:15.16");
74:
75: Node node = createNode(coordinates, null, null,
76: new AttributeInstance[] { cs, ts }, new String[] { ":",
77: ";" });
78:
79: GMLCoordinatesTypeBinding strategy = (GMLCoordinatesTypeBinding) container
80: .getComponentInstanceOfType(GMLCoordinatesTypeBinding.class);
81:
82: CoordinateSequence c = (CoordinateSequence) strategy.parse(
83: coordinates, node, null);
84: assertNotNull(c);
85: assertEquals(3, c.size());
86: assertEquals(c.getCoordinate(0), new Coordinate(12.34, 56.78));
87: assertEquals(c.getCoordinate(1), new Coordinate(9.10, 11.12));
88: assertEquals(c.getCoordinate(2), new Coordinate(13.14, 15.16));
89: }
90: }
|