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: * Created on Apr 29, 2004
018: */
019: package org.geotools.validation.xml;
020:
021: import java.io.File;
022: import java.io.FileNotFoundException;
023: import java.io.FileReader;
024: import java.net.URI;
025: import java.util.HashMap;
026: import java.util.Map;
027:
028: import junit.framework.TestCase;
029:
030: import org.geotools.validation.dto.PlugInDTO;
031: import org.geotools.validation.dto.TestDTO;
032: import org.geotools.validation.dto.TestSuiteDTO;
033:
034: /**
035: * XMLReaderTest purpose.
036: *
037: * <p>
038: * Description of XMLReaderTest ...
039: * </p>
040: *
041: * <p>
042: * Capabilities:
043: * </p>
044: *
045: * <ul>
046: * <li>
047: * Feature: description
048: * </li>
049: * </ul>
050: *
051: * <p>
052: * Example Use:
053: * </p>
054: * <pre><code>
055: * XMLReaderTest x = new XMLReaderTest(...);
056: * </code></pre>
057: *
058: * @author dzwiers, Refractions Research, Inc.
059: * @author $Author: sploreg $ (last modification)
060: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/extension/validation/src/test/java/org/geotools/validation/xml/XMLReaderTest.java $
061: * @version $Id: XMLReaderTest.java 22754 2006-11-16 03:03:20Z jgarnett $
062: */
063: public class XMLReaderTest extends TestCase {
064: public XMLReaderTest() {
065: super ("XMLReaderTest");
066: }
067:
068: public XMLReaderTest(String s) {
069: super (s);
070: }
071:
072: protected FileReader features() throws FileNotFoundException {
073: File file = new File(
074: "C:/Java/workspace/geoserver/conf/plugins/Constraint.xml");
075: if (!file.exists()) {
076: return null;
077: }
078: return new FileReader(file);
079: }
080:
081: public void testReadPlugIn() {
082: try {
083:
084: FileReader fr = features();
085: if (fr == null)
086: return;
087:
088: PlugInDTO dto = XMLReader.readPlugIn(fr);
089: assertNotNull("Error if null", dto);
090: assertTrue("Name read", "Constraint".equals(dto.getName()));
091: assertTrue("Description read",
092: "All features must pass the provided filter"
093: .equals(dto.getDescription()));
094: assertTrue("ClassName read",
095: "org.geoserver.validation.plugins.filter.OGCFilter"
096: .equals(dto.getClassName()));
097: assertNotNull("Should be one arg.", dto.getArgs());
098: assertTrue("Should be one arg.", dto.getArgs().size() == 1);
099: assertTrue("Arg. name", dto.getArgs().containsKey(
100: "tempDirectory"));
101: assertTrue("Arg. value : "
102: + dto.getArgs().get("tempDirectory"), dto.getArgs()
103: .containsValue(new URI("file:///c:/temp")));
104: } catch (Exception e) {
105: fail(e.toString());
106: }
107: }
108:
109: public void testReadTestSuite() {
110: try {
111: //set-up
112: FileReader fr = features();
113: if (fr == null)
114: return;
115:
116: Map m = new HashMap();
117: PlugInDTO dto = XMLReader.readPlugIn(fr);
118: m.put(dto.getName(), dto);
119: fr = new FileReader(
120: "C:/Java/workspace/geoserver/conf/plugins/NameInList.xml");
121: dto = XMLReader.readPlugIn(fr);
122: m.put(dto.getName(), dto);
123:
124: fr = new FileReader(
125: "C:/Java/workspace/geoserver/conf/validation/RoadTestSuite.xml");
126:
127: TestSuiteDTO testsuite = XMLReader.readTestSuite("test",
128: fr, m);
129: assertTrue("TestSuite Name read", "RoadTestSuite"
130: .equals(testsuite.getName()));
131:
132: // multi line so cannot effectively test
133:
134: /*assertTrue("TestSuite Description read",("This test suite checks each road name to see \n"+
135: "that they are of appropriate length and checks to \n"+
136: "see if they are on the list of possible road names.\n"+
137: "It also checks to see if any roads are contained in\n"+
138: "a specified box.").equals(testsuite.getDescription()));*/
139: TestDTO test = (TestDTO) testsuite.getTests().get(
140: "NameLookup");
141:
142: assertNotNull("NameLookup does not exist as a test", test);
143:
144: // multi line so cannot effectively test
145: // assertTrue("Test Description read","Checks to see if the road name is in the list of possible names.".equals(test.getDescription()));
146: assertNotNull("Should not be null", test.getPlugIn());
147: assertTrue("Test plugInName read", "NameInList".equals(test
148: .getPlugIn().getName()));
149:
150: assertNotNull("Should be one arg.", test.getArgs());
151: assertTrue("Should be one arg.", test.getArgs().size() == 2);
152: assertTrue("Arg. name", test.getArgs().containsKey(
153: "LUTName"));
154:
155: // multi line so cannot effectively test
156: //assertTrue("Arg. value : "+test.getArgs().get("LUTName"),test.getArgs().containsValue("RoadNameLUT.xls"));
157: } catch (Exception e) {
158: e.printStackTrace();
159: fail(e.toString());
160: }
161: }
162: }
|