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


001:        /*
002:         *    GeoTools - OpenSource mapping toolkit
003:         *    http://geotools.org
004:         *    (C) 2002-2006, 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;
009:         *    version 2.1 of the License.
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.gml3;
017:
018:        import junit.extensions.TestSetup;
019:        import junit.framework.Test;
020:        import junit.framework.TestCase;
021:        import junit.framework.TestSuite;
022:        import org.eclipse.xsd.XSDSchema;
023:        import org.eclipse.xsd.util.XSDSchemaLocationResolver;
024:        import java.io.File;
025:        import java.io.FileNotFoundException;
026:        import java.net.URI;
027:        import java.util.List;
028:        import org.geotools.xml.Configuration;
029:        import org.geotools.xml.Schemas;
030:        import org.geotools.xs.XSConfiguration;
031:
032:        /**
033:         * Structure of the files in the test folder:
034:         *
035:         * <pre>
036:         * <code>
037:         * a.xsd
038:         * b.xsd
039:         * c.xsd
040:         * </code>
041:         * Where a.xsd includes b.xsd, a.xsd imports c.xsd, c.xsd imports subfolder/d.xsd.
042:         * </pre>
043:         *
044:         * @author Gabriel Roldan
045:         * @version $Id: ApplicationSchemaConfigurationTest.java 29135 2008-02-07 19:49:09Z desruisseaux $
046:         * @URL $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/unsupported/xml-gml3/src/test/java/org/geotools/gml3/ApplicationSchemaConfigurationTest.java $
047:         * @since 2.4.x
048:         *
049:         */
050:        public class ApplicationSchemaConfigurationTest extends TestCase {
051:            private static final String namespace = "http://www.geotools.org/test";
052:            private static ApplicationSchemaConfiguration configuration;
053:            private static XSDSchema rootSchema;
054:            private static String rootSchemaLocationFolder;
055:            private static String rootSchemaLocation;
056:
057:            /**
058:             * Builds a test suite for all this class' tests with per suite
059:             * initialization directed to {@link #oneTimeSetUp()} and per suite clean up
060:             * directed to {@link #oneTimeTearDown()}
061:             *
062:             * @return
063:             */
064:            public static Test suite() {
065:                TestSuite suite = new TestSuite();
066:                suite.addTestSuite(ApplicationSchemaConfigurationTest.class);
067:
068:                TestSetup wrapper = new TestSetup(suite) {
069:                    protected void setUp() throws Exception {
070:                        oneTimeSetUp();
071:                    }
072:
073:                    protected void tearDown() {
074:                        oneTimeTearDown();
075:                    }
076:                };
077:
078:                return wrapper;
079:            }
080:
081:            private static void oneTimeSetUp() throws Exception {
082:                // test files located in src/test/resources/<this class package name>
083:                final String testFilesFolderName = "./ApplicationSchemaConfigurationTestFiles";
084:                final File file = new File(new URI(
085:                        ApplicationSchemaConfigurationTest.class.getResource(
086:                                testFilesFolderName).toExternalForm()));
087:
088:                if (!file.exists()) {
089:                    throw new FileNotFoundException(
090:                            "test resources folder does not exists: "
091:                                    + file.getAbsolutePath());
092:                }
093:
094:                rootSchemaLocationFolder = file.toURI().toString();
095:                rootSchemaLocation = new File(file, "a.xsd").toURI().toString();
096:                configuration = new ApplicationSchemaConfiguration(namespace,
097:                        rootSchemaLocation);
098:
099:                rootSchema = Schemas.parse(rootSchemaLocation);
100:            }
101:
102:            private static void oneTimeTearDown() {
103:                configuration = null;
104:                rootSchema = null;
105:            }
106:
107:            /**
108:             */
109:            protected void setUp() throws Exception {
110:                super .setUp();
111:
112:                // may be we're running a single test instead of the whose suite
113:                if (configuration == null) {
114:                    oneTimeSetUp();
115:                }
116:            }
117:
118:            protected void tearDown() throws Exception {
119:                super .tearDown();
120:            }
121:
122:            public void testGetDependencies() {
123:                List dependencies = configuration.getDependencies();
124:                assertNotNull(dependencies);
125:                assertEquals(2, dependencies.size());
126:
127:                Configuration dep1 = (Configuration) dependencies.get(0);
128:                Configuration dep2 = (Configuration) dependencies.get(1);
129:
130:                assertTrue(dep1 instanceof  XSConfiguration);
131:                assertTrue(dep2 instanceof  GMLConfiguration);
132:            }
133:
134:            public void testGetSchemaLocationResolverPreconditions()
135:                    throws Exception {
136:                final XSDSchemaLocationResolver resolver = configuration
137:                        .getSchemaLocationResolver();
138:
139:                //null schema is allowed if for the same namespace than the configuration
140:                String location = resolver.resolveSchemaLocation(null,
141:                        namespace, "a.xsd");
142:                assertEquals(rootSchemaLocation, location);
143:
144:                try {
145:                    //but now allowed otherwise
146:                    resolver.resolveSchemaLocation(null, namespace + "/2", "");
147:                    fail("Expected NPE on null schema");
148:                } catch (NullPointerException e) {
149:                    assertTrue(true);
150:                }
151:
152:                try {
153:                    resolver.resolveSchemaLocation(rootSchema, null, "");
154:                    fail("Expected NPE on null uri");
155:                } catch (NullPointerException e) {
156:                    assertTrue(true);
157:                }
158:
159:                try {
160:                    resolver.resolveSchemaLocation(rootSchema, namespace, null);
161:                    fail("Expected NPE on null schema location");
162:                } catch (NullPointerException e) {
163:                    assertTrue(true);
164:                }
165:            }
166:
167:            /**
168:             * a.xsd include b.xsd
169:             */
170:            public void testGetSchemaLocationResolverRelativeInclude()
171:                    throws Exception {
172:                final XSDSchemaLocationResolver resolver = configuration
173:                        .getSchemaLocationResolver();
174:
175:                // simulate an include, empty locationUri
176:                final String locationUri = "";
177:                final String schemaLocation = "b.xsd";
178:
179:                final String importLocation = resolver.resolveSchemaLocation(
180:                        rootSchema, locationUri, schemaLocation);
181:                final String expectedLocation = new File(new File(new URI(
182:                        rootSchemaLocationFolder)), schemaLocation).toURL()
183:                        .toExternalForm();
184:                assertEquals(expectedLocation, importLocation);
185:            }
186:
187:            /**
188:             * a.xsd imports c.xsd
189:             */
190:            public void testGetSchemaLocationResolverRelativeImport()
191:                    throws Exception {
192:                final XSDSchemaLocationResolver resolver = configuration
193:                        .getSchemaLocationResolver();
194:
195:                // simulate a relative path import
196:                final String locationUri = "http://www.geotools.org/test/2";
197:                final String schemaLocation = "c.xsd";
198:
199:                final String importLocation = resolver.resolveSchemaLocation(
200:                        rootSchema, locationUri, schemaLocation);
201:                final String expectedLocation = new File(new File(new URI(
202:                        rootSchemaLocationFolder)), schemaLocation).toURL()
203:                        .toExternalForm();
204:                assertEquals(expectedLocation, importLocation);
205:            }
206:
207:            /**
208:             * a.xsd imports http://www.w3.org/2001/xml.xsd
209:             */
210:            public void testGetSchemaLocationResolverAbsoluteImport()
211:                    throws Exception {
212:                final XSDSchemaLocationResolver resolver = configuration
213:                        .getSchemaLocationResolver();
214:
215:                // simulate an absolute path import
216:                final String locationUri = "http://www.w3.org/XML/1998/namespace";
217:                final String schemaLocation = "http://www.w3.org/2001/xml.xsd";
218:
219:                final String importLocation = resolver.resolveSchemaLocation(
220:                        rootSchema, locationUri, schemaLocation);
221:
222:                assertNull(importLocation);
223:            }
224:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.