001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2006, GeoTools Project Managment Committee (PMC)
005: * (C) 2006, Geomatys
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;
010: * version 2.1 of the License.
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.referencing.factory;
018:
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022:
023: import org.geotools.factory.Hints;
024: import org.opengis.referencing.AuthorityFactory;
025: import org.opengis.referencing.FactoryException;
026: import org.opengis.referencing.NoSuchAuthorityCodeException;
027: import org.opengis.referencing.crs.GeographicCRS;
028: import org.opengis.referencing.crs.CRSAuthorityFactory;
029: import org.opengis.referencing.crs.CoordinateReferenceSystem;
030:
031: import org.geotools.referencing.CRS;
032: import org.geotools.referencing.ReferencingFactoryFinder;
033: import org.geotools.referencing.crs.DefaultGeographicCRS;
034: import org.geotools.factory.FactoryNotFoundException;
035:
036: /**
037: * Tests the {@link URN_AuthorityFactory} class backed by WMS or AUTO factories.
038: *
039: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/factory/URN_AuthorityFactoryTest.java $
040: * @version $Id: URN_AuthorityFactoryTest.java 29058 2008-02-03 17:47:07Z desruisseaux $
041: * @author Martin Desruisseaux
042: */
043: public final class URN_AuthorityFactoryTest extends TestCase {
044: /**
045: * Run the suite from the command line.
046: */
047: public static void main(final String[] args) {
048: junit.textui.TestRunner.run(suite());
049: }
050:
051: /**
052: * Returns the test suite.
053: */
054: public static Test suite() {
055: return new TestSuite(URN_AuthorityFactoryTest.class);
056: }
057:
058: /**
059: * Creates a suite of the given name.
060: */
061: public URN_AuthorityFactoryTest(final String name) {
062: super (name);
063: }
064:
065: /**
066: * Make sure that a singleton instance is registered.
067: */
068: public void testRegistration() {
069: String authority = "URN:OGC:DEF";
070: final AuthorityFactory factory = ReferencingFactoryFinder
071: .getCRSAuthorityFactory(authority, null);
072: assertSame(factory, ReferencingFactoryFinder
073: .getCRSAuthorityFactory(authority, null));
074: assertSame(factory, ReferencingFactoryFinder
075: .getCSAuthorityFactory(authority, null));
076: assertSame(factory, ReferencingFactoryFinder
077: .getDatumAuthorityFactory(authority, null));
078: /*
079: * Tests the X-OGC namespace, which should be synonymous.
080: */
081: authority = "URN:X-OGC:DEF";
082: assertSame(factory, ReferencingFactoryFinder
083: .getCRSAuthorityFactory(authority, null));
084: assertSame(factory, ReferencingFactoryFinder
085: .getCSAuthorityFactory(authority, null));
086: assertSame(factory, ReferencingFactoryFinder
087: .getDatumAuthorityFactory(authority, null));
088: }
089:
090: /**
091: * Tests the CRS factory.
092: */
093: public void testCRS() throws FactoryException {
094: CRSAuthorityFactory factory = ReferencingFactoryFinder
095: .getCRSAuthorityFactory("URN:OGC:DEF", null);
096: GeographicCRS crs;
097: try {
098: crs = factory.createGeographicCRS("CRS:84");
099: fail();
100: } catch (NoSuchAuthorityCodeException exception) {
101: // This is the expected exception.
102: assertEquals("CRS:84", exception.getAuthorityCode());
103: }
104: crs = factory
105: .createGeographicCRS("urn:ogc:def:crs:CRS:WMS1.3:84");
106: assertSame(crs, factory
107: .createGeographicCRS("urn:ogc:def:crs:CRS:1.3:84"));
108: assertSame(crs, factory
109: .createGeographicCRS("URN:OGC:DEF:CRS:CRS:1.3:84"));
110: assertSame(crs, factory
111: .createGeographicCRS("URN:OGC:DEF:CRS:CRS:84"));
112: assertSame(crs, factory
113: .createGeographicCRS("urn:x-ogc:def:crs:CRS:1.3:84"));
114: assertSame(crs, CRS.decode("urn:ogc:def:crs:CRS:1.3:84"));
115: assertSame(crs, CRS.decode("CRS:84"));
116: assertNotSame(crs, DefaultGeographicCRS.WGS84);
117: assertFalse(DefaultGeographicCRS.WGS84.equals(crs));
118: assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84,
119: crs));
120:
121: // Test CRS:83
122: crs = factory.createGeographicCRS("urn:ogc:def:crs:CRS:1.3:83");
123: assertSame(crs, CRS.decode("CRS:83"));
124: assertFalse(CRS.equalsIgnoreMetadata(
125: DefaultGeographicCRS.WGS84, crs));
126: }
127:
128: /**
129: * Tests fetching the URN authority when the "longitude first axis order" hint is set.
130: */
131: public void testWhenForceXY() throws FactoryException {
132: try {
133: Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING,
134: "http");
135: Hints.putSystemDefault(
136: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
137: Boolean.TRUE);
138: try {
139: ReferencingFactoryFinder.getCRSAuthorityFactory(
140: "URN:OGC:DEF", null);
141: fail("URN factory should not accept FORCE_LONGITUDE_FIRST_AXIS_ORDER = TRUE");
142: } catch (FactoryNotFoundException e) {
143: // This is the expected exception.
144: }
145: CoordinateReferenceSystem crs = CRS.decode(
146: "URN:OGC:DEF:CRS:CRS:84", true);
147: assertTrue(CRS.equalsIgnoreMetadata(
148: DefaultGeographicCRS.WGS84, crs));
149: crs = CRS.decode("URN:OGC:DEF:CRS:CRS:84");
150: assertTrue(CRS.equalsIgnoreMetadata(
151: DefaultGeographicCRS.WGS84, crs));
152: } finally {
153: Hints.removeSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING);
154: Hints
155: .removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
156: }
157: }
158: }
|