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: // JUnit dependencies
020: import junit.framework.Test;
021: import junit.framework.TestCase;
022: import junit.framework.TestSuite;
023:
024: // OpenGIS dependencies
025: import org.opengis.referencing.NoSuchAuthorityCodeException;
026:
027: /**
028: * Tests the {@link URN_Parser} class.
029: *
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/factory/URN_ParserTest.java $
031: * @version $Id: URN_ParserTest.java 24576 2007-02-24 00:07:40Z desruisseaux $
032: * @author Martin Desruisseaux
033: */
034: public final class URN_ParserTest extends TestCase {
035: /**
036: * Run the suite from the command line.
037: */
038: public static void main(final String[] args) {
039: junit.textui.TestRunner.run(suite());
040: }
041:
042: /**
043: * Returns the test suite.
044: */
045: public static Test suite() {
046: return new TestSuite(URN_ParserTest.class);
047: }
048:
049: /**
050: * Creates a suite of the given name.
051: */
052: public URN_ParserTest(final String name) {
053: super (name);
054: }
055:
056: /**
057: * Tests the main types.
058: */
059: public void testMainTypes() {
060: assertEquals("crs", URN_Type.MAIN[0].name);
061: assertEquals("datum", URN_Type.MAIN[1].name);
062: assertEquals("cs", URN_Type.MAIN[2].name);
063: assertEquals("coordinateOperation", URN_Type.MAIN[3].name);
064: }
065:
066: /**
067: * Parses a valid URN.
068: */
069: public void testParse() throws NoSuchAuthorityCodeException {
070: final URN_Parser parser = new URN_Parser(
071: "urn:ogc:def:CRS:EPSG:6.11.2:4326");
072: assertEquals("crs", parser.type.name);
073: assertEquals("EPSG", parser.authority);
074: assertEquals("6.11.2", parser.version.toString());
075: assertEquals("4326", parser.code);
076: assertEquals("EPSG:4326", parser.getAuthorityCode());
077: }
078:
079: /**
080: * Parses a valid URN without version.
081: */
082: public void testParseWithoutVersion()
083: throws NoSuchAuthorityCodeException {
084: final URN_Parser parser = new URN_Parser(
085: "urn:ogc:def:CRS:EPSG:4326");
086: assertEquals("crs", parser.type.name);
087: assertEquals("EPSG", parser.authority);
088: assertNull(parser.version);
089: assertEquals("4326", parser.code);
090: assertEquals("EPSG:4326", parser.getAuthorityCode());
091: }
092:
093: /**
094: * Parses an invalid URN.
095: */
096: public void testInvalidParse() {
097: final String urn = "urn:ogcx:def:CRS:EPSG:6.8:4326";
098: try {
099: new URN_Parser(urn);
100: fail();
101: } catch (NoSuchAuthorityCodeException e) {
102: // This is the expected exception.
103: assertEquals(urn, e.getAuthorityCode());
104: }
105: }
106:
107: /**
108: * Parses a URN with an unknow type.
109: */
110: public void testInvalidType() {
111: final String urn = "urn:ogc:def:dummy:EPSG:6.8:4326";
112: try {
113: new URN_Parser(urn);
114: fail();
115: } catch (NoSuchAuthorityCodeException e) {
116: // This is the expected exception.
117: assertEquals("dummy", e.getAuthorityCode());
118: }
119: }
120: }
|