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.io.File;
020: import java.util.Collection;
021:
022: // JUnit dependencies
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: // OpenGIS dependencies
028: import org.opengis.metadata.citation.Citation;
029: import org.opengis.referencing.FactoryException;
030: import org.opengis.referencing.crs.CoordinateReferenceSystem;
031: import org.opengis.referencing.crs.ProjectedCRS;
032:
033: // Geotools dependencies
034: import org.geotools.factory.Hints;
035: import org.geotools.metadata.iso.citation.Citations;
036: import org.geotools.referencing.CRS;
037: import org.geotools.referencing.ReferencingFactoryFinder;
038: import org.geotools.referencing.NamedIdentifier;
039:
040: /**
041: * Tests {@link FactoryUsingWKT}.
042: *
043: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/factory/epsg/FactoryUsingWktTest.java $
044: * @version $Id: FactoryUsingWktTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
045: * @author Martin Desruisseaux
046: * @author Jody Garnett
047: */
048: public class FactoryUsingWktTest extends TestCase {
049: /**
050: * The factory to test.
051: */
052: private FactoryUsingWKT factory;
053:
054: /**
055: * Returns the test suite.
056: */
057: public static Test suite() {
058: return new TestSuite(FactoryUsingWktTest.class);
059: }
060:
061: /**
062: * Run the test from the command line.
063: *
064: * @param args the command line arguments.
065: */
066: public static void main(final String[] args) {
067: org.geotools.util.logging.Logging.GEOTOOLS
068: .forceMonolineConsoleOutput();
069: junit.textui.TestRunner.run(suite());
070: }
071:
072: /**
073: * Creates a test case with the specified name.
074: */
075: public FactoryUsingWktTest(final String name) {
076: super (name);
077: }
078:
079: /**
080: * Gets the authority factory for ESRI.
081: */
082: protected void setUp() throws Exception {
083: super .setUp();
084: factory = (FactoryUsingWKT) ReferencingFactoryFinder
085: .getCRSAuthorityFactory("EPSG", new Hints(
086: Hints.CRS_AUTHORITY_FACTORY,
087: FactoryUsingWKT.class));
088: }
089:
090: /**
091: * Tests the setting of "CRS authority extra directory" hint.
092: */
093: public void testCrsAuthorityExtraDirectoryHint() throws Exception {
094: Hints hints = new Hints(Hints.CRS_AUTHORITY_FACTORY,
095: FactoryUsingWKT.class);
096: try {
097: hints.put(Hints.CRS_AUTHORITY_EXTRA_DIRECTORY, "invalid");
098: fail("Should of been tossed out as an invalid hint");
099: } catch (IllegalArgumentException expected) {
100: // This is the expected exception.
101: }
102: String directory = new File(".").getAbsolutePath();
103: hints = new Hints(Hints.CRS_AUTHORITY_FACTORY,
104: FactoryUsingWKT.class);
105: hints.put(Hints.CRS_AUTHORITY_EXTRA_DIRECTORY, directory);
106: // TODO: test the factory here.
107: }
108:
109: /**
110: * Tests the authority code.
111: */
112: public void testAuthority() {
113: final Citation authority = factory.getAuthority();
114: assertNotNull(authority);
115: assertEquals("European Petroleum Survey Group", authority
116: .getTitle().toString());
117: assertTrue(authority.getIdentifiers().contains("EPSG"));
118: assertFalse(authority.getIdentifiers().contains("ESRI"));
119: assertTrue(factory instanceof FactoryUsingWKT);
120: }
121:
122: /**
123: * Tests the vendor.
124: */
125: public void testVendor() {
126: final Citation vendor = factory.getVendor();
127: assertNotNull(vendor);
128: assertEquals("Geotools", vendor.getTitle().toString());
129: }
130:
131: /**
132: * Tests the {@code 18001} code.
133: */
134: public void test42101() throws FactoryException {
135: CoordinateReferenceSystem actual, expected;
136: expected = factory.createCoordinateReferenceSystem("42101");
137: actual = CRS.decode("EPSG:42101");
138: assertSame(expected, actual);
139: assertTrue(actual instanceof ProjectedCRS);
140: Collection ids = actual.getIdentifiers();
141: assertTrue(ids.contains(new NamedIdentifier(Citations.EPSG,
142: "42101")));
143: assertFalse(ids.contains(new NamedIdentifier(Citations.ESRI,
144: "42101")));
145: }
146: }
|