001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-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; either
009: * version 2.1 of the License, or (at your option) any later version.
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.wms;
017:
018: // J2SE dependencies
019: import java.util.Collection;
020: import java.util.logging.Level;
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.referencing.FactoryException;
029: import org.opengis.referencing.crs.ProjectedCRS;
030: import org.opengis.referencing.crs.CRSAuthorityFactory;
031:
032: // Geotools dependencies
033: import org.geotools.resources.Arguments;
034: import org.geotools.referencing.ReferencingFactoryFinder;
035:
036: /**
037: * Tests {@link AutoCRSFactory}.
038: *
039: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/factory/wms/AUTOTest.java $
040: * @version $Id: AUTOTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
041: * @author Jody Garnett
042: * @author Martin Desruisseaux
043: */
044: public final class AUTOTest extends TestCase {
045: /**
046: * The factory to test.
047: */
048: private CRSAuthorityFactory factory;
049:
050: /**
051: * Run the suite from the command line.
052: */
053: public static void main(final String[] args) {
054: final Arguments arguments = new Arguments(args);
055: final boolean log = arguments.getFlag("-log");
056: arguments.getRemainingArguments(0);
057: org.geotools.util.logging.Logging.GEOTOOLS
058: .forceMonolineConsoleOutput(log ? Level.CONFIG : null);
059: junit.textui.TestRunner.run(suite());
060: }
061:
062: /**
063: * Returns the test suite.
064: */
065: public static Test suite() {
066: return new TestSuite(AUTOTest.class);
067: }
068:
069: /**
070: * Creates a suite of the given name.
071: */
072: public AUTOTest(final String name) {
073: super (name);
074: }
075:
076: /**
077: * Initializes the factory to test.
078: */
079: protected void setUp() throws Exception {
080: super .setUp();
081: factory = new AutoCRSFactory();
082: }
083:
084: /**
085: * Tests the registration in {@link ReferencingFactoryFinder}.
086: */
087: public void testFactoryFinder() {
088: final Collection authorities = ReferencingFactoryFinder
089: .getAuthorityNames();
090: assertTrue(authorities.contains("AUTO"));
091: assertTrue(authorities.contains("AUTO2"));
092: factory = ReferencingFactoryFinder.getCRSAuthorityFactory(
093: "AUTO", null);
094: assertTrue(factory instanceof AutoCRSFactory);
095: assertSame(factory, ReferencingFactoryFinder
096: .getCRSAuthorityFactory("AUTO2", null));
097: }
098:
099: /**
100: * Checks the authority names.
101: */
102: public void testAuthority() {
103: final Collection identifiers = factory.getAuthority()
104: .getIdentifiers();
105: assertTrue(identifiers.contains("AUTO"));
106: assertTrue(identifiers.contains("AUTO2"));
107: assertFalse(identifiers.contains("EPSG"));
108: assertFalse(identifiers.contains("CRS"));
109: }
110:
111: /**
112: * UDIG requires this to work.
113: */
114: public void test42001() throws FactoryException {
115: final ProjectedCRS utm = factory
116: .createProjectedCRS("AUTO:42001,0.0,0.0");
117: assertNotNull("auto-utm", utm);
118: assertSame(utm, factory.createObject("AUTO :42001, 0,0"));
119: assertSame(utm, factory.createObject("AUTO2:42001, 0,0"));
120: assertSame(utm, factory.createObject("42001, 0,0"));
121: assertNotSame(utm, factory.createObject("AUTO :42001,30,0"));
122: assertEquals("Transverse_Mercator", utm.getConversionFromBase()
123: .getMethod().getName().getCode());
124: }
125: }
|