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.filter.v1_0;
17:
18: import org.w3c.dom.Document;
19: import org.w3c.dom.Element;
20: import org.opengis.filter.And;
21: import org.opengis.filter.Filter;
22: import org.opengis.filter.PropertyIsEqualTo;
23: import org.opengis.filter.spatial.Intersects;
24: import org.geotools.xml.Binding;
25:
26: public class OGCFilterTypeBindingTest extends FilterTestSupport {
27: public void testType() {
28: assertEquals(Filter.class, binding(OGC.FilterType).getType());
29: }
30:
31: public void testExecutionMode() {
32: assertEquals(Binding.OVERRIDE, binding(OGC.FilterType)
33: .getExecutionMode());
34: }
35:
36: public void testParseSpatial() throws Exception {
37: Element filterElement = FilterMockData.element(document,
38: document, OGC.Filter);
39: FilterMockData.intersects(document, filterElement);
40:
41: Filter filter = (Filter) parse();
42: assertTrue(filter instanceof Intersects);
43: }
44:
45: public void testEncodeSpatial() throws Exception {
46: Document doc = encode(FilterMockData.intersects(), OGC.Filter);
47: assertEquals("ogc:Filter", doc.getDocumentElement()
48: .getNodeName());
49:
50: assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE,
51: "Intersects").getLength());
52: }
53:
54: public void testParseComparison() throws Exception {
55: Element filterElement = FilterMockData.element(document,
56: document, OGC.Filter);
57: FilterMockData.propertyIsEqualTo(document, filterElement);
58:
59: Filter filter = (Filter) parse();
60: assertTrue(filter instanceof PropertyIsEqualTo);
61: }
62:
63: public void testEncodeComparison() throws Exception {
64: Document doc = encode(FilterMockData.propertyIsEqualTo(),
65: OGC.Filter);
66:
67: assertEquals("ogc:Filter", doc.getDocumentElement()
68: .getNodeName());
69: assertEquals(1, doc.getElementsByTagNameNS(OGC.NAMESPACE,
70: "PropertyIsEqualTo").getLength());
71: }
72:
73: public void testParseLogical() throws Exception {
74: Element filterElement = FilterMockData.element(document,
75: document, OGC.Filter);
76: FilterMockData.and(document, filterElement);
77:
78: Filter filter = (Filter) parse();
79: assertTrue(filter instanceof And);
80: }
81:
82: public void testEncodeLogical() throws Exception {
83: Document doc = encode(FilterMockData.and(), OGC.Filter);
84:
85: assertEquals("ogc:Filter", doc.getDocumentElement()
86: .getNodeName());
87: assertEquals(1, doc
88: .getElementsByTagNameNS(OGC.NAMESPACE, "And")
89: .getLength());
90: }
91: }
|