001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, GeoTools Project Managment Committee (PMC)
005: * (C) 2007, 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: // JUnit dependencies
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: // OpenGIS dependencies
025: import org.geotools.factory.Hints;
026: import org.opengis.referencing.AuthorityFactory;
027: import org.opengis.referencing.FactoryException;
028: import org.opengis.referencing.NoSuchAuthorityCodeException;
029: import org.opengis.referencing.crs.GeographicCRS;
030: import org.opengis.referencing.crs.CRSAuthorityFactory;
031:
032: // Geotools dependencies
033: import org.geotools.referencing.CRS;
034: import org.geotools.referencing.ReferencingFactoryFinder;
035: import org.geotools.referencing.crs.DefaultGeographicCRS;
036:
037: /**
038: * Tests the {@link HTTP_AuthorityFactory} class backed by WMS or AUTO factories.
039: *
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/factory/HTTP_AuthorityFactoryTest.java $
041: * @version $Id: HTTP_AuthorityFactoryTest.java 29058 2008-02-03 17:47:07Z desruisseaux $
042: * @author Martin Desruisseaux
043: */
044: public final class HTTP_AuthorityFactoryTest extends TestCase {
045: /**
046: * Run the suite from the command line.
047: */
048: public static void main(final String[] args) {
049: junit.textui.TestRunner.run(suite());
050: }
051:
052: /**
053: * Returns the test suite.
054: */
055: public static Test suite() {
056: return new TestSuite(HTTP_AuthorityFactoryTest.class);
057: }
058:
059: /**
060: * Creates a suite of the given name.
061: */
062: public HTTP_AuthorityFactoryTest(final String name) {
063: super (name);
064: }
065:
066: /**
067: * Tests the {@link HTTP_AuthorityFactory#defaultAxisOrderHints} method.
068: */
069: public void testAxisOrderHints() {
070: // The following are required for proper execution of the remaining of this test.
071: assertNull(Hints
072: .getSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER));
073: assertNull(Hints
074: .getSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING));
075:
076: // Standard behavior should be to set FORCE_LONGITUDE_FIRST_AXIS_ORDER to false.
077: assertFalse(HTTP_AuthorityFactory.defaultAxisOrderHints(null,
078: "http"));
079:
080: try {
081: // The hints should be ignored.
082: Hints.putSystemDefault(
083: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
084: Boolean.TRUE);
085: assertFalse(HTTP_AuthorityFactory.defaultAxisOrderHints(
086: null, "http"));
087:
088: // The hints should be honored.
089: Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING,
090: "http");
091: assertTrue(HTTP_AuthorityFactory.defaultAxisOrderHints(
092: null, "http"));
093:
094: // The hints should be ignored.
095: Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING,
096: "urn");
097: assertFalse(HTTP_AuthorityFactory.defaultAxisOrderHints(
098: null, "http"));
099:
100: // The hints should be honored.
101: Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING,
102: "http, urn");
103: assertTrue(HTTP_AuthorityFactory.defaultAxisOrderHints(
104: null, "http"));
105:
106: // The hints should be honored.
107: Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING,
108: "urn, http");
109: assertTrue(HTTP_AuthorityFactory.defaultAxisOrderHints(
110: null, "http"));
111: } finally {
112: Hints
113: .removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
114: Hints.removeSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING);
115: }
116: }
117:
118: /**
119: * Tests the CRS factory.
120: */
121: public void testCRS() throws FactoryException {
122: CRSAuthorityFactory factory = ReferencingFactoryFinder
123: .getCRSAuthorityFactory("http://www.opengis.net", null);
124: GeographicCRS crs;
125: try {
126: crs = factory.createGeographicCRS("CRS:84");
127: fail();
128: } catch (NoSuchAuthorityCodeException exception) {
129: // This is the expected exception.
130: assertEquals("CRS:84", exception.getAuthorityCode());
131: }
132: crs = factory
133: .createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#84");
134: assertSame(crs, CRS
135: .decode("http://www.opengis.net/gml/srs/crs.xml#84"));
136: assertSame(crs, CRS.decode("CRS:84"));
137: assertNotSame(crs, DefaultGeographicCRS.WGS84);
138: assertFalse(DefaultGeographicCRS.WGS84.equals(crs));
139: assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84,
140: crs));
141:
142: // Test CRS:83
143: crs = factory
144: .createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#83");
145: assertSame(crs, CRS.decode("CRS:83"));
146: assertFalse(CRS.equalsIgnoreMetadata(
147: DefaultGeographicCRS.WGS84, crs));
148: }
149: }
|