001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 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.filter.function;
017:
018: import junit.framework.TestCase;
019: import java.util.Collections;
020: import org.opengis.filter.FilterFactory;
021: import org.opengis.filter.expression.Function;
022: import org.opengis.metadata.citation.Citation;
023: import org.geotools.data.DataUtilities;
024: import org.geotools.factory.CommonFactoryFinder;
025: import org.geotools.feature.Feature;
026: import org.geotools.feature.FeatureType;
027: import org.geotools.feature.IllegalAttributeException;
028: import org.geotools.feature.SchemaException;
029: import org.geotools.metadata.iso.citation.CitationImpl;
030:
031: /**
032: *
033: * @since 2.4
034: * @author Gabriel Roldan, Axios Engineering
035: * @version $Id: PropertyExistsFunctionTest.java 24966 2007-03-30 11:33:47Z
036: * vmpazos $
037: * @source $URL:
038: * http://svn.geotools.org/geotools/trunk/gt/modules/library/cql/src/test/java/org/geotools/filter/function/PropertyExistsFunctionTest.java $
039: */
040: public class PropertyExistsFunctionTest extends TestCase {
041: private static final FilterFactory ff = CommonFactoryFinder
042: .getFilterFactory(null);
043: PropertyExistsFunction f;
044:
045: public void setUp() {
046: f = new PropertyExistsFunction();
047: }
048:
049: public void tearDown() {
050: f = null;
051: }
052:
053: public void testName() {
054: assertEquals("propertyexists", f.getName().toLowerCase());
055: }
056:
057: public void testFind() {
058: Function function = ff.function("propertyexists", ff
059: .property("testPropName"));
060: assertNotNull(function);
061: }
062:
063: public void testEvaluateFeature() throws SchemaException,
064: IllegalAttributeException {
065: FeatureType type = DataUtilities.createType("ns",
066: "name:string,geom:Geometry");
067: Feature feature = type
068: .create(new Object[] { "testName", null });
069:
070: f.setParameters(Collections.singletonList(ff
071: .property("nonExistant")));
072: assertEquals(Boolean.FALSE, f.evaluate(feature));
073:
074: f.setParameters(Collections.singletonList(ff.property("name")));
075: assertEquals(Boolean.TRUE, f.evaluate(feature));
076:
077: f.setParameters(Collections.singletonList(ff.property("geom")));
078: assertEquals(Boolean.TRUE, f.evaluate(feature));
079: }
080:
081: public void testEvaluatePojo() {
082: Citation pojo = new CitationImpl();
083:
084: f.setParameters(Collections.singletonList(ff
085: .property("edition")));
086: assertEquals(Boolean.TRUE, f.evaluate(pojo));
087:
088: f.setParameters(Collections.singletonList(ff
089: .property("alternateTitles")));
090: assertEquals(Boolean.TRUE, f.evaluate(pojo));
091:
092: // worng case (note the first letter)
093: f.setParameters(Collections.singletonList(ff
094: .property("AlternateTitles")));
095: assertEquals(Boolean.FALSE, f.evaluate(pojo));
096:
097: f.setParameters(Collections.singletonList(ff
098: .property("nonExistentProperty")));
099: assertEquals(Boolean.FALSE, f.evaluate(pojo));
100: }
101:
102: // @todo: REVISIT. don't we implement equals on functions/filters/etc?
103: // public void testEquals(){
104: // FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
105: // Function actual = new PropertyExistsFunction();
106: // f.setParameters(Collections.singletonList(ff.property("testPropName")));
107: // actual.setParameters(Collections.singletonList(ff.property("testPropName")));
108: // assertEquals(f, actual);
109: // }
110: }
|