Source Code Cross Referenced for KMLTransformerTest.java in  » GIS » GeoServer » org » vfny » geoserver » wms » responses » map » kml » 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 » GeoServer » org.vfny.geoserver.wms.responses.map.kml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002:         * This code is licensed under the GPL 2.0 license, availible at the root
003:         * application directory.
004:         */
005:        package org.vfny.geoserver.wms.responses.map.kml;
006:
007:        import com.mockrunner.mock.web.MockHttpServletRequest;
008:        import com.vividsolutions.jts.geom.Envelope;
009:        import org.geoserver.data.test.MockData;
010:        import org.geoserver.util.ReaderUtils;
011:        import org.geoserver.wms.WMSTestSupport;
012:        import org.geotools.data.FeatureSource;
013:        import org.geotools.map.DefaultMapLayer;
014:        import org.geotools.map.MapLayer;
015:        import org.geotools.referencing.CRS;
016:        import org.geotools.styling.Style;
017:        import org.vfny.geoserver.config.FeatureTypeConfig;
018:        import org.vfny.geoserver.global.Data;
019:        import org.vfny.geoserver.global.FeatureTypeInfo;
020:        import org.vfny.geoserver.global.MapLayerInfo;
021:        import org.vfny.geoserver.global.dto.FeatureTypeInfoDTO;
022:        import org.vfny.geoserver.wms.WMSMapContext;
023:        import org.vfny.geoserver.wms.requests.GetMapRequest;
024:        import org.vfny.geoserver.wms.servlets.GetMap;
025:        import org.w3c.dom.Document;
026:        import org.w3c.dom.Element;
027:        import org.w3c.dom.NodeList;
028:
029:        import java.io.ByteArrayInputStream;
030:        import java.io.ByteArrayOutputStream;
031:        import javax.xml.parsers.DocumentBuilder;
032:        import javax.xml.parsers.DocumentBuilderFactory;
033:
034:        public class KMLTransformerTest extends WMSTestSupport {
035:            WMSMapContext mapContext;
036:            MapLayer mapLayer;
037:
038:            protected void setUp() throws Exception {
039:                super .setUp();
040:
041:                mapLayer = createMapLayer(MockData.BASIC_POLYGONS);
042:
043:                mapContext = new WMSMapContext(
044:                        createGetMapRequest(MockData.BASIC_POLYGONS));
045:                mapContext.addLayer(mapLayer);
046:            }
047:
048:            public void testVectorTransformer() throws Exception {
049:                KMLVectorTransformer transformer = new KMLVectorTransformer(
050:                        mapContext, mapLayer);
051:                transformer.setIndentation(2);
052:
053:                FeatureSource featureSource = mapLayer.getFeatureSource();
054:                int nfeatures = featureSource.getFeatures().size();
055:
056:                ByteArrayOutputStream output = new ByteArrayOutputStream();
057:                transformer.transform(featureSource.getFeatures(), output);
058:
059:                DocumentBuilder docBuilder = DocumentBuilderFactory
060:                        .newInstance().newDocumentBuilder();
061:                Document document = docBuilder.parse(new ByteArrayInputStream(
062:                        output.toByteArray()));
063:
064:                Element element = document.getDocumentElement();
065:                assertEquals("kml", element.getNodeName());
066:                assertEquals(nfeatures, element.getElementsByTagName("Style")
067:                        .getLength());
068:                assertEquals(nfeatures, element.getElementsByTagName(
069:                        "Placemark").getLength());
070:            }
071:
072:            //JD: commented out because there is no way to specify a coordinate reference
073:            // system in property datastores.
074:            //    public void testReprojection() throws Exception {
075:            //        KMLTransformer transformer = new KMLTransformer();
076:            //        transformer.setIndentation(2);
077:            //           
078:            //        ByteArrayOutputStream output = new ByteArrayOutputStream();
079:            //        transformer.transform(mapContext, output);
080:            //        transformer.transform(mapContext,System.out);
081:            //        DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
082:            //        Document doc1 = docBuilder.parse(new ByteArrayInputStream(output.toByteArray()));
083:            //
084:            //        mapContext.setCoordinateReferenceSystem(CRS.decode("EPSG:3005"));
085:            //        output = new ByteArrayOutputStream();
086:            //        transformer.transform(mapContext, output);
087:            //        transformer.transform(mapContext,System.out);
088:            //        Document doc2 = docBuilder.parse(new ByteArrayInputStream(output.toByteArray()));
089:            //        
090:            //        NodeList docs1 = doc1.getDocumentElement().getElementsByTagName("Document");
091:            //        NodeList docs2 = doc2.getDocumentElement().getElementsByTagName("Document");
092:            //        
093:            //        assertEquals( docs1.getLength(), docs2.getLength() );
094:            //        for ( int i = 0; i < docs1.getLength(); i++ ) {
095:            //            Element e1 = (Element) docs1.item(i);
096:            //            Element e2 = (Element) docs2.item(i);
097:            //            
098:            //            String name1 = ReaderUtils.getChildText( e1, "name" );
099:            //            String name2 = ReaderUtils.getChildText( e2, "name" );
100:            //            
101:            //            assertEquals( name1, name2 );
102:            //            
103:            //            Element p1 = (Element) e1.getElementsByTagName("Placemark").item(0);
104:            //            Element p2 = (Element) e2.getElementsByTagName("Placemark").item(0);
105:            //            
106:            //            Element poly1 = (Element) p1.getElementsByTagName("Polygon").item(0);
107:            //            Element poly2 = (Element) p2.getElementsByTagName("Polygon").item(0);
108:            //            
109:            //            Element c1 = (Element) poly1.getElementsByTagName("coordinates").item(0);
110:            //            Element c2 = (Element) poly2.getElementsByTagName("coordinates").item(0);
111:            //            
112:            //            assertFalse(c1.getFirstChild().getNodeValue().equals( c2.getFirstChild().getNodeValue()));
113:            //        }
114:            //        
115:            //    }
116:
117:            public void testRasterTransformerInline() throws Exception {
118:                KMLRasterTransformer transformer = new KMLRasterTransformer(
119:                        mapContext);
120:                transformer.setInline(true);
121:
122:                ByteArrayOutputStream output = new ByteArrayOutputStream();
123:                transformer.transform(mapLayer, output);
124:
125:                DocumentBuilder docBuilder = DocumentBuilderFactory
126:                        .newInstance().newDocumentBuilder();
127:                Document document = docBuilder.parse(new ByteArrayInputStream(
128:                        output.toByteArray()));
129:
130:                assertEquals("kml", document.getDocumentElement().getNodeName());
131:
132:                assertEquals(mapContext.getLayerCount(), document
133:                        .getElementsByTagName("Folder").getLength());
134:                assertEquals(mapContext.getLayerCount(), document
135:                        .getElementsByTagName("GroundOverlay").getLength());
136:
137:                assertEquals(mapContext.getLayerCount(), document
138:                        .getElementsByTagName("href").getLength());
139:
140:                Element href = (Element) document.getElementsByTagName("href")
141:                        .item(0);
142:                assertEquals("layer_0.png", href.getFirstChild().getNodeValue());
143:            }
144:
145:            public void testRasterTransformerNotInline() throws Exception {
146:                KMLRasterTransformer transformer = new KMLRasterTransformer(
147:                        mapContext);
148:                transformer.setInline(false);
149:
150:                ByteArrayOutputStream output = new ByteArrayOutputStream();
151:                transformer.transform(mapLayer, output);
152:
153:                DocumentBuilder docBuilder = DocumentBuilderFactory
154:                        .newInstance().newDocumentBuilder();
155:                Document document = docBuilder.parse(new ByteArrayInputStream(
156:                        output.toByteArray()));
157:
158:                assertEquals("kml", document.getDocumentElement().getNodeName());
159:
160:                assertEquals(mapContext.getLayerCount(), document
161:                        .getElementsByTagName("Folder").getLength());
162:                assertEquals(mapContext.getLayerCount(), document
163:                        .getElementsByTagName("GroundOverlay").getLength());
164:
165:                assertEquals(mapContext.getLayerCount(), document
166:                        .getElementsByTagName("href").getLength());
167:
168:                Element href = (Element) document.getElementsByTagName("href")
169:                        .item(0);
170:                assertTrue(href.getFirstChild().getNodeValue().startsWith(
171:                        "http://localhost"));
172:            }
173:
174:            public void testSuperOverlayTransformer() throws Exception {
175:                KMLSuperOverlayTransformer transformer = new KMLSuperOverlayTransformer(
176:                        mapContext);
177:                transformer.setIndentation(2);
178:
179:                mapContext.setAreaOfInterest(new Envelope(-180, 180, -90, 90));
180:
181:                ByteArrayOutputStream output = new ByteArrayOutputStream();
182:                transformer.transform(mapLayer, output);
183:
184:                DocumentBuilder docBuilder = DocumentBuilderFactory
185:                        .newInstance().newDocumentBuilder();
186:                Document document = docBuilder.parse(new ByteArrayInputStream(
187:                        output.toByteArray()));
188:
189:                assertEquals("kml", document.getDocumentElement().getNodeName());
190:                assertEquals(3, document.getElementsByTagName("Region")
191:                        .getLength());
192:                assertEquals(2, document.getElementsByTagName("NetworkLink")
193:                        .getLength());
194:                assertEquals(2, document.getElementsByTagName("GroundOverlay")
195:                        .getLength());
196:
197:            }
198:
199:            public void testTransformer() throws Exception {
200:                KMLTransformer transformer = new KMLTransformer();
201:
202:                ByteArrayOutputStream output = new ByteArrayOutputStream();
203:                transformer.transform(mapContext, output);
204:
205:                DocumentBuilder docBuilder = DocumentBuilderFactory
206:                        .newInstance().newDocumentBuilder();
207:                Document document = docBuilder.parse(new ByteArrayInputStream(
208:                        output.toByteArray()));
209:
210:                assertEquals("kml", document.getDocumentElement().getNodeName());
211:            }
212:        }
w__w___w___.j___av__a__2_s__.c___o__m | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.