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: * NullZeroValidationTest purpose.
032: * <p>
033: * Description of NullZeroValidationTest ...
034: * <p>
035: * Capabilities:
036: * <ul>
037: * <li></li>
038: * </ul>
039: * Example Use:
040: * <pre><code>
041: * NullZeroValidationTest x = new NullZeroValidationTest(...);
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/NullZeroValidationTest.java $
047: * @version $Id: NullZeroValidationTest.java 20884 2006-08-07 14:10:46Z jgarnett $
048: */
049: public class NullZeroValidationTest extends TestCase {
050: private GeometryFactory gf;
051: private RoadValidationResults results;
052: private FeatureType type;
053: NullZeroValidation test;
054:
055: /**
056: * Constructor for NullZeroValidationTest.
057: * @param arg0
058: */
059: public NullZeroValidationTest(String arg0) {
060: super (arg0);
061: }
062:
063: /*
064: * @see TestCase#setUp()
065: */
066: protected void setUp() throws Exception {
067: super .setUp();
068:
069: gf = new GeometryFactory();
070: test = new NullZeroValidation();
071: test.setAttribute("name");
072: test.setTypeRef("road");
073: test.setName("JUnit");
074: test.setName("test used for junit test " + getName());
075:
076: type = DataUtilities.createType(getName() + ".road",
077: "id:0,*geom:LineString,name:String");
078:
079: results = new RoadValidationResults();
080: }
081:
082: private Feature road(String road, int id, String name)
083: throws IllegalAttributeException {
084: Coordinate[] coords = new Coordinate[] { new Coordinate(1, 1),
085: new Coordinate(2, 2), new Coordinate(4, 2),
086: new Coordinate(5, 1) };
087: return type.create(new Object[] { new Integer(id),
088: gf.createLineString(coords), name, }, type
089: .getTypeName()
090: + "." + road);
091: }
092:
093: /*
094: * @see TestCase#tearDown()
095: */
096: protected void tearDown() throws Exception {
097: test = null;
098: super .tearDown();
099: }
100:
101: public void testValidateNumber() throws Exception {
102: test.setTypeRef("road");
103: test.setAttribute("id");
104: assertTrue(test.validate(road("rd1", 1, "street"), type,
105: results));
106: assertFalse(test.validate(road("rd2", 0, "avenue"), type,
107: results));
108: }
109:
110: public void testValidateName() throws Exception {
111: test.setTypeRef("road");
112: test.setAttribute("name");
113: assertTrue(test.validate(road("rd1", 1, "street"), type,
114: results));
115: assertFalse(test.validate(road("rd2", 0, ""), type, results));
116: }
117:
118: public void testNameAccessors() {
119: test.setName("foo");
120: assertEquals("foo", test.getName());
121: }
122:
123: public void testDescriptionAccessors() {
124: test.setDescription("foo");
125: assertEquals("foo", test.getDescription());
126: }
127:
128: public void testGetPriority() {
129: test.getPriority();
130: }
131: }
|