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 java.util.HashMap;
020:
021: import org.geotools.data.DataTestCase;
022: import org.geotools.data.DataUtilities;
023: import org.geotools.data.memory.MemoryDataStore;
024: import org.geotools.feature.Feature;
025: import org.geotools.feature.FeatureCollection;
026: import org.geotools.feature.IllegalAttributeException;
027: import org.geotools.validation.spatial.IsValidGeometryValidation;
028:
029: /**
030: * ValidationProcessorTest purpose.
031: * <p>
032: * Description of ValidationProcessorTest ...
033: * <p>
034: * Capabilities:
035: * <ul>
036: * </li></li>
037: * </ul>
038: * Example Use:
039: * <pre><code>
040: * ValidationProcessorTest x = new ValidationProcessorTest(...);
041: * </code></pre>
042: *
043: * @author bowens, Refractions Research, Inc.
044: * @author $Author: sploreg $ (last modification)
045: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/ValidationProcessorTest.java $
046: * @version $Id: ValidationProcessorTest.java 22754 2006-11-16 03:03:20Z jgarnett $
047: */
048: public class ValidationProcessorTest extends DataTestCase {
049: MemoryDataStore store;
050:
051: ValidationProcessor processor;
052: RoadNetworkValidationResults results;
053:
054: /**
055: * Constructor for ValidationProcessorTest.
056: * @param arg0
057: */
058: public ValidationProcessorTest(String arg0) {
059: super (arg0);
060: }
061:
062: /*
063: * @see TestCase#setUp()
064: */
065: protected void setUp() throws Exception {
066: super .setUp();
067: store = new MemoryDataStore();
068: store.addFeatures(roadFeatures);
069: store.addFeatures(riverFeatures);
070: processor = new ValidationProcessor();
071: results = new RoadNetworkValidationResults();
072: }
073:
074: /*
075: * @see TestCase#tearDown()
076: */
077: protected void tearDown() throws Exception {
078: super .tearDown();
079: store = null;
080: super .tearDown();
081: }
082:
083: public void testIsValidFeatureValidation() throws Exception {
084: IsValidGeometryValidation geom = new IsValidGeometryValidation();
085: geom.setName("IsValidGeometry");
086: geom.setDescription("IsValid geomtry test for Junit Test +"
087: + getName());
088: geom.setTypeRef("*");
089: processor.addValidation(geom);
090:
091: // test the correct roads
092: processor.runFeatureTests("dataStoreId", DataUtilities
093: .collection(this .roadFeatures), results);
094: assertTrue(results.getFailedMessages().length == 0);
095:
096: // test the broken road
097: // make an incorrect line
098: try {
099: this .newRoad = this .roadType.create(new Object[] {
100: new Integer(2), line(new int[] { 1, 2, 1, 2 }),
101: "r4" }, "road.rd4");
102: } catch (IllegalAttributeException e) {
103: }
104:
105: Feature[] singleRoad = new Feature[1];
106: singleRoad[0] = this .newRoad;
107: FeatureCollection features = DataUtilities
108: .collection(singleRoad);
109: processor.runFeatureTests("dataStoreId", features, results);
110: assertTrue(results.getFailedMessages().length > 0);
111:
112: // run integrity tests
113: // make a map of FeatureSources
114: HashMap map = new HashMap();
115: String[] typeNames = this .store.getTypeNames();
116: for (int i = 0; i < typeNames.length; i++)
117: map.put(typeNames[i], this .store
118: .getFeatureSource(typeNames[i]));
119: map.put("newThing", this .store.getFeatureSource(typeNames[0]));
120:
121: processor.runIntegrityTests(null, map, null, results);
122: assertTrue(results.getFailedMessages().length > 0);
123: /*
124: String[] messages = validationResults.getFailedMessages();
125: for (int i=0; i<validationResults.getFailedMessages().length; i++)
126: System.out.println(messages[i]);
127: */
128:
129: }
130:
131: }
|