001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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.xml.ogc;
017:
018: import java.io.IOException;
019: import java.io.StringWriter;
020: import java.util.logging.Logger;
021:
022: import javax.naming.OperationNotSupportedException;
023:
024: import junit.framework.TestCase;
025:
026: import org.geotools.filter.BetweenFilter;
027: import org.geotools.filter.Expression;
028: import org.geotools.filter.FidFilter;
029: import org.geotools.filter.FilterFactory;
030: import org.geotools.filter.FilterFactoryFinder;
031: import org.geotools.filter.IllegalFilterException;
032: import org.geotools.filter.LikeFilter;
033: import org.geotools.xml.DocumentWriter;
034: import org.geotools.xml.filter.FilterSchema;
035:
036: /**
037: * For now just writes the expression built.
038: *
039: * @author David Zwiers, Refractions Research
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/ogc/ExpresionEncodeTest.java $
041: */
042: public class ExpresionEncodeTest extends TestCase {
043: /** Standard logging instance */
044: protected static final Logger LOGGER = org.geotools.util.logging.Logging
045: .getLogger("org.geotools.filter");
046: /** Constructor with test name. */
047: String dataFolder = "";
048:
049: public ExpresionEncodeTest(String testName) {
050: super (testName);
051:
052: //_log.getLoggerRepository().setThreshold(Level.DEBUG);
053: LOGGER.finer("running XMLEncoderTests");
054:
055: dataFolder = System.getProperty("dataFolder");
056:
057: if (dataFolder == null) {
058: //then we are being run by maven
059: dataFolder = System.getProperty("basedir");
060: dataFolder = "file:////" + "tests/unit/testData"; //url.toString();
061: LOGGER.finer("data folder is " + dataFolder);
062: }
063: }
064:
065: public void testPropBetweenFilter() throws IllegalFilterException,
066: OperationNotSupportedException, IOException {
067: FilterFactory ff = FilterFactoryFinder.createFilterFactory();
068: BetweenFilter bf = ff.createBetweenFilter();
069: bf.addLeftValue(ff.createLiteralExpression(60000));
070: bf.addMiddleValue(ff.createAttributeExpression("testDouble"));
071: bf.addRightValue(ff.createLiteralExpression(200000));
072:
073: StringWriter output = new StringWriter();
074: DocumentWriter.writeFragment(bf, FilterSchema.getInstance(),
075: output, null);
076:
077: // System.out.println(output);
078: }
079:
080: public void testLikeFilter() throws IllegalFilterException,
081: OperationNotSupportedException, IOException {
082: FilterFactory ff = FilterFactoryFinder.createFilterFactory();
083: Expression testAttribute = ff
084: .createAttributeExpression("testString");
085:
086: LikeFilter lf = ff.createLikeFilter();
087: lf.setValue(testAttribute);
088: lf.setPattern(ff.createLiteralExpression("test*"), "*", ".",
089: "!");
090:
091: StringWriter output = new StringWriter();
092: DocumentWriter.writeFragment(lf, FilterSchema.getInstance(),
093: output, null);
094:
095: //System.out.println(output);
096: }
097:
098: public void testFidFilter() throws OperationNotSupportedException,
099: IOException {
100: FilterFactory ff = FilterFactoryFinder.createFilterFactory();
101: FidFilter fif = ff.createFidFilter();
102: fif.addFid("f1");
103: fif.addFid("f2");
104: fif.addFid("f3");
105: fif.addFid("f4");
106:
107: StringWriter output = new StringWriter();
108: DocumentWriter.writeFragment(fif, FilterSchema.getInstance(),
109: output, null);
110:
111: //System.out.println(output);
112: }
113: }
|