001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2004 TOPP - www.openplans.org
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.validation.attributes;
018:
019: import junit.framework.TestCase;
020:
021: import org.geotools.data.DataUtilities;
022: import org.geotools.feature.Feature;
023: import org.geotools.feature.FeatureType;
024: import org.geotools.feature.IllegalAttributeException;
025: import org.geotools.validation.RoadValidationResults;
026:
027: import com.vividsolutions.jts.geom.Coordinate;
028: import com.vividsolutions.jts.geom.GeometryFactory;
029:
030: /**
031: * RangeFeatureValidationTest purpose.
032: * <p>
033: * Description of RangeFeatureValidationTest ...
034: * <p>
035: * Capabilities:
036: * <ul>
037: * <li></li>
038: * </ul>
039: * Example Use:
040: * <pre><code>
041: * RangeFeatureValidationTest x = new RangeFeatureValidationTest(...);
042: * </code></pre>
043: *
044: * @author bowens, Refractions Research, Inc.
045: * @author $Author: sploreg $ (last modification)
046: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/attributes/RangeFeatureValidationTest.java $
047: * @version $Id: RangeFeatureValidationTest.java 20884 2006-08-07 14:10:46Z jgarnett $
048: */
049: public class RangeFeatureValidationTest extends TestCase {
050: private GeometryFactory gf;
051: private RoadValidationResults results;
052: private FeatureType type;
053: private Feature feature;
054: RangeValidation test;
055:
056: /**
057: * Constructor for RangeFeatureValidationTest.
058: * @param arg0
059: */
060: public RangeFeatureValidationTest(String arg0) {
061: super (arg0);
062: }
063:
064: /*
065: * @see TestCase#setUp()
066: */
067: protected void setUp() throws Exception {
068: super .setUp();
069: gf = new GeometryFactory();
070:
071: test = new RangeValidation();
072: test.setAttribute("name");
073: test.setTypeRef("road");
074: test.setName("JUnit");
075: test.setName("test used for junit test " + getName());
076:
077: type = DataUtilities.createType(getName() + ".road",
078: "id:0,*geom:LineString,name:String");
079:
080: results = new RoadValidationResults();
081: }
082:
083: private Feature road(String road, int id, String name)
084: throws IllegalAttributeException {
085: Coordinate[] coords = new Coordinate[] { new Coordinate(1, 1),
086: new Coordinate(2, 2), new Coordinate(4, 2),
087: new Coordinate(5, 1) };
088: return type.create(new Object[] { new Integer(id),
089: gf.createLineString(coords), name, }, type
090: .getTypeName()
091: + "." + road);
092: }
093:
094: /*
095: * @see TestCase#tearDown()
096: */
097: protected void tearDown() throws Exception {
098: test = null;
099: super .tearDown();
100: }
101:
102: public void testSetName() {
103: test.setName("foo");
104: assertEquals("foo", test.getName());
105: }
106:
107: public void testGetName() {
108: test.setName("bork");
109: assertEquals("bork", test.getName());
110: }
111:
112: public void testSetDescription() {
113: test.setDescription("foo");
114: assertEquals("foo", test.getDescription());
115: }
116:
117: public void testGetDescription() {
118: test.setDescription("bork");
119: assertEquals("bork", test.getDescription());
120: }
121:
122: public void testGetPriority() {
123: //TODO Implement getPriority().
124: }
125:
126: public void testGetMax() {
127: test.setMax(100);
128: assertEquals(100, test.getMax());
129: }
130:
131: public void testGetMin() {
132: test.setMin(10);
133: assertEquals(10, test.getMin());
134: }
135:
136: public void testGetPath() {
137: test.setAttribute("path");
138: assertEquals("path", test.getAttribute());
139: }
140:
141: public void testSetMax() {
142: test.setMax(500);
143: assertEquals(500, test.getMax());
144:
145: }
146:
147: public void testSetMin() {
148: test.setMin(5);
149: assertEquals(5, test.getMin());
150: }
151:
152: public void testSetPath() {
153: test.setAttribute("path2");
154: assertEquals("path2", test.getAttribute());
155: }
156:
157: public void testRangeFeatureValidation() throws Exception {
158: test.setTypeRef("road");
159: test.setAttribute("id");
160: test.setMin(0);
161: assertTrue(test.validate(road("rd1", 1, "street"), type,
162: results));
163: assertTrue(test.validate(road("rd2", 0, "avenue"), type,
164: results));
165: assertFalse(test.validate(road("rd3", -1, "alley"), type,
166: results));
167: }
168:
169: }
|