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;
009: * version 2.1 of the License.
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.referencing.factory.epsg;
017:
018: // JSE dependencies
019: import java.util.Set;
020: import java.util.Iterator;
021: import java.io.PrintWriter;
022: import java.io.StringWriter;
023:
024: // OpenGIS dependencies
025: import org.opengis.metadata.Identifier;
026: import org.opengis.metadata.citation.Citation;
027: import org.opengis.referencing.IdentifiedObject;
028: import org.opengis.referencing.FactoryException;
029: import org.opengis.referencing.NoSuchAuthorityCodeException;
030: import org.opengis.referencing.crs.CoordinateReferenceSystem;
031:
032: // Geotools dependencies
033: import org.geotools.referencing.ReferencingFactoryFinder;
034: import org.geotools.referencing.NamedIdentifier;
035: import org.geotools.metadata.iso.citation.Citations;
036:
037: // JUnit dependencies
038: import junit.framework.Test;
039: import junit.framework.TestCase;
040: import junit.framework.TestSuite;
041:
042: /**
043: * Tests ESRI CRS support.
044: *
045: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-extension/src/test/java/org/geotools/referencing/factory/epsg/EsriExtensionTest.java $
046: * @version $Id: EsriExtensionTest.java 25398 2007-05-02 13:32:07Z desruisseaux $
047: * @author Jody Garnett
048: * @author Martin Desruisseaux
049: */
050: public class EsriExtensionTest extends TestCase {
051: /**
052: * The factory to test.
053: */
054: private EsriExtension factory;
055:
056: /**
057: * Returns the test suite.
058: */
059: public static Test suite() {
060: return new TestSuite(EsriExtensionTest.class);
061: }
062:
063: /**
064: * Run the test from the command line.
065: * Options: {@code -verbose}.
066: *
067: * @param args the command line arguments.
068: */
069: public static void main(final String[] args) {
070: junit.textui.TestRunner.run(suite());
071: }
072:
073: /**
074: * Creates a test case with the specified name.
075: */
076: public EsriExtensionTest(final String name) {
077: super (name);
078: }
079:
080: /**
081: * Get the authority factory for ESRI.
082: */
083: protected void setUp() throws Exception {
084: super .setUp();
085: factory = (EsriExtension) ReferencingFactoryFinder
086: .getCRSAuthorityFactory("ESRI", null);
087: }
088:
089: /**
090: * Tests the authority code.
091: */
092: public void testAuthority() {
093: Citation authority = factory.getAuthority();
094: assertNotNull(authority);
095: assertEquals("ESRI", authority.getTitle().toString());
096: assertTrue(factory instanceof EsriExtension);
097: }
098:
099: /**
100: * Tests the vendor.
101: */
102: public void testVendor() {
103: Citation vendor = factory.getVendor();
104: assertNotNull(vendor);
105: assertEquals("Geotools", vendor.getTitle().toString());
106: }
107:
108: /**
109: * Tests the codes.
110: */
111: public void testCodes() throws FactoryException {
112: final Set codes = factory
113: .getAuthorityCodes(IdentifiedObject.class);
114: final Set subset = factory
115: .getAuthorityCodes(CoordinateReferenceSystem.class);
116: assertNotNull(codes);
117: assertEquals(codes.size(), subset.size());
118: assertTrue(codes.containsAll(subset));
119: assertFalse(codes.contains("26910")); // This is an EPSG code.
120: // The following number may be adjusted if esri.properties is updated.
121: assertEquals(779, codes.size());
122: }
123:
124: /**
125: * Checks for duplication with EPSG-HSQL.
126: */
127: public void testDuplication() throws FactoryException {
128: final StringWriter buffer = new StringWriter();
129: final PrintWriter writer = new PrintWriter(buffer);
130: final Set duplicated = factory.reportDuplicatedCodes(writer);
131: assertTrue(buffer.toString(), duplicated.isEmpty());
132: }
133:
134: /**
135: * Checks for CRS instantiations.
136: */
137: public void testInstantiation() throws FactoryException {
138: final StringWriter buffer = new StringWriter();
139: final PrintWriter writer = new PrintWriter(buffer);
140: final Set duplicated = factory
141: .reportInstantiationFailures(writer);
142: // The following number may be adjusted if esri.properties is updated.
143: assertTrue(buffer.toString(), duplicated.size() <= 87);
144: }
145:
146: /**
147: * Tests an EPSG code.
148: */
149: public void test26910() throws FactoryException {
150: try {
151: CoordinateReferenceSystem crs = factory
152: .createCoordinateReferenceSystem("26910");
153: fail();
154: } catch (NoSuchAuthorityCodeException e) {
155: // This is the expected exception.
156: }
157: }
158:
159: /**
160: * Tests an EPSG code.
161: */
162: public void test4326() throws FactoryException {
163: try {
164: CoordinateReferenceSystem crs = factory
165: .createCoordinateReferenceSystem("4326");
166: fail();
167: } catch (NoSuchAuthorityCodeException e) {
168: // This is the expected exception.
169: }
170: }
171:
172: /**
173: * Tests an EPSG code.
174: */
175: public void test4269() throws FactoryException {
176: try {
177: CoordinateReferenceSystem crs = factory
178: .createCoordinateReferenceSystem("4269");
179: fail();
180: } catch (NoSuchAuthorityCodeException e) {
181: // This is the expected exception.
182: }
183: }
184:
185: /**
186: * Tests an extra code (neither EPSG or ESRI).
187: */
188: public void test42102() throws FactoryException {
189: try {
190: CoordinateReferenceSystem crs = factory
191: .createCoordinateReferenceSystem("42102");
192: fail();
193: } catch (NoSuchAuthorityCodeException e) {
194: // This is the expected exception.
195: }
196: }
197:
198: /**
199: * Tests an ESRI code.
200: */
201: public void test30591() throws FactoryException {
202: final CoordinateReferenceSystem crs = factory
203: .createCoordinateReferenceSystem("30591");
204: assertSame(crs, factory
205: .createCoordinateReferenceSystem("ESRI:30591"));
206: assertSame(crs, factory
207: .createCoordinateReferenceSystem("esri:30591"));
208: assertSame(crs, factory
209: .createCoordinateReferenceSystem(" ESRI : 30591 "));
210: assertSame(crs, factory
211: .createCoordinateReferenceSystem("EPSG:30591"));
212: assertSame(crs, factory.createObject("30591"));
213: final Set identifiers = crs.getIdentifiers();
214: assertNotNull(identifiers);
215: assertFalse(identifiers.isEmpty());
216:
217: String asString = identifiers.toString();
218: assertTrue(asString, identifiers.contains(new NamedIdentifier(
219: Citations.ESRI, "30591")));
220: assertTrue(asString, identifiers.contains(new NamedIdentifier(
221: Citations.EPSG, "30591")));
222:
223: final Iterator iterator = identifiers.iterator();
224: Identifier identifier;
225:
226: // Checks the first identifier.
227: assertTrue(iterator.hasNext());
228: identifier = (Identifier) iterator.next();
229: assertTrue(identifier instanceof NamedIdentifier);
230: assertEquals(Citations.ESRI, identifier.getAuthority());
231: assertEquals("30591", identifier.getCode());
232: assertEquals("ESRI:30591", identifier.toString());
233:
234: // Checks the second identifier.
235: assertTrue(iterator.hasNext());
236: identifier = (Identifier) iterator.next();
237: assertTrue(identifier instanceof NamedIdentifier);
238: assertEquals(Citations.EPSG, identifier.getAuthority());
239: assertEquals("30591", identifier.getCode());
240: assertEquals("EPSG:30591", identifier.toString());
241: }
242: }
|