Source Code Cross Referenced for PropertyAccessorTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » metadata » 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.metadata 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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 java.util.HashSet;
020:        import java.util.Set;
021:        import junit.framework.Test;
022:        import junit.framework.TestCase;
023:        import junit.framework.TestSuite;
024:        import org.geotools.util.SimpleInternationalString;
025:        import org.opengis.metadata.citation.Citation;
026:        import org.geotools.metadata.iso.citation.CitationImpl;
027:        import org.geotools.metadata.iso.citation.Citations;
028:        import org.opengis.util.InternationalString;
029:
030:        /**
031:         * Tests the {@link PropertyAccessor} class.
032:         *
033:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/metadata/src/test/java/org/geotools/metadata/PropertyAccessorTest.java $
034:         * @version $Id: PropertyAccessorTest.java 25193 2007-04-18 13:37:38Z desruisseaux $
035:         * @author Martin Desruisseaux
036:         */
037:        public class PropertyAccessorTest extends TestCase {
038:            /**
039:             * Run the suit from the command line.
040:             */
041:            public static void main(final String[] args) {
042:                junit.textui.TestRunner.run(suite());
043:            }
044:
045:            /**
046:             * Returns the test suite.
047:             */
048:            public static Test suite() {
049:                return new TestSuite(PropertyAccessorTest.class);
050:            }
051:
052:            /**
053:             * Constructs a test case with the given name.
054:             */
055:            public PropertyAccessorTest(final String name) {
056:                super (name);
057:            }
058:
059:            /**
060:             * Creates a property accessor for the given citation.
061:             */
062:            private static PropertyAccessor createPropertyAccessor(
063:                    final Citation citation) {
064:                final Class implementation = citation.getClass();
065:                final Class type = PropertyAccessor.getType(implementation,
066:                        "org.opengis.metadata");
067:                assertNotNull(type);
068:                return new PropertyAccessor(implementation, type);
069:            }
070:
071:            /**
072:             * Tests the constructor.
073:             */
074:            public void testConstructor() {
075:                final Citation citation = Citations.EPSG;
076:                PropertyAccessor accessor;
077:                assertNull("No dummy interface expected.", PropertyAccessor
078:                        .getType(citation.getClass(), "org.opengis.dummy"));
079:                accessor = createPropertyAccessor(citation);
080:                assertEquals("Count of 'get' methods.", 14, accessor.count());
081:            }
082:
083:            /**
084:             * Tests the {@code indexOf} and {code name} methods.
085:             */
086:            public void testName() {
087:                final Citation citation = Citations.EPSG;
088:                final PropertyAccessor accessor = createPropertyAccessor(citation);
089:                assertEquals("Non-existent property", -1, accessor
090:                        .indexOf("dummy"));
091:                assertEquals("getTitle() property", "title", accessor
092:                        .name(accessor.indexOf("title")));
093:                assertEquals("getTitle() property", "title", accessor
094:                        .name(accessor.indexOf("TITLE")));
095:                assertEquals("getISBN() property", "ISBN", accessor
096:                        .name(accessor.indexOf("ISBN")));
097:                assertNull(accessor.name(-1));
098:            }
099:
100:            /**
101:             * Tests the get method.
102:             */
103:            public void testGet() {
104:                Citation citation = Citations.EPSG;
105:                final PropertyAccessor accessor = createPropertyAccessor(citation);
106:                final int index = accessor.indexOf("identifiers");
107:                assertTrue(String.valueOf(index), index >= 0);
108:                final Object identifiers = accessor.get(index, citation);
109:                assertNotNull(identifiers);
110:                assertTrue(identifiers instanceof  Collection);
111:                assertTrue(((Collection) identifiers).contains("EPSG"));
112:            }
113:
114:            /**
115:             * Tests the shallow equals and copy methods.
116:             */
117:            public void testEquals() {
118:                Citation citation = Citations.EPSG;
119:                final PropertyAccessor accessor = createPropertyAccessor(citation);
120:                assertFalse(accessor.shallowEquals(citation, Citations.GEOTIFF,
121:                        true));
122:                assertFalse(accessor.shallowEquals(citation, Citations.GEOTIFF,
123:                        false));
124:                assertTrue(accessor.shallowEquals(citation, Citations.EPSG,
125:                        false));
126:
127:                citation = new CitationImpl();
128:                assertTrue(accessor.shallowCopy(Citations.EPSG, citation, true));
129:                assertFalse(accessor.shallowEquals(citation, Citations.GEOTIFF,
130:                        true));
131:                assertFalse(accessor.shallowEquals(citation, Citations.GEOTIFF,
132:                        false));
133:                assertTrue(accessor.shallowEquals(citation, Citations.EPSG,
134:                        false));
135:
136:                final int index = accessor.indexOf("identifiers");
137:                final Object source = accessor.get(index, Citations.EPSG);
138:                final Object target = accessor.get(index, citation);
139:                assertNotNull(source);
140:                assertNotNull(target);
141:                assertNotSame(source, target);
142:                assertEquals(source, target);
143:                assertTrue(((Collection) target).contains("EPSG"));
144:
145:                assertSame(target, accessor.set(index, citation, null));
146:                final Object value = accessor.get(index, citation);
147:                assertNotNull(value);
148:                assertTrue(((Collection) value).isEmpty());
149:
150:                try {
151:                    accessor.shallowCopy(citation, Citations.EPSG, true);
152:                    fail("Citations.EPSG should be unmodifiable.");
153:                } catch (UnmodifiableMetadataException e) {
154:                    // This is the expected exception.
155:                }
156:            }
157:
158:            /**
159:             * Tests the hash code computation.
160:             */
161:            public void testHashCode() {
162:                final CitationImpl citation = new CitationImpl();
163:                final PropertyAccessor accessor = createPropertyAccessor(citation);
164:                int hashCode = accessor.hashCode(citation);
165:                assertEquals("Empty metadata.", 0, hashCode);
166:
167:                final String ISBN = "Dummy ISBN";
168:                citation.setISBN(ISBN);
169:                hashCode = accessor.hashCode(citation);
170:                assertEquals("Metadata with a single String value.", ISBN
171:                        .hashCode(), hashCode);
172:
173:                final Set set = new HashSet();
174:                assertEquals("By Set.hashCode() contract.", 0, set.hashCode());
175:                assertTrue(set.add(ISBN));
176:                assertEquals("Expected Metadata.hashCode() == Set.hashCode().",
177:                        set.hashCode(), hashCode);
178:
179:                final InternationalString title = new SimpleInternationalString(
180:                        "Dummy title");
181:                citation.setTitle(title);
182:                hashCode = accessor.hashCode(citation);
183:                assertEquals("Metadata with two values.", ISBN.hashCode()
184:                        + title.hashCode(), hashCode);
185:                assertTrue(set.add(title));
186:                assertEquals("Expected Metadata.hashCode() == Set.hashCode().",
187:                        set.hashCode(), hashCode);
188:                assertEquals("CitationsImpl.hashCode() should delegate.",
189:                        hashCode, citation.hashCode());
190:
191:                final Collection values = citation.asMap().values();
192:                assertEquals(hashCode, new HashSet(values).hashCode());
193:                assertTrue(values.containsAll(set));
194:                assertTrue(set.containsAll(values));
195:            }
196:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.