001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2004-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2004, Institut de Recherche pour le Développement
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; either
010: * version 2.1 of the License, or (at your option) any later version.
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;
018:
019: // J2SE dependencies
020: import java.util.HashMap;
021: import java.util.Locale;
022: import java.util.Map;
023:
024: // JUnit dependencies
025: import junit.framework.Test;
026: import junit.framework.TestCase;
027: import junit.framework.TestSuite;
028:
029: // OpenGIS dependencies
030: import org.opengis.parameter.InvalidParameterValueException;
031: import org.opengis.util.InternationalString;
032:
033: // Geotools dependencies
034: import org.geotools.metadata.iso.citation.CitationImpl;
035: import org.geotools.util.SimpleInternationalString;
036:
037: /**
038: * Tests the creation of {@link AbstractIdentifiedObject} and a few subclasses.
039: *
040: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/test/java/org/geotools/referencing/IdentifiedObjectTest.java $
041: * @version $Id: IdentifiedObjectTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
042: * @author Martin Desruisseaux
043: */
044: public final class IdentifiedObjectTest extends TestCase {
045: /**
046: * Run the suite from the command line.
047: */
048: public static void main(String[] args) {
049: org.geotools.util.logging.Logging.GEOTOOLS
050: .forceMonolineConsoleOutput();
051: junit.textui.TestRunner.run(suite());
052: }
053:
054: /**
055: * Returns the test suite.
056: */
057: public static Test suite() {
058: return new TestSuite(IdentifiedObjectTest.class);
059: }
060:
061: /**
062: * Construct a test case.
063: */
064: public IdentifiedObjectTest(String testName) {
065: super (testName);
066: }
067:
068: /**
069: * Tests {@link NamedIdentifier} attributes. Useful for making sure that the
070: * hash code enumerated in the switch statement in the constructor have
071: * the correct value.
072: */
073: public void testIdentifier() {
074: final Map properties = new HashMap();
075: assertNull(properties.put("code", "This is a code"));
076: assertNull(properties.put("authority", "This is an authority"));
077: assertNull(properties.put("version", "This is a version"));
078: assertNull(properties.put("dummy", "Doesn't matter"));
079: assertNull(properties.put("remarks", "There is remarks"));
080: assertNull(properties.put("remarks_fr", "Voici des remarques"));
081: assertNull(properties.put("remarks_fr_CA", "Pareil"));
082:
083: NamedIdentifier identifier = new NamedIdentifier(properties);
084: assertEquals("code", "This is a code", identifier.getCode());
085: assertEquals("authority", "This is an authority", identifier
086: .getAuthority().getTitle().toString());
087: assertEquals("version", "This is a version", identifier
088: .getVersion());
089: assertEquals("remarks", "There is remarks", identifier
090: .getRemarks().toString(Locale.ENGLISH));
091: assertEquals("remarks_fr", "Voici des remarques", identifier
092: .getRemarks().toString(Locale.FRENCH));
093: assertEquals("remarks_fr_CA", "Pareil", identifier.getRemarks()
094: .toString(Locale.CANADA_FRENCH));
095: assertEquals("remarks_fr_BE", "Voici des remarques", identifier
096: .getRemarks().toString(new Locale("fr", "BE")));
097:
098: if (false) {
099: // Disabled in order to avoid logging a warning (it disturb the JUnit output)
100: properties.put("remarks", new SimpleInternationalString(
101: "Overrides remarks"));
102: identifier = new NamedIdentifier(properties);
103: assertEquals("remarks", "Overrides remarks", identifier
104: .getRemarks().toString(Locale.ENGLISH));
105: }
106:
107: assertNotNull(properties.remove("authority"));
108: assertNull(properties.put("AutHOrITY", new CitationImpl(
109: "An other authority")));
110: identifier = new NamedIdentifier(properties);
111: assertEquals("authority", "An other authority", identifier
112: .getAuthority().getTitle().toString(Locale.ENGLISH));
113:
114: assertNotNull(properties.remove("AutHOrITY"));
115: assertNull(properties.put("authority", Locale.CANADA));
116: try {
117: identifier = new NamedIdentifier(properties);
118: fail();
119: } catch (InvalidParameterValueException exception) {
120: // This is the expected exception
121: }
122: }
123:
124: /**
125: * Test {@link IdentifiedObject}.
126: */
127: public void testIdentifiedObject() {
128: final Map properties = new HashMap();
129: assertNull(properties.put("name", "This is a name"));
130: assertNull(properties.put("remarks", "There is remarks"));
131: assertNull(properties.put("remarks_fr", "Voici des remarques"));
132: assertNull(properties.put("dummy", "Doesn't matter"));
133: assertNull(properties.put("dummy_fr", "Rien d'intéressant"));
134: assertNull(properties.put("local", "A custom localized string"));
135: assertNull(properties
136: .put("local_fr", "Une chaîne personalisée"));
137: assertNull(properties.put("anchorPoint", "Anchor point"));
138: assertNull(properties.put("realizationEpoch",
139: "Realization epoch"));
140: assertNull(properties.put("validArea", "Valid area"));
141:
142: final Map remaining = new HashMap();
143: final AbstractIdentifiedObject reference = new AbstractIdentifiedObject(
144: properties, remaining, new String[] { "local" });
145: assertEquals("name", "This is a name", reference.getName()
146: .getCode());
147: assertEquals("remarks", "There is remarks", reference
148: .getRemarks().toString(null));
149: assertEquals("remarks_fr", "Voici des remarques", reference
150: .getRemarks().toString(Locale.FRENCH));
151:
152: // Check extra properties
153: assertEquals("Size:", 6, remaining.size());
154: assertEquals("dummy", "Doesn't matter", remaining.get("dummy"));
155: assertEquals("dummy_fr", "Rien d'intéressant", remaining
156: .get("dummy_fr"));
157: assertEquals("local", "A custom localized string",
158: ((InternationalString) remaining.get("local"))
159: .toString(null));
160: assertEquals("local_fr", "Une chaîne personalisée",
161: ((InternationalString) remaining.get("local"))
162: .toString(Locale.FRENCH));
163: assertFalse("local_fr", remaining.containsKey("local_fr"));
164:
165: // Check the case of some special property keys
166: assertEquals("anchorPoint", "Anchor point", remaining
167: .get("anchorPoint"));
168: assertEquals("realizationEpoch", "Realization epoch", remaining
169: .get("realizationEpoch"));
170: assertEquals("validArea", "Valid area", remaining
171: .get("validArea"));
172: }
173:
174: /**
175: * Test {@link AbstractReferenceSystem}.
176: */
177: public void testReferenceSystem() {
178: final Map properties = new HashMap();
179: assertNull(properties.put("name", "This is a name"));
180: assertNull(properties.put("scope", "This is a scope"));
181: assertNull(properties.put("scope_fr", "Valide dans ce domaine"));
182: assertNull(properties.put("remarks", "There is remarks"));
183: assertNull(properties.put("remarks_fr", "Voici des remarques"));
184:
185: final AbstractReferenceSystem reference = new AbstractReferenceSystem(
186: properties);
187: assertEquals("name", "This is a name", reference.getName()
188: .getCode());
189: assertEquals("scope", "This is a scope", reference.getScope()
190: .toString(null));
191: assertEquals("scope_fr", "Valide dans ce domaine", reference
192: .getScope().toString(Locale.FRENCH));
193: assertEquals("remarks", "There is remarks", reference
194: .getRemarks().toString(null));
195: assertEquals("remarks_fr", "Voici des remarques", reference
196: .getRemarks().toString(Locale.FRENCH));
197: }
198: }
|