Source Code Cross Referenced for MetadataBuilderTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » coverage » io » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » GIS » GeoTools 2.4.1 » org.geotools.coverage.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2005-2006, Geotools Project Managment Committee (PMC)
005:         *    (C) 2002, 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.coverage.io;
018:
019:        // J2SE dependencies
020:        import java.io.IOException;
021:        import java.io.PrintWriter;
022:        import java.io.StringWriter;
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.coverage.grid.GridRange;
031:        import org.opengis.coverage.grid.GridCoverage;
032:        import org.opengis.referencing.crs.GeographicCRS;
033:        import org.opengis.referencing.crs.CoordinateReferenceSystem;
034:
035:        // Geotools dependencies
036:        import org.geotools.referencing.CRS;
037:        import org.geotools.resources.Arguments;
038:
039:        /**
040:         * Tests the {@link MetadataBuilder} implementation.
041:         *
042:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/coverageio/src/test/java/org/geotools/coverage/io/MetadataBuilderTest.java $
043:         * @version $Id: MetadataBuilderTest.java 27848 2007-11-12 13:10:32Z desruisseaux $
044:         * @author Martin Desruisseaux
045:         */
046:        public class MetadataBuilderTest extends TestCase {
047:            /**
048:             * Set to a non-null value for printing some diagnostic message to the standard output.
049:             */
050:            private static PrintWriter out;
051:
052:            /**
053:             * Run the suit from the command line. Run the test with the
054:             * "-print" option in order to print test to standard output.
055:             */
056:            public static void main(final String[] args) {
057:                final Arguments arguments = new Arguments(args);
058:                if (arguments.getFlag("-print")) {
059:                    out = arguments.out;
060:                } else {
061:                    out = new PrintWriter(new StringWriter());
062:                }
063:                arguments.getRemainingArguments(0);
064:                org.geotools.util.logging.Logging.GEOTOOLS
065:                        .forceMonolineConsoleOutput();
066:                junit.textui.TestRunner.run(suite());
067:            }
068:
069:            /**
070:             * Returns the test suite.
071:             */
072:            public static Test suite() {
073:                return new TestSuite(MetadataBuilderTest.class);
074:            }
075:
076:            /**
077:             * Constructs a test case with the given name.
078:             */
079:            public MetadataBuilderTest(final String name) {
080:                super (name);
081:            }
082:
083:            /**
084:             * Tests the addition of alias.
085:             */
086:            public void testAlias() throws IOException {
087:                final MetadataBuilder parser = new MetadataBuilder();
088:                /*
089:                 * Tests "add" operations.
090:                 */
091:                parser.add("Alias 1", "Value 1");
092:                parser.add("Alias 2", "Value 2");
093:                try {
094:                    parser.add("  alias  1", "Value X");
095:                    fail(); // We should not get there.
096:                } catch (AmbiguousMetadataException exception) {
097:                    // This is the expected exception.
098:                    if (out != null) {
099:                        out.println(exception);
100:                    }
101:                }
102:                parser.add("Alias 1", "Value 1"); // Already defined
103:                parser.add("Alias 3", "Value 3");
104:                /*
105:                 * Tests "addAlias" operations.
106:                 */
107:                parser.addAlias(MetadataBuilder.X_RESOLUTION, "Alias 1");
108:                parser.addAlias(MetadataBuilder.Y_RESOLUTION, "Alias 2");
109:                parser.addAlias(MetadataBuilder.Y_RESOLUTION, "Alias 2bis");
110:                parser.addAlias(MetadataBuilder.X_RESOLUTION, "Alias 1bis");
111:                parser.addAlias(MetadataBuilder.X_RESOLUTION, "Alias 1"); // Already defined
112:                try {
113:                    parser.addAlias(MetadataBuilder.X_RESOLUTION, "Alias 2");
114:                    fail(); // We should not get there.
115:                } catch (AmbiguousMetadataException exception) {
116:                    // This is the expected exception.
117:                    if (out != null) {
118:                        out.println(exception);
119:                    }
120:                }
121:                parser.add("Alias 2bis", "Value 2");
122:                try {
123:                    parser.add("Alias 1bis", "Value 2");
124:                    fail(); // We should not get there.
125:                } catch (AmbiguousMetadataException exception) {
126:                    // This is the expected exception.
127:                    if (out != null) {
128:                        out.println(exception);
129:                    }
130:                }
131:                /*
132:                 * Tests "get" operations.
133:                 */
134:                assertEquals("Value 1", parser
135:                        .get(MetadataBuilder.X_RESOLUTION));
136:                assertEquals("Value 2", parser
137:                        .get(MetadataBuilder.Y_RESOLUTION));
138:                try {
139:                    parser.get(MetadataBuilder.DATUM);
140:                    fail(); // We should not get there.
141:                } catch (MissingMetadataException exception) {
142:                    // This is the expected exception.
143:                    if (out != null) {
144:                        out.println(exception);
145:                    }
146:                }
147:                /*
148:                 * Tests "getAsDouble" and "getAsInt" operations.
149:                 */
150:                parser.add("ULX", "40");
151:                parser.add("ULY", "12.5");
152:                parser.addAlias(MetadataBuilder.X_MINIMUM, "ULX");
153:                parser.addAlias(MetadataBuilder.Y_MAXIMUM, "ULY");
154:                assertEquals(40, parser.getAsDouble(MetadataBuilder.X_MINIMUM),
155:                        0);
156:                assertEquals(12.5, parser
157:                        .getAsDouble(MetadataBuilder.Y_MAXIMUM), 0);
158:                assertEquals(40, parser.getAsInt(MetadataBuilder.X_MINIMUM));
159:                try {
160:                    parser.getAsInt(MetadataBuilder.Y_MAXIMUM);
161:                    fail(); // We should not get there.
162:                } catch (MetadataException exception) {
163:                    // This is the expected exception.
164:                    if (out != null) {
165:                        out.println(exception);
166:                    }
167:                }
168:                if (out != null) {
169:                    out.println();
170:                    parser.listMetadata(out);
171:                    out.flush();
172:                }
173:            }
174:
175:            /**
176:             * Tests the formatting.
177:             */
178:            public void testFormat() throws IOException {
179:                final MetadataBuilder parser = new MetadataBuilder();
180:                /*
181:                 * Do not add a COORDINATE_REFERENCE_SYSTEM property, because we want
182:                 * to test the MetadataBuilder capability to create it from scratch.
183:                 */
184:                parser.addAlias(MetadataBuilder.PROJECTION, "Projection");
185:                parser.addAlias(MetadataBuilder.DATUM, "Datum");
186:                parser.addAlias(MetadataBuilder.UNITS, "Units");
187:                parser.addAlias(MetadataBuilder.X_MINIMUM, "Upper left X");
188:                parser.addAlias(MetadataBuilder.Y_MAXIMUM, "Upper left Y");
189:                parser.addAlias(MetadataBuilder.X_RESOLUTION, "Resolution X");
190:                parser.addAlias(MetadataBuilder.Y_RESOLUTION, "Resolution Y");
191:                parser.addAlias(MetadataBuilder.WIDTH, "Width");
192:                parser.addAlias(MetadataBuilder.HEIGHT, "Height");
193:
194:                final GridCoverage coverage = GridCoverageExamples
195:                        .getExample(0);
196:                parser.add(coverage);
197:                if (out != null) {
198:                    out.println(parser);
199:                    out.flush();
200:                }
201:                assertEquals(35.0, parser
202:                        .getAsDouble(MetadataBuilder.X_MINIMUM), 1E-8);
203:                assertEquals(5.0,
204:                        parser.getAsDouble(MetadataBuilder.Y_MAXIMUM), 1E-8);
205:                assertEquals(0.1, parser
206:                        .getAsDouble(MetadataBuilder.X_RESOLUTION), 1E-8);
207:                assertEquals(0.1, parser
208:                        .getAsDouble(MetadataBuilder.Y_RESOLUTION), 1E-8);
209:                assertEquals(450, parser.getAsInt(MetadataBuilder.WIDTH));
210:                assertEquals(460, parser.getAsInt(MetadataBuilder.HEIGHT));
211:
212:                final GridRange range = parser.getGridRange();
213:                assertEquals("Width", 450, range.getLength(0));
214:                assertEquals("Height", 460, range.getLength(1));
215:
216:                final CoordinateReferenceSystem expectedCRS = coverage
217:                        .getCoordinateReferenceSystem();
218:                final CoordinateReferenceSystem createdCRS = parser
219:                        .getCoordinateReferenceSystem();
220:                assertTrue("The test data changed!",
221:                        expectedCRS instanceof  GeographicCRS);
222:                assertTrue("Created wrong CRS type.",
223:                        createdCRS instanceof  GeographicCRS);
224:                assertNotSame("Not testing creation.", expectedCRS, createdCRS);
225:                assertTrue("Created incompatible CRS.", CRS
226:                        .equalsIgnoreMetadata(expectedCRS, createdCRS));
227:
228:                parser.addAlias(MetadataBuilder.COORDINATE_REFERENCE_SYSTEM,
229:                        "CRS");
230:                parser.add(coverage);
231:                assertSame("Should not create CRS anymore.", expectedCRS,
232:                        parser.getCoordinateReferenceSystem());
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.