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 junit.framework.TestCase;
19: import java.io.ByteArrayInputStream;
20: import org.opengis.filter.Filter;
21: import org.opengis.filter.PropertyIsEqualTo;
22: import org.opengis.filter.expression.Literal;
23: import org.opengis.filter.expression.PropertyName;
24: import org.geotools.xml.Configuration;
25: import org.geotools.xml.Parser;
26: import org.geotools.xml.Parser.Properties;
27:
28: public class OGCFilterTest extends TestCase {
29: Parser parser;
30:
31: protected void setUp() throws Exception {
32: super .setUp();
33:
34: Configuration configuration = new OGCConfiguration();
35: parser = new Parser(configuration);
36: }
37:
38: public void testRun() throws Exception {
39: Object thing = parser.parse(getClass().getResourceAsStream(
40: "test1.xml"));
41: assertNotNull(thing);
42: assertTrue(thing instanceof PropertyIsEqualTo);
43:
44: PropertyIsEqualTo equal = (PropertyIsEqualTo) thing;
45: assertTrue(equal.getExpression1() instanceof PropertyName);
46: assertTrue(equal.getExpression2() instanceof Literal);
47:
48: PropertyName name = (PropertyName) equal.getExpression1();
49: assertEquals("testString", name.getPropertyName());
50:
51: Literal literal = (Literal) equal.getExpression2();
52: assertEquals("2", literal.toString());
53: }
54:
55: public void testLax() throws Exception {
56: String xml = "<Filter>" + " <PropertyIsEqualTo>"
57: + " <PropertyName>foo</PropertyName>"
58: + " <Literal>bar</Literal>"
59: + " </PropertyIsEqualTo>" + "</Filter>";
60:
61: OGCConfiguration configuration = new OGCConfiguration();
62: configuration.getProperties().add(
63: Properties.IGNORE_SCHEMA_LOCATION);
64:
65: Parser parser = new Parser(configuration);
66: Filter filter = (Filter) parser.parse(new ByteArrayInputStream(
67: xml.getBytes()));
68: assertNotNull(filter);
69: }
70: }
|