Source Code Cross Referenced for XMLEncoderTest.java in  » GIS » GeoTools-2.4.1 » org » geotools » xml » ogc » 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.xml.ogc 
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; 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.xml.ogc;
017:
018:        import java.io.ByteArrayInputStream;
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.io.StringBufferInputStream;
022:        import java.io.StringReader;
023:        import java.io.StringWriter;
024:        import java.util.HashMap;
025:        import java.util.Map;
026:        import java.util.logging.Level;
027:        import java.util.logging.Logger;
028:
029:        import javax.xml.parsers.DocumentBuilder;
030:        import javax.xml.parsers.DocumentBuilderFactory;
031:
032:        import junit.framework.Test;
033:        import junit.framework.TestCase;
034:        import junit.framework.TestSuite;
035:
036:        import org.geotools.filter.BetweenFilter;
037:        import org.geotools.filter.FidFilter;
038:        import org.geotools.filter.Filter;
039:        import org.geotools.filter.FilterDOMParser;
040:        import org.geotools.filter.FilterFactory;
041:        import org.geotools.filter.FilterFactoryFinder;
042:        import org.geotools.filter.NullFilter;
043:        import org.geotools.test.TestData;
044:        import org.geotools.xml.DocumentFactory;
045:        import org.geotools.xml.DocumentWriter;
046:        import org.geotools.xml.SchemaFactory;
047:        import org.geotools.xml.XMLHandlerHints;
048:        import org.geotools.xml.filter.FilterSchema;
049:        import org.w3c.dom.Document;
050:        import org.w3c.dom.Element;
051:        import org.w3c.dom.Node;
052:        import org.w3c.dom.NodeList;
053:
054:        /**
055:         * This code uses the filter parser to generate test cases, and runs it through the encoder.
056:         * 
057:         * TODO create the filters manually, and check the output.
058:         *
059:         * @author James MacGill, CCG
060:         * @author Rob Hranac, TOPP
061:         * @author David Zwiers
062:         * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/xml/src/test/java/org/geotools/xml/ogc/XMLEncoderTest.java $
063:         */
064:        public class XMLEncoderTest extends TestCase {
065:
066:            /** Standard logging instance */
067:            protected static final Logger LOGGER = org.geotools.util.logging.Logging
068:                    .getLogger("org.geotools.filter");
069:
070:            /** Constructor with test name. */
071:            String dataFolder = "";
072:
073:            public XMLEncoderTest(String testName) {
074:                super (testName);
075:
076:                //_log.getLoggerRepository().setThreshold(Level.DEBUG);
077:                LOGGER.finer("running XMLEncoderTests");
078:
079:                dataFolder = System.getProperty("dataFolder");
080:
081:                if (dataFolder == null) {
082:                    try {
083:                        TestData.file(this , null);
084:                    } catch (IOException e) {
085:                        LOGGER.finer("data folder is unavailable" + dataFolder);
086:                    }
087:                }
088:                if (dataFolder == null) {
089:                    //then we are being run by maven        	
090:                    dataFolder = System.getProperty("basedir");
091:                    dataFolder = "file:////" + "tests/unit/testData"; //url.toString();
092:                    LOGGER.finer("data folder is " + dataFolder);
093:                }
094:            }
095:
096:            /**
097:             * Main for test runner.
098:             *
099:             * @param args DOCUMENT ME!
100:             */
101:            public static void main(String[] args) {
102:                junit.textui.TestRunner.run(suite());
103:            }
104:
105:            /**
106:             * Required suite builder.
107:             *
108:             * @return A test suite for this unit test.
109:             */
110:            public static Test suite() {
111:                TestSuite suite = new TestSuite(XMLEncoderTest.class);
112:
113:                return suite;
114:            }
115:
116:            public void test1() throws Exception {
117:                Filter test = parseDocument("test1.xml");
118:                assertNotNull(test);
119:                StringWriter output = new StringWriter();
120:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
121:                        output, null);
122:                //System.out.println( output );
123:                InputStream stream = new StringBufferInputStream(output
124:                        .toString());
125:
126:                Object o = DocumentFactory.getInstance(stream, new HashMap(),
127:                        Level.FINEST);
128:                assertNotNull(o);
129:                assertEquals(test, o);
130:                //LOGGER.fine("parsed filter is: " + test);        
131:            }
132:
133:            public void test3a() throws Exception {
134:                Filter test = parseDocument("test3a.xml");
135:
136:                //LOGGER.fine("parsed filter is: " + test);
137:            }
138:
139:            public void test3b() throws Exception {
140:                Filter test = parseDocument("test3b.xml");
141:                StringWriter output = new StringWriter();
142:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
143:                        output, null);
144:
145:                //LOGGER.fine("parsed filter is: " + test);
146:            }
147:
148:            public void test4() throws Exception {
149:                Filter test = parseDocument("test4.xml");
150:                StringWriter output = new StringWriter();
151:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
152:                        output, null);
153:
154:                //LOGGER.fine("parsed filter is: " + test);
155:            }
156:
157:            public void test5() throws Exception {
158:                Filter test = parseDocument("test5.xml");
159:                StringWriter output = new StringWriter();
160:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
161:                        output, null);
162:
163:                //LOGGER.fine("parsed filter is: " + test);
164:            }
165:
166:            public void test8() throws Exception {
167:                Filter test = parseDocument("test8.xml");
168:
169:                StringWriter output = new StringWriter();
170:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
171:                        output, null);
172:
173:                //System.out.println(output);
174:                //LOGGER.fine("parsed filter is: " + test);
175:            }
176:
177:            public void test9() throws Exception {
178:                Filter test = parseDocument("test9.xml");
179:                StringWriter output = new StringWriter();
180:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
181:                        output, null);
182:
183:                //LOGGER.fine("parsed filter is: " + test);
184:            }
185:
186:            public void test12() throws Exception {
187:                Filter test = parseDocument("test12.xml");
188:                StringWriter output = new StringWriter();
189:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
190:                        output, null);
191:
192:                // LOGGER.fine("parsed filter is: " + test);
193:            }
194:
195:            public void test13() throws Exception {
196:                Filter test = parseDocument("test13.xml");
197:                StringWriter output = new StringWriter();
198:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
199:                        output, null);
200:
201:                //LOGGER.fine("parsed filter is: " + test);
202:            }
203:
204:            public void test14() throws Exception {
205:                Filter test = parseDocument("test14.xml");
206:                StringWriter output = new StringWriter();
207:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
208:                        output, null);
209:
210:                //LOGGER.fine("parsed filter is: " + test);
211:            }
212:
213:            public void test28() throws Exception {
214:                Filter test = parseDocument("test28.xml");
215:                StringWriter output = new StringWriter();
216:                DocumentWriter.writeFragment(test, FilterSchema.getInstance(),
217:                        output, null);
218:
219:                //System.out.println(output);
220:                //        LOGGER.fine("parsedfilter is: " + test);
221:            }
222:
223:            public Filter parseDocument(String uri) throws Exception {
224:                Filter filter = null;
225:                DocumentBuilderFactory dbf = DocumentBuilderFactory
226:                        .newInstance();
227:                DocumentBuilder db = dbf.newDocumentBuilder();
228:                Document dom = db.parse(TestData.getResource(this , uri)
229:                        .toExternalForm());
230:
231:                //        LOGGER.fine("exporting " + uri);
232:                // first grab a filter node
233:                NodeList nodes = dom.getElementsByTagName("Filter");
234:
235:                for (int j = 0; j < nodes.getLength(); j++) {
236:                    Element filterNode = (Element) nodes.item(j);
237:                    NodeList list = filterNode.getChildNodes();
238:                    Node child = null;
239:
240:                    for (int i = 0; i < list.getLength(); i++) {
241:                        child = list.item(i);
242:
243:                        //_log.getLoggerRepository().setThreshold(Level.INFO);
244:                        if ((child == null)
245:                                || (child.getNodeType() != Node.ELEMENT_NODE)) {
246:                            continue;
247:                        }
248:
249:                        filter = FilterDOMParser.parseFilter(child);
250:
251:                        StringWriter output = new StringWriter();
252:                        DocumentWriter.writeFragment(filter, FilterSchema
253:                                .getInstance(), output, null);
254:
255:                        //                System.out.println(output);
256:                    }
257:                }
258:
259:                return filter;
260:            }
261:
262:            // TODO test or ( null, and( fidFilter, null ) ) filter
263:            public void testStrictHintComplexFilter() throws Exception {
264:                FilterFactory factory = FilterFactoryFinder
265:                        .createFilterFactory();
266:                NullFilter null1 = factory.createNullFilter();
267:                null1.nullCheckValue(factory.createAttributeExpression("name"));
268:                NullFilter null2 = factory.createNullFilter();
269:                null2.nullCheckValue(factory.createAttributeExpression("geom"));
270:                FidFilter fidFilter = factory.createFidFilter("FID.1");
271:                Filter inner = null1.and(fidFilter);
272:                Filter filter = null2.or(inner);
273:
274:                StringWriter output = new StringWriter();
275:                XMLHandlerHints hints = new XMLHandlerHints();
276:                hints.put(XMLHandlerHints.FILTER_COMPLIANCE_STRICTNESS,
277:                        XMLHandlerHints.VALUE_FILTER_COMPLIANCE_MEDIUM);
278:                DocumentWriter.writeFragment(filter,
279:                        FilterSchema.getInstance(), output, hints);
280:                String string = output.toString().replaceAll("\\s", "");
281:                assertEquals(
282:                        "<Filterxmlns=\"http://www.opengis.net/ogc\"xmlns:gml=\"http://www.opengis.net/gml\">"
283:                                + "<PropertyIsNull><PropertyName>geom</PropertyName></PropertyIsNull>"
284:                                + "<FeatureIdfid=\"FID.1\"/>" + "</Filter>",
285:                        string);
286:
287:                // Note:  Round trip doesn't work in this case because request may returns more features than "filter" will accept
288:            }
289:
290:            public void testStrictHintOR() throws Exception {
291:                FilterFactory factory = FilterFactoryFinder
292:                        .createFilterFactory();
293:                Filter filter = factory.createFidFilter("FID.1").or(
294:                        factory.createFidFilter("FID.2"));
295:
296:                StringWriter output = new StringWriter();
297:                XMLHandlerHints hints = new XMLHandlerHints();
298:                hints.put(XMLHandlerHints.FILTER_COMPLIANCE_STRICTNESS,
299:                        XMLHandlerHints.VALUE_FILTER_COMPLIANCE_MEDIUM);
300:                DocumentWriter.writeFragment(filter,
301:                        FilterSchema.getInstance(), output, hints);
302:                String string = output.toString().replaceAll("\\s", "");
303:                // The following test fails with Java 1.6. May be caused by some iteration order dependent code.
304:                if (TestData.isBaseJavaPlatform()) {
305:                    assertEquals(
306:                            "<Filterxmlns=\"http://www.opengis.net/ogc\"xmlns:gml=\"http://www.opengis.net/gml\"><FeatureIdfid=\"FID.1\"/><FeatureIdfid=\"FID.2\"/></Filter>",
307:                            string);
308:                }
309:                Filter roundTrip = (Filter) DocumentFactory.getInstance(
310:                        new ByteArrayInputStream(output.toString().getBytes()),
311:                        null, Level.OFF);
312:                assertEquals(filter, roundTrip);
313:            }
314:
315:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.