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;
018:
019: import org.geotools.data.DataTestCase;
020: import org.geotools.data.memory.MemoryDataStore;
021: import org.geotools.feature.IllegalAttributeException;
022: import org.geotools.validation.spatial.IsValidGeometryValidation;
023:
024: /**
025: * FeatureValidationTest purpose.
026: *
027: * <p>
028: * Description of FeatureValidationTest ...
029: * </p>
030: *
031: * <p></p>
032: *
033: * @author jgarnett, Refractions Research, Inc.
034: * @author $Author: sploreg $ (last modification)
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/FeatureValidationTest.java $
036: * @version $Id: FeatureValidationTest.java 20884 2006-08-07 14:10:46Z jgarnett $
037: */
038: public class FeatureValidationTest extends DataTestCase {
039: MemoryDataStore store;
040:
041: /**
042: * FeatureValidationTest constructor.
043: *
044: * <p>
045: * Run test <code>testName</code>.
046: * </p>
047: *
048: * @param testName
049: */
050: public FeatureValidationTest(String testName) {
051: super (testName);
052: }
053:
054: /**
055: * Construct data store for use.
056: *
057: * @throws Exception
058: *
059: * @see junit.framework.TestCase#setUp()
060: */
061: protected void setUp() throws Exception {
062: super .setUp();
063: store = new MemoryDataStore();
064: store.addFeatures(roadFeatures);
065: store.addFeatures(riverFeatures);
066: }
067:
068: /**
069: * Override tearDown.
070: *
071: * @throws Exception
072: *
073: * @see junit.framework.TestCase#tearDown()
074: */
075: protected void tearDown() throws Exception {
076: store = null;
077: super .tearDown();
078: }
079:
080: public void testIsValidFeatureValidation() {
081: // the visitor
082: RoadValidationResults validationResults = new RoadValidationResults();
083:
084: IsValidGeometryValidation validator = new IsValidGeometryValidation();
085: validator.setName("isValidRoad");
086: validator.setDescription("Tests to see if a road is valid");
087: validator.setTypeRef("*");
088: validationResults.setValidation(validator);
089: assertTrue(validator.validate(this .newRoad, this .roadType,
090: validationResults));
091:
092: try {
093: this .newRoad = this .roadType.create(new Object[] {
094: new Integer(2), line(new int[] { 1, 2, 1, 2 }),
095: "r4" }, "road.rd4");
096: } catch (IllegalAttributeException e) {
097: }
098:
099: assertTrue(!validator.validate(this .newRoad, this .roadType,
100: validationResults)); // validate will return false
101: }
102:
103: /**
104: * testABunchOfValidations purpose.
105: *
106: * <p>
107: * Description ...
108: * </p>
109: */
110: public void testABunchOfValidations() {
111: // the visitor
112: RoadNetworkValidationResults roadValidationResults = new RoadNetworkValidationResults();
113:
114: // various FeatureType tests
115: IsValidGeometryValidation isValidValidator1 = new IsValidGeometryValidation();
116: isValidValidator1.setName("isValidRoad");
117: isValidValidator1
118: .setDescription("Tests to see if a road is valid");
119: isValidValidator1.setTypeRef("roads");
120:
121: IsValidGeometryValidation isValidValidator2 = new IsValidGeometryValidation();
122: isValidValidator2.setName("isValidRail");
123: isValidValidator2
124: .setDescription("Tests to see if a railway is valid");
125: isValidValidator2.setTypeRef("rails");
126:
127: IsValidGeometryValidation isValidValidator3 = new IsValidGeometryValidation();
128: isValidValidator3.setName("isValidRiver");
129: isValidValidator3
130: .setDescription("Tests to see if a river is valid");
131: isValidValidator3.setTypeRef("rivers");
132:
133: IsValidGeometryValidation isValidValidator4 = new IsValidGeometryValidation();
134: isValidValidator4.setName("isValidAll");
135: isValidValidator4
136: .setDescription("Tests to see if all geometries are valid");
137: isValidValidator4.setTypeRef("*");
138:
139: // various Integrity tests
140: //
141: //
142: //
143: // tell the RoadValidator what tests to use
144: roadValidationResults.setValidation(isValidValidator1);
145: roadValidationResults.setValidation(isValidValidator2);
146: roadValidationResults.setValidation(isValidValidator3);
147: roadValidationResults.setValidation(isValidValidator4);
148:
149: // run each feature validation test on the featureTypes it tests
150: String[] types1 = isValidValidator1.getTypeNames();
151:
152: for (int i = 0; i < types1.length; i++) {
153: //isValidValidator1.validate(featuresToTest(types[i]), featureType(types[i]), roadValidationResults);
154: }
155:
156: String[] types2 = isValidValidator1.getTypeNames();
157:
158: for (int i = 0; i < types2.length; i++) {
159: //isValidValidator2.validate(featuresToTest(types[i]), featureType(types[i]), roadValidationResults);
160: }
161:
162: String[] types3 = isValidValidator1.getTypeNames();
163:
164: for (int i = 0; i < types3.length; i++) {
165: //isValidValidator3.validate(featuresToTest(types[i]), featureType(types[i]), roadValidationResults);
166: }
167:
168: String[] types4 = isValidValidator1.getTypeNames();
169:
170: for (int i = 0; i < types4.length; i++) {
171: //isValidValidator4.validate(featuresToTest(types[i]), featureType(types[i]), roadValidationResults);
172: }
173:
174: // check the results of the roadValidator
175: String[] roadFailures = roadValidationResults
176: .getFailedMessages();
177: String[] roadWarnings = roadValidationResults
178: .getWarningMessages();
179: boolean roadsPassed = true;
180:
181: if (roadFailures.length != 0) {
182: roadsPassed = false;
183:
184: for (int i = 0; i < roadFailures.length; i++) {
185: System.out.println(roadFailures[i]);
186: }
187: }
188:
189: if (roadWarnings.length != 0) {
190: for (int i = 0; i < roadWarnings.length; i++) {
191: System.out.println(roadWarnings[i]);
192: }
193: }
194:
195: assertTrue(roadsPassed);
196: }
197: }
|