001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002-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.data.jdbc;
017:
018: import java.util.logging.Logger;
019:
020: import junit.framework.TestCase;
021:
022: import org.geotools.feature.AttributeType;
023: import org.geotools.feature.AttributeTypeFactory;
024: import org.geotools.feature.Feature;
025: import org.geotools.feature.FeatureType;
026: import org.geotools.feature.FeatureTypeBuilder;
027: import org.geotools.feature.IllegalAttributeException;
028: import org.geotools.feature.SchemaException;
029:
030: import com.vividsolutions.jts.geom.Coordinate;
031: import com.vividsolutions.jts.geom.GeometryFactory;
032: import com.vividsolutions.jts.geom.LineString;
033:
034: /**
035: * Common filter testing code factored up here.
036: *
037: * @author Chris Holmes
038: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/jdbc/src/test/java/org/geotools/data/jdbc/SQLFilterTestSupport.java $
039: */
040: public abstract class SQLFilterTestSupport extends TestCase {
041: /** Standard logging instance */
042: protected static final Logger LOGGER = org.geotools.util.logging.Logging
043: .getLogger("org.geotools.filter");
044: protected static AttributeTypeFactory attFactory = AttributeTypeFactory
045: .defaultInstance();
046:
047: /** Schema on which to preform tests */
048: protected static FeatureType testSchema = null;
049:
050: /** Schema on which to preform tests */
051: protected static Feature testFeature = null;
052: protected boolean setup = false;
053:
054: /**
055: * Creates a new instance of TestCaseSupport
056: *
057: * @param name what to call this...
058: */
059: public SQLFilterTestSupport(String name) {
060: super (name);
061: }
062:
063: protected void setUp() throws SchemaException,
064: IllegalAttributeException {
065: if (setup) {
066: return;
067: } else {
068: prepareFeatures();
069: }
070:
071: setup = true;
072: }
073:
074: protected void prepareFeatures() throws SchemaException,
075: IllegalAttributeException {
076: //_log.getLoggerRepository().setThreshold(Level.INFO);
077: // Create the schema attributes
078: LOGGER.finer("creating flat feature...");
079:
080: AttributeType geometryAttribute = AttributeTypeFactory
081: .newAttributeType("testGeometry", LineString.class);
082: LOGGER.finer("created geometry attribute");
083:
084: AttributeType booleanAttribute = AttributeTypeFactory
085: .newAttributeType("testBoolean", Boolean.class);
086: LOGGER.finer("created boolean attribute");
087:
088: AttributeType charAttribute = AttributeTypeFactory
089: .newAttributeType("testCharacter", Character.class);
090: AttributeType byteAttribute = AttributeTypeFactory
091: .newAttributeType("testByte", Byte.class);
092: AttributeType shortAttribute = AttributeTypeFactory
093: .newAttributeType("testShort", Short.class);
094: AttributeType intAttribute = AttributeTypeFactory
095: .newAttributeType("testInteger", Integer.class);
096: AttributeType longAttribute = AttributeTypeFactory
097: .newAttributeType("testLong", Long.class);
098: AttributeType floatAttribute = AttributeTypeFactory
099: .newAttributeType("testFloat", Float.class);
100: AttributeType doubleAttribute = AttributeTypeFactory
101: .newAttributeType("testDouble", Double.class);
102: AttributeType stringAttribute = AttributeTypeFactory
103: .newAttributeType("testString", String.class);
104:
105: AttributeType[] types = { geometryAttribute, booleanAttribute,
106: charAttribute, byteAttribute, shortAttribute,
107: intAttribute, longAttribute, floatAttribute,
108: doubleAttribute, stringAttribute };
109:
110: // Builds the schema
111: testSchema = FeatureTypeBuilder.newFeatureType(types,
112: "testSchema");
113:
114: GeometryFactory geomFac = new GeometryFactory();
115:
116: // Creates coordinates for the linestring
117: Coordinate[] coords = new Coordinate[3];
118: coords[0] = new Coordinate(1, 2);
119: coords[1] = new Coordinate(3, 4);
120: coords[2] = new Coordinate(5, 6);
121:
122: // Builds the test feature
123: Object[] attributes = new Object[10];
124: attributes[0] = geomFac.createLineString(coords);
125: attributes[1] = new Boolean(true);
126: attributes[2] = new Character('t');
127: attributes[3] = new Byte("10");
128: attributes[4] = new Short("101");
129: attributes[5] = new Integer(1002);
130: attributes[6] = new Long(10003);
131: attributes[7] = new Float(10000.4);
132: attributes[8] = new Double(100000.5);
133: attributes[9] = "test string data";
134:
135: // Creates the feature itself
136: testFeature = testSchema.create(attributes);
137: LOGGER.finer("...flat feature created");
138:
139: //_log.getLoggerRepository().setThreshold(Level.DEBUG);
140: }
141: }
|