001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 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;
017:
018: // JUnit dependencies
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: // OpenGIS dependencies
024: import org.opengis.referencing.AuthorityFactory;
025: import org.opengis.referencing.FactoryException;
026: import org.opengis.referencing.crs.CoordinateReferenceSystem;
027:
028: // Geotools dependencies
029: import org.geotools.util.Version;
030: import org.geotools.referencing.CRS;
031:
032: /**
033: * Tests the {@link org.geotools.referencing.factory.URN_AuthorityFactory} with EPSG codes.
034: *
035: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/plugin/epsg-hsql/src/test/java/org/geotools/referencing/factory/URN_EPSG_Test.java $
036: * @version $Id: URN_EPSG_Test.java 25477 2007-05-10 13:01:00Z desruisseaux $
037: * @author Justin Deoliveira
038: * @author Martin Desruisseaux
039: */
040: public class URN_EPSG_Test extends TestCase {
041: /**
042: * Run the suite from the command line.
043: */
044: public static void main(final String[] args) {
045: junit.textui.TestRunner.run(suite());
046: }
047:
048: /**
049: * Returns the test suite.
050: */
051: public static Test suite() {
052: return new TestSuite(URN_EPSG_Test.class);
053: }
054:
055: /**
056: * Creates a suite of the given name.
057: */
058: public URN_EPSG_Test(final String name) {
059: super (name);
060: }
061:
062: /**
063: * Tests {@link AuthorityFactoryAdapter#isCodeMethodOverriden}.
064: */
065: public void testMethodOverriden() {
066: final Versioned test = new Versioned();
067: assertTrue(test.isCodeMethodOverriden());
068: }
069:
070: /**
071: * Tests the 4326 code.
072: */
073: public void test4326() throws FactoryException {
074: CoordinateReferenceSystem expected = CRS.decode("EPSG:4326");
075: CoordinateReferenceSystem actual = CRS
076: .decode("urn:ogc:def:crs:EPSG:6.8:4326");
077: assertSame(expected, actual);
078: actual = CRS.decode("urn:x-ogc:def:crs:EPSG:6.8:4326");
079: assertSame(expected, actual);
080: actual = CRS.decode("urn:ogc:def:crs:EPSG:6.11:4326");
081: assertSame(expected, actual);
082: }
083:
084: /**
085: * Tests versioning.
086: */
087: public void testVersion() throws FactoryException {
088: CoordinateReferenceSystem expected = CRS.decode("EPSG:4326");
089: final String version = String.valueOf(CRS.getVersion("EPSG"));
090: final String urn = "urn:ogc:def:crs:EPSG:" + version + ":4326";
091: final Versioned test = new Versioned();
092: final int failureCount = FallbackAuthorityFactory
093: .getFailureCount();
094: assertNull(test.lastVersion);
095: assertSame(expected, test.createCoordinateReferenceSystem(urn));
096: assertEquals(version, test.lastVersion.toString());
097: assertEquals("Primary factory should not fail.", failureCount,
098: FallbackAuthorityFactory.getFailureCount());
099:
100: test.lastVersion = null;
101: assertSame(expected, test.createCoordinateReferenceSystem(urn));
102: assertNull("Should not create a new factory.", test.lastVersion);
103: assertEquals("Primary factory should not fail.", failureCount,
104: FallbackAuthorityFactory.getFailureCount());
105:
106: assertSame(
107: expected,
108: test
109: .createCoordinateReferenceSystem("urn:ogc:def:crs:EPSG:6.11:4326"));
110: assertEquals("6.11", test.lastVersion.toString());
111: assertEquals("Should use the fallback factory.",
112: failureCount + 1, FallbackAuthorityFactory
113: .getFailureCount());
114: }
115:
116: /**
117: * A custom class for testing versioning.
118: */
119: private static final class Versioned extends URN_AuthorityFactory {
120: static Version lastVersion;
121:
122: protected AuthorityFactory createVersionedFactory(
123: final Version version) throws FactoryException {
124: lastVersion = version;
125: return super.createVersionedFactory(version);
126: }
127: }
128: }
|