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.MultiPolygon;
22: import com.vividsolutions.jts.geom.Polygon;
23: import org.geotools.xml.ElementInstance;
24: import org.geotools.xml.Node;
25:
26: public class GMLMultiPolygonPropertyTypeBindingTest extends
27: AbstractGMLBindingTest {
28: ElementInstance association;
29: ElementInstance geometry;
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33:
34: association = createElement(GML.NAMESPACE,
35: "myMultiPolygonProperty", GML.MULTIPOLYGONPROPERTYTYPE,
36: null);
37: geometry = createElement(GML.NAMESPACE, "myMultiPolygon",
38: GML.MULTIPOINTTYPE, null);
39:
40: container = new DefaultPicoContainer();
41: container
42: .registerComponentImplementation(GeometryFactory.class);
43: container
44: .registerComponentImplementation(GMLGeometryAssociationTypeBinding.class);
45: container
46: .registerComponentImplementation(GMLMultiPolygonPropertyTypeBinding.class);
47: }
48:
49: public void testWithGeometry() throws Exception {
50: Polygon p1 = new GeometryFactory().createPolygon(
51: new GeometryFactory()
52: .createLinearRing(new Coordinate[] {
53: new Coordinate(0, 0),
54: new Coordinate(1, 1),
55: new Coordinate(2, 2),
56: new Coordinate(0, 0) }), null);
57: Polygon p2 = new GeometryFactory().createPolygon(
58: new GeometryFactory()
59: .createLinearRing(new Coordinate[] {
60: new Coordinate(2, 2),
61: new Coordinate(3, 3),
62: new Coordinate(4, 4),
63: new Coordinate(2, 2) }), null);
64:
65: Node node = createNode(
66: association,
67: new ElementInstance[] { geometry },
68: new Object[] { new GeometryFactory()
69: .createMultiPolygon(new Polygon[] { p1, p2 }) },
70: null, null);
71:
72: GMLGeometryAssociationTypeBinding s = (GMLGeometryAssociationTypeBinding) container
73: .getComponentInstanceOfType(GMLGeometryAssociationTypeBinding.class);
74:
75: GMLMultiPolygonPropertyTypeBinding s1 = (GMLMultiPolygonPropertyTypeBinding) container
76: .getComponentInstanceOfType(GMLMultiPolygonPropertyTypeBinding.class);
77:
78: MultiPolygon p = (MultiPolygon) s1.parse(association, node, s
79: .parse(association, node, null));
80: assertNotNull(p);
81: }
82: }
|