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; 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.metadata;
017:
018: import java.util.Collection;
019: import junit.framework.Test;
020: import junit.framework.TestCase;
021: import junit.framework.TestSuite;
022: import org.geotools.metadata.iso.citation.CitationImpl;
023: import org.geotools.metadata.iso.citation.Citations;
024: import org.geotools.metadata.iso.quality.PositionalAccuracyImpl;
025: import org.opengis.metadata.quality.ConformanceResult;
026:
027: /**
028: * Tests {@link Citations} and related constants.
029: *
030: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/metadata/CitationsTest.java $
031: * @version $Id: CitationsTest.java 25711 2007-06-01 11:07:57Z desruisseaux $
032: * @author Martin Desruisseaux
033: */
034: public class CitationsTest extends TestCase {
035: /**
036: * Run the suit 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(CitationsTest.class);
047: }
048:
049: /**
050: * Constructs a test case with the given name.
051: */
052: public CitationsTest(final String name) {
053: super (name);
054: }
055:
056: /**
057: * Tests the {@link AbstractMetadata#toString()} method first, since debugging
058: * will relying a lot on this method for the remaining of the test suite.
059: */
060: public void testToString() {
061: final String text = Citations.EPSG.toString();
062: /*
063: * Reminder: (?s) allows .* to skip new line characters.
064: * (?m) enable the multi-lines mode for ^ and $.
065: * ^ and $ match the begining and end of a line respectively.
066: */
067: assertTrue(text
068: .matches("(?s)(?m).*^\\s+Identifiers:\\s+EPSG$.*"));
069: assertTrue(text
070: .matches("(?s)(?m).*^\\s+Linkage:\\s+http://www.epsg.org$.*"));
071: }
072:
073: /**
074: * Makes sure that {@link Citations} constants are immutables.
075: */
076: public void testCitation() {
077: assertEquals("Identity comparaison", Citations.EPSG,
078: Citations.EPSG);
079: assertNotSame(Citations.EPSG, Citations.OGC);
080: assertTrue(Citations.EPSG instanceof CitationImpl);
081: try {
082: ((CitationImpl) Citations.EPSG).setISBN("Dummy");
083: fail("Pre-defined metadata should be unmodifiable.");
084: } catch (UnmodifiableMetadataException e) {
085: // This is the expected exception.
086: }
087: try {
088: Citations.EPSG.getIdentifiers().add("Dummy");
089: fail("Pre-defined metadata should be unmodifiable.");
090: } catch (UnsupportedOperationException e) {
091: // This is the expected exception.
092: }
093: }
094:
095: /**
096: * Tests {@link PositionalAccuracyImpl} constants.
097: */
098: public void testPositionalAccuracy() {
099: assertEquals("Identity comparaison",
100: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED,
101: PositionalAccuracyImpl.DATUM_SHIFT_APPLIED);
102:
103: assertEquals("Identity comparaison",
104: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED,
105: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED);
106:
107: assertNotSame(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED,
108: PositionalAccuracyImpl.DATUM_SHIFT_OMITTED);
109:
110: final Collection appliedResults = PositionalAccuracyImpl.DATUM_SHIFT_APPLIED
111: .getResults();
112: final Collection omittedResults = PositionalAccuracyImpl.DATUM_SHIFT_OMITTED
113: .getResults();
114: final ConformanceResult applied = (ConformanceResult) appliedResults
115: .iterator().next();
116: final ConformanceResult omitted = (ConformanceResult) omittedResults
117: .iterator().next();
118: assertNotSame(applied, omitted);
119: assertTrue(applied.pass());
120: assertFalse(omitted.pass());
121: assertFalse(applied.equals(omitted));
122: assertFalse(appliedResults.equals(omittedResults));
123: assertFalse(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED
124: .equals(PositionalAccuracyImpl.DATUM_SHIFT_OMITTED));
125: }
126: }
|