001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.gml2.bindings;
017:
018: import com.vividsolutions.jts.geom.Coordinate;
019: import com.vividsolutions.jts.geom.Envelope;
020: import org.geotools.xml.ElementInstance;
021: import org.geotools.xml.Node;
022:
023: public class GMLBoxTypeBindingTest extends AbstractGMLBindingTest {
024: ElementInstance box;
025: ElementInstance coord1;
026: ElementInstance coord2;
027: ElementInstance coord3;
028: ElementInstance coords;
029:
030: protected void setUp() throws Exception {
031: super .setUp();
032:
033: box = createElement(GML.NAMESPACE, "myBox", GML.BOXTYPE, null);
034: coord1 = createElement(GML.NAMESPACE, "coord", GML.COORDTYPE,
035: null);
036: coord2 = createElement(GML.NAMESPACE, "coord", GML.COORDTYPE,
037: null);
038: coord3 = createElement(GML.NAMESPACE, "coord", GML.COORDTYPE,
039: null);
040: coords = createElement(GML.NAMESPACE, "coordinates",
041: GML.COORDINATESTYPE, null);
042: }
043:
044: public void testTwoCoord() throws Exception {
045: Node node = createNode(box, new ElementInstance[] { coord1,
046: coord2 }, new Object[] { new Coordinate(1, 2),
047: new Coordinate(3, 4) }, null, null);
048:
049: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
050: Envelope e = (Envelope) s.parse(box, node, null);
051: assertNotNull(e);
052: assertEquals(e.getMinX(), 1d, 0d);
053: assertEquals(e.getMinY(), 2d, 0d);
054: assertEquals(e.getMaxX(), 3d, 0d);
055: assertEquals(e.getMaxY(), 4d, 0d);
056: }
057:
058: public void testSingleCoord() throws Exception {
059: Node node = createNode(box, new ElementInstance[] { coord1 },
060: new Object[] { createCoordinateSequence(new Coordinate(
061: 1, 2)) }, null, null);
062:
063: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
064:
065: try {
066: Envelope e = (Envelope) s.parse(box, node, null);
067: fail("< 2 coordinate envelope should have thrown exception");
068: } catch (Exception e) {
069: //ok
070: }
071: }
072:
073: public void testMultiCoord() throws Exception {
074: Node node = createNode(box, new ElementInstance[] { coord1,
075: coord2, coord3 }, new Object[] {
076: createCoordinateSequence(new Coordinate(1, 2)),
077: createCoordinateSequence(new Coordinate(3, 4)),
078: createCoordinateSequence(new Coordinate(5, 6)) }, null,
079: null);
080:
081: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
082:
083: try {
084: Envelope e = (Envelope) s.parse(box, node, null);
085: fail("> 2 coordinate envelope should have thrown exception");
086: } catch (Exception e) {
087: //ok
088: }
089: }
090:
091: public void testTwoCoordinates() throws Exception {
092: Node node = createNode(
093: box,
094: new ElementInstance[] { coords },
095: new Object[] { createCoordinateSequence(new Coordinate[] {
096: new Coordinate(1, 2), new Coordinate(3, 4) }) },
097: null, null);
098:
099: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
100: Envelope e = (Envelope) s.parse(box, node, null);
101: assertNotNull(e);
102: assertEquals(e.getMinX(), 1d, 0d);
103: assertEquals(e.getMinY(), 2d, 0d);
104: assertEquals(e.getMaxX(), 3d, 0d);
105: assertEquals(e.getMaxY(), 4d, 0d);
106: }
107:
108: public void testSingleCoordinates() throws Exception {
109: Node node = createNode(box, new ElementInstance[] { coords },
110: new Object[] { createCoordinateSequence(new Coordinate(
111: 1, 2)) }, null, null);
112:
113: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
114:
115: try {
116: Envelope e = (Envelope) s.parse(box, node, null);
117: fail("< 2 coordinate envelope should have thrown exception");
118: } catch (Exception e) {
119: //ok
120: }
121: }
122:
123: public void testMultiCoordinates() throws Exception {
124: Node node = createNode(
125: box,
126: new ElementInstance[] { coords },
127: new Object[] { createCoordinateSequence(new Coordinate[] {
128: new Coordinate(1, 2), new Coordinate(3, 4),
129: new Coordinate(5, 6) }) }, null, null);
130:
131: GMLBoxTypeBinding s = (GMLBoxTypeBinding) getBinding(GML.BOXTYPE);
132:
133: try {
134: Envelope e = (Envelope) s.parse(box, node, null);
135: fail("> 2 coordinate envelope should have thrown exception");
136: } catch (Exception e) {
137: //ok
138: }
139: }
140: }
|