01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2007, GeoTools Project Managment Committee (PMC)
05: * (C) 2007, Geomatys
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation;
10: * version 2.1 of the License.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.image.io.metadata;
18:
19: // J2SE dependencies
20: import java.util.Arrays;
21: import java.util.Collection;
22: import javax.imageio.metadata.IIOMetadataFormat;
23:
24: // JUnit dependencies
25: import junit.framework.Test;
26: import junit.framework.TestCase;
27: import junit.framework.TestSuite;
28:
29: /**
30: * Tests {@link GeographicMetadata}.
31: *
32: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/test/java/org/geotools/image/io/metadata/GeographicMetadataTest.java $
33: * @version $Id: GeographicMetadataTest.java 26761 2007-08-29 21:25:45Z desruisseaux $
34: * @author Martin Desruisseaux
35: */
36: public class GeographicMetadataTest extends TestCase {
37: /**
38: * Run the suit from the command line.
39: */
40: public static void main(final String[] args) {
41: junit.textui.TestRunner.run(suite());
42: }
43:
44: /**
45: * Returns the test suite.
46: */
47: public static Test suite() {
48: return new TestSuite(GeographicMetadataTest.class);
49: }
50:
51: /**
52: * Constructs a test case with the given name.
53: */
54: public GeographicMetadataTest(final String name) {
55: super (name);
56: }
57:
58: /**
59: * Tests the geographic metadata format.
60: */
61: public void testFormat() {
62: if (true) {
63: return;
64: // TODO: this test doesn't seem to work with J2SE 1.4.
65: // Try again when we will be allowed to target J2SE 1.5.
66: }
67: final GeographicMetadata metadata = new GeographicMetadata();
68: final Collection formats = Arrays.asList(metadata
69: .getMetadataFormatNames());
70: assertTrue(formats
71: .contains(GeographicMetadataFormat.FORMAT_NAME));
72: final IIOMetadataFormat format = metadata
73: .getMetadataFormat(GeographicMetadataFormat.FORMAT_NAME);
74: assertTrue(format instanceof GeographicMetadataFormat);
75:
76: final Collection crsChilds = Arrays.asList(format
77: .getChildNames("CoordinateReferenceSystem"));
78: assertTrue(crsChilds.contains("CoordinateSystem"));
79: assertTrue(crsChilds.contains("Datum"));
80: assertEquals(IIOMetadataFormat.DATATYPE_STRING, format
81: .getAttributeDataType("Datum", "name"));
82: }
83:
84: /**
85: * Tests the setting of values in the metadata object.
86: */
87: public void testSetting() {
88: final GeographicMetadata metadata = new GeographicMetadata();
89: final ImageReferencing referencing = metadata.getReferencing();
90: referencing.addAxis("latitude", "north", "degrees");
91: referencing.addAxis("longitude", "east", "degrees");
92: referencing.setCoordinateSystem("WGS84", "geographic");
93: referencing.setDatum("WGS84");
94:
95: final String text = metadata.toString();
96: assertTrue(text.indexOf("name=\"latitude\"") >= 0);
97: assertTrue(text.indexOf("name=\"longitude\"") >= 0);
98: }
99: }
|