001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-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: * Created on August 16, 2003, 5:10 PM
017: */
018: package org.geotools.data;
019:
020: import java.util.Arrays;
021: import java.util.List;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: import org.opengis.filter.Filter;
028:
029: /**
030: *
031: * @author jamesm
032: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/main/src/test/java/org/geotools/data/DefaultQueryTest.java $
033: */
034: public class DefaultQueryTest extends TestCase {
035:
036: public DefaultQueryTest(java.lang.String testName) {
037: super (testName);
038: }
039:
040: public static Test suite() {
041: TestSuite suite = new TestSuite(DefaultQueryTest.class);
042: return suite;
043: }
044:
045: public void testFullConstructor() {
046: DefaultQuery query = new DefaultQuery("mytype", Filter.INCLUDE,
047: 10, new String[] { "foo" }, "myquery");
048: assertNotNull(query);
049: }
050:
051: /** Test of getPropertyNames method, of class org.geotools.data.DefaultQuery. */
052: public void testPropertyNames() {
053: System.out.println("testPropertyNames");
054: DefaultQuery query = new DefaultQuery();
055: assertNull(query.getPropertyNames());
056: query.setPropertyNames(new String[] { "foo", "bar" });
057: String names[] = query.getPropertyNames();
058: assertNotNull(names);
059: assertEquals("foo", names[0]);
060: List list = Arrays.asList(names);
061: query.setPropertyNames(list);
062: names = query.getPropertyNames();
063:
064: assertEquals("bar", names[1]);
065: query.setPropertyNames((List) null);
066: assertNull(query.getPropertyNames());
067:
068: query = new DefaultQuery("Test", Filter.INCLUDE, new String[] {
069: "foo", "wibble" });
070: assertNotNull(query.getPropertyNames());
071: }
072:
073: /** Test of retrieveAllProperties method, of class org.geotools.data.DefaultQuery. */
074: public void testRetrieveAllProperties() {
075: System.out.println("testRetrieveAllProperties");
076:
077: DefaultQuery query = new DefaultQuery();
078: assertTrue(query.retrieveAllProperties());
079:
080: query.setPropertyNames(new String[] { "foo", "bar" });
081: assertFalse(query.retrieveAllProperties());
082:
083: query.setPropertyNames((String[]) null);
084: assertTrue(query.retrieveAllProperties());
085:
086: query.setPropertyNames(new String[] { "foo", "bar" });
087: query.setPropertyNames((List) null);
088: assertTrue(query.retrieveAllProperties());
089: }
090:
091: /** Test of getMaxFeatures method, of class org.geotools.data.DefaultQuery. */
092: public void testMaxFeatures() {
093: System.out.println("testMaxFeatures");
094: DefaultQuery query = new DefaultQuery();
095: assertEquals(Query.DEFAULT_MAX, query.getMaxFeatures());
096:
097: query.setMaxFeatures(5);
098: assertEquals(5, query.getMaxFeatures());
099: }
100:
101: /** Test of getFilter method, of class org.geotools.data.DefaultQuery. */
102: public void testFilter() {
103: System.out.println("testGetFilter");
104: DefaultQuery query = new DefaultQuery();
105: query.setFilter(Filter.EXCLUDE);
106: assertEquals(Filter.EXCLUDE, query.getFilter());
107:
108: query = new DefaultQuery("test", Filter.INCLUDE);
109: assertEquals(Filter.INCLUDE, query.getFilter());
110: }
111:
112: /** Test of getTypeName method, of class org.geotools.data.DefaultQuery. */
113: public void testTypeName() {
114: DefaultQuery query = new DefaultQuery();
115: assertNull(query.getTypeName());
116:
117: query.setTypeName("foobar");
118: assertEquals("foobar", query.getTypeName());
119:
120: query = new DefaultQuery("mytype", Filter.EXCLUDE);
121: assertEquals("mytype", query.getTypeName());
122: }
123:
124: /** Test of getHandle method, of class org.geotools.data.DefaultQuery. */
125: public void testHandle() {
126: System.out.println("testGetHandle");
127: DefaultQuery query = new DefaultQuery();
128: assertNull(query.getHandle());
129: query.setHandle("myquery");
130: assertEquals("myquery", query.getHandle());
131: }
132:
133: /** Test of getVersion method, of class org.geotools.data.DefaultQuery. */
134: public void testVersion() {
135: System.out.println("testGetVersion");
136: DefaultQuery query = new DefaultQuery();
137: assertNull(query.getVersion());
138: }
139:
140: /** Test of toString method, of class org.geotools.data.DefaultQuery. */
141: public void testToString() {
142: System.out.println("testToString");
143: DefaultQuery query = new DefaultQuery();
144: assertNotNull(query.toString());
145:
146: query.setHandle("myquery");
147: assertNotNull(query.toString());
148:
149: query.setFilter(Filter.EXCLUDE);
150: assertNotNull(query.toString());
151:
152: query.setPropertyNames(new String[] { "foo", "bar" });
153: assertNotNull(query.toString());
154:
155: }
156:
157: }
|