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.factory;
017:
018: import java.util.Collections;
019: import java.util.HashMap;
020: import java.util.Map;
021: import junit.framework.Test;
022: import junit.framework.TestCase;
023: import junit.framework.TestSuite;
024:
025: /**
026: * Tests {@link GeoTools}.
027: *
028: * @since 2.4
029: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/factory/GeoToolsTest.java $
030: * @version $Id: GeoToolsTest.java 25406 2007-05-03 18:08:10Z desruisseaux $
031: * @author Jody Garnett
032: * @author Martin Desruisseaux
033: */
034: public class GeoToolsTest extends TestCase {
035: /**
036: * Run the suite from the command line.
037: */
038: public static void main(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(GeoToolsTest.class);
047: }
048:
049: /**
050: * Constructs a test case.
051: */
052: public GeoToolsTest(final String testName) {
053: super (testName);
054: }
055:
056: /**
057: * Make sures that J2SE 1.4 assertions are enabled.
058: */
059: public void testAssertionEnabled() {
060: assertTrue("Assertions not enabled.", GeoToolsTest.class
061: .desiredAssertionStatus());
062: }
063:
064: /**
065: * Tests the removal of keys from a hashmap. Required for {@link FactoryRegistry} working.
066: */
067: public void testHintsKey() {
068: final Hints hints = new Hints(
069: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
070: assertFalse(hints.isEmpty());
071:
072: Map map = new HashMap();
073: assertNull(map.put(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
074: Boolean.FALSE));
075: map = Collections.unmodifiableMap(map);
076: assertFalse(map.isEmpty());
077:
078: final Hints remaining = new Hints(hints);
079: assertTrue(remaining.keySet().removeAll(map.keySet()));
080: assertTrue(remaining.isEmpty());
081: }
082:
083: /**
084: * Tests addition of custom hints.
085: */
086: public void testMyHints() {
087: Hints hints = GeoTools.getDefaultHints();
088: assertTrue(hints.isEmpty());
089: assertNull(Hints.putSystemDefault(
090: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.FALSE));
091: try {
092: hints = GeoTools.getDefaultHints();
093: assertNotNull(hints);
094: assertFalse(hints.isEmpty());
095: assertEquals(1, hints.size());
096: final Object value = hints
097: .get(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
098: assertTrue(value instanceof Boolean);
099: assertFalse(((Boolean) value).booleanValue());
100: /*
101: * Tests the toString() method.
102: */
103: String text = hints.toString().trim();
104: assertTrue(text
105: .matches("Hints:\\s+FORCE_LONGITUDE_FIRST_AXIS_ORDER = false"));
106:
107: assertEquals(hints.put(
108: Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER,
109: Boolean.TRUE), Boolean.FALSE);
110: text = hints.toString().trim();
111: assertTrue(text
112: .matches("Hints:\\s+FORCE_LONGITUDE_FIRST_AXIS_ORDER = true"));
113:
114: assertEquals(hints
115: .remove(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER),
116: Boolean.TRUE);
117: text = hints.toString().trim();
118: assertTrue(text
119: .matches("Hints:\\s+System defaults:\\s+FORCE_LONGITUDE_FIRST_AXIS_ORDER = false"));
120: } finally {
121: assertNotNull(Hints
122: .removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER));
123: }
124: assertTrue(GeoTools.getDefaultHints().isEmpty());
125: }
126:
127: /**
128: * Tests the use of system properties.
129: *
130: * @todo Uncomment when we will be allowed to compile for J2SE 1.5.
131: * Call to {@link System#clearProperty} is mandatory for this test.
132: */
133: public void testSystemHints() {
134: Hints hints = GeoTools.getDefaultHints();
135: assertNotNull(hints);
136: assertTrue(hints.isEmpty());
137: // System.setProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER, "true");
138: // Hints.scanSystemProperties();
139: // try {
140: // hints = GeoTools.getDefaultHints();
141: // assertNotNull(hints);
142: // assertFalse(hints.isEmpty());
143: // assertEquals(1, hints.size());
144: // final Object value = hints.get(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
145: // assertTrue(value instanceof Boolean);
146: // assertTrue(((Boolean) value).booleanValue());
147: // } finally {
148: // System.clearProperty(GeoTools.FORCE_LONGITUDE_FIRST_AXIS_ORDER);
149: // assertNotNull(Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER));
150: // }
151: hints = GeoTools.getDefaultHints();
152: assertNotNull(hints);
153: assertTrue(hints.isEmpty());
154: }
155: }
|