001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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.validation;
017:
018: import java.io.File;
019: import java.io.FilenameFilter;
020: import java.util.Map;
021:
022: import org.geotools.data.DefaultRepository;
023: import org.geotools.feature.FeatureIterator;
024: import org.geotools.data.Repository;
025: import org.geotools.data.memory.MemoryDataStore;
026: import org.geotools.data.shapefile.ShapefileDataStore;
027: import org.geotools.test.TestData;
028: import org.geotools.validation.xml.XMLReader;
029:
030: /**
031: * A proper test fixture for the ValidationProcessor (and friends to hit).
032: *
033: * <p>
034: * For geoserver developers this environment is similar to confDemo. Where
035: * possible names have been forced to agree with geoserver.
036: * </p>
037: * <p>
038: * In the interests of saving space the contents of confDemo have been reduced to:
039: * <ul>
040: * <li>lakes - MultiPolygon
041: * <li>streams - MultiLinestring
042: * <li>swamps - MultiPolygon
043: * <li>rivers - MultiPolygon
044: * </ul>
045: * The complete confDemo also includes a large road and building shapefile.
046: * </p>
047: * @author Jody Garnett
048: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/TestFixture.java $
049: */
050: public class TestFixture {
051: Repository data = new DefaultRepository();
052: public Map pluginDTOs;
053: public Map testSuiteDTOs;
054: public ValidationProcessor processor;
055: public DefaultRepository repository;
056:
057: /** Starting point for your own TestFixture */
058: public TestFixture(File pluginDir, File testDir, File propertiesFile)
059: throws Exception {
060: repository = new DefaultRepository();
061: repository.load(propertiesFile);
062:
063: pluginDTOs = XMLReader.loadPlugIns(pluginDir);
064: testSuiteDTOs = XMLReader.loadValidations(testDir, pluginDTOs);
065: processor = new ValidationProcessor();
066: processor.load(pluginDTOs, testSuiteDTOs);
067: }
068:
069: /**
070: * Sets up a test fixture based on GeoServer confDemo.
071: * <p>
072: * The shapefiles are copied into MemoryDataStores - allowing tests to be more
073: * abusive.
074: * </p>
075: */
076: public TestFixture() throws Exception {
077: repository = new DefaultRepository();
078: File directory = TestData.file(this , "shapefiles");
079: String shapefiles[] = directory.list(new FilenameFilter() {
080: public boolean accept(File dir, String name) {
081: return name.toUpperCase().endsWith(".SHP");
082: }
083: });
084: for (int i = 0; i < shapefiles.length; i++) {
085: File shapefile = new File(directory, shapefiles[i]);
086: ShapefileDataStore dataStore = new ShapefileDataStore(
087: shapefile.toURL());
088: String dataStoreId = dataStore.getTypeNames()[0]
089: .toUpperCase();
090: String typeName = dataStore.getTypeNames()[0];
091: FeatureIterator features = dataStore.getFeatureSource(
092: typeName).getFeatures().features();
093: MemoryDataStore cache = new MemoryDataStore(features);
094:
095: repository.register(dataStoreId, cache);
096: }
097: File pluginDir = TestData.file(this , "plugins");
098: File validationDir = TestData.file(this , "validation");
099:
100: pluginDTOs = XMLReader.loadPlugIns(pluginDir);
101: testSuiteDTOs = XMLReader.loadValidations(validationDir,
102: pluginDTOs);
103:
104: processor = new ValidationProcessor();
105: processor.load(pluginDTOs, testSuiteDTOs);
106: }
107: }
|