001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, 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: // Java dependencies
019: import java.util.Set;
020: import java.util.Collection;
021: import java.io.PrintWriter;
022: import java.io.StringWriter;
023:
024: // OpenGIS dependencies
025: import org.opengis.metadata.citation.Citation;
026: import org.opengis.referencing.FactoryException;
027: import org.opengis.referencing.crs.ProjectedCRS;
028: import org.opengis.referencing.crs.CRSAuthorityFactory;
029: import org.opengis.referencing.crs.CoordinateReferenceSystem;
030:
031: // Geotools dependencies
032: import org.geotools.factory.Hints;
033: import org.geotools.referencing.CRS;
034: import org.geotools.referencing.NamedIdentifier;
035: import org.geotools.referencing.ReferencingFactoryFinder;
036: import org.geotools.referencing.factory.OrderedAxisAuthorityFactory;
037: import org.geotools.metadata.iso.citation.Citations;
038:
039: // JUnit dependencies
040: import junit.framework.Test;
041: import junit.framework.TestCase;
042: import junit.framework.TestSuite;
043:
044: /**
045: * Tests {@link UnnamedExtension}.
046: *
047: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-extension/src/test/java/org/geotools/referencing/factory/epsg/UnnamedExtensionTest.java $
048: * @version $Id: UnnamedExtensionTest.java 27925 2007-11-18 23:08:33Z desruisseaux $
049: * @author Martin Desruisseaux
050: * @author Jody Garnett
051: */
052: public class UnnamedExtensionTest extends TestCase {
053: /**
054: * The factory to test.
055: */
056: private UnnamedExtension factory;
057:
058: /**
059: * Returns the test suite.
060: */
061: public static Test suite() {
062: return new TestSuite(UnnamedExtensionTest.class);
063: }
064:
065: /**
066: * Run the test from the command line.
067: * Options: {@code -verbose}.
068: *
069: * @param args the command line arguments.
070: */
071: public static void main(final String[] args) {
072: org.geotools.util.logging.Logging.GEOTOOLS
073: .forceMonolineConsoleOutput();
074: junit.textui.TestRunner.run(suite());
075: }
076:
077: /**
078: * Creates a test case with the specified name.
079: */
080: public UnnamedExtensionTest(final String name) {
081: super (name);
082: }
083:
084: /**
085: * Gets the authority factory for ESRI.
086: */
087: protected void setUp() throws Exception {
088: super .setUp();
089: factory = (UnnamedExtension) ReferencingFactoryFinder
090: .getCRSAuthorityFactory("EPSG", new Hints(
091: Hints.CRS_AUTHORITY_FACTORY,
092: UnnamedExtension.class));
093: }
094:
095: /**
096: * Tests the authority code.
097: */
098: public void testAuthority() {
099: final Citation authority = factory.getAuthority();
100: assertNotNull(authority);
101: assertEquals("European Petroleum Survey Group", authority
102: .getTitle().toString());
103: assertTrue(authority.getIdentifiers().contains("EPSG"));
104: assertFalse(authority.getIdentifiers().contains("ESRI"));
105: assertTrue(factory instanceof UnnamedExtension);
106: }
107:
108: /**
109: * Tests the vendor.
110: */
111: public void testVendor() {
112: final Citation vendor = factory.getVendor();
113: assertNotNull(vendor);
114: assertEquals("Geotools", vendor.getTitle().toString());
115: }
116:
117: /**
118: * Checks for duplication with EPSG-HSQL.
119: */
120: public void testDuplication() throws FactoryException {
121: final StringWriter buffer = new StringWriter();
122: final PrintWriter writer = new PrintWriter(buffer);
123: final Set duplicated = factory.reportDuplicatedCodes(writer);
124: assertTrue(buffer.toString(), duplicated.isEmpty());
125: }
126:
127: /**
128: * Checks for CRS instantiations.
129: */
130: public void testInstantiation() throws FactoryException {
131: final StringWriter buffer = new StringWriter();
132: final PrintWriter writer = new PrintWriter(buffer);
133: final Set duplicated = factory
134: .reportInstantiationFailures(writer);
135: assertTrue(buffer.toString(), duplicated.isEmpty());
136: }
137:
138: /**
139: * Tests the {@code 41001} code.
140: */
141: public void test41001() throws FactoryException {
142: CoordinateReferenceSystem actual, expected;
143: expected = factory.createCoordinateReferenceSystem("41001");
144: actual = CRS.decode("EPSG:41001");
145: assertSame(expected, actual);
146: assertTrue(actual instanceof ProjectedCRS);
147: Collection ids = actual.getIdentifiers();
148: assertTrue(ids.contains(new NamedIdentifier(Citations.EPSG,
149: "41001")));
150: assertFalse(ids.contains(new NamedIdentifier(Citations.ESRI,
151: "41001")));
152: }
153:
154: /**
155: * UDIG requires this to work.
156: */
157: public void test42102() throws FactoryException {
158: final Hints hints = new Hints(Hints.CRS_AUTHORITY_FACTORY,
159: UnnamedExtension.class);
160: final CRSAuthorityFactory factory = new OrderedAxisAuthorityFactory(
161: "EPSG", hints, null);
162: final CoordinateReferenceSystem crs = factory
163: .createCoordinateReferenceSystem("EPSG:42102");
164: assertNotNull(crs);
165: assertNotNull(crs.getIdentifiers());
166: assertFalse(crs.getIdentifiers().isEmpty());
167: NamedIdentifier expected = new NamedIdentifier(Citations.EPSG,
168: "42102");
169: assertTrue(crs.getIdentifiers().contains(expected));
170: }
171:
172: /**
173: * WFS requires this to work.
174: */
175: public void test42102Lower() throws FactoryException {
176: CoordinateReferenceSystem crs = CRS.decode("epsg:42102");
177: assertNotNull(crs);
178: assertNotNull(crs.getIdentifiers());
179: assertFalse(crs.getIdentifiers().isEmpty());
180: NamedIdentifier expected = new NamedIdentifier(Citations.EPSG,
181: "42102");
182: assertTrue(crs.getIdentifiers().contains(expected));
183: }
184:
185: /**
186: * WFS requires this to work.
187: */
188: public void test42304Lower() throws FactoryException {
189: CoordinateReferenceSystem crs = CRS.decode("epsg:42304");
190: assertNotNull(crs);
191: }
192:
193: /**
194: * Tests the extensions through a URI.
195: *
196: * @see http://jira.codehaus.org/browse/GEOT-1563
197: */
198: public void testURI() throws FactoryException {
199: final String id = "100001";
200: final CoordinateReferenceSystem crs = CRS.decode("EPSG:" + id);
201: assertSame(crs, CRS.decode("urn:x-ogc:def:crs:EPSG:6.11.2:"
202: + id));
203: assertSame(crs,
204: CRS.decode("http://www.opengis.net/gml/srs/epsg.xml#"
205: + id));
206: }
207: }
|