01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.wms.responses.map.kml;
06:
07: import org.geoserver.data.test.MockData;
08: import org.geoserver.wms.WMSTestSupport;
09: import org.vfny.geoserver.wms.WMSMapContext;
10: import org.vfny.geoserver.wms.requests.GetMapRequest;
11: import java.io.File;
12: import java.io.FileOutputStream;
13: import java.util.Enumeration;
14: import java.util.zip.ZipEntry;
15: import java.util.zip.ZipFile;
16: import javax.xml.namespace.QName;
17:
18: public class KMZMapProducerTest extends WMSTestSupport {
19: KMZMapProducer mapProducer;
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23:
24: // create a map context
25: WMSMapContext mapContext = new WMSMapContext();
26: mapContext.addLayer(createMapLayer(MockData.BASIC_POLYGONS));
27: mapContext.addLayer(createMapLayer(MockData.BUILDINGS));
28: mapContext.setMapHeight(256);
29: mapContext.setMapWidth(256);
30:
31: GetMapRequest getMapRequest = createGetMapRequest(new QName[] {
32: MockData.BASIC_POLYGONS, MockData.BUILDINGS });
33: mapContext.setRequest(getMapRequest);
34:
35: // create hte map producer
36: mapProducer = (KMZMapProducer) new KMZMapProducerFactory()
37: .createMapProducer(KMZMapProducerFactory.MIME_TYPE,
38: getWMS());
39: mapProducer.setMapContext(mapContext);
40: mapProducer.produceMap();
41: }
42:
43: public void test() throws Exception {
44: // create the kmz
45: File temp = File.createTempFile("test", "kmz");
46: temp.delete();
47: temp.mkdir();
48: temp.deleteOnExit();
49:
50: File zip = new File(temp, "kmz.zip");
51: zip.deleteOnExit();
52:
53: FileOutputStream output = new FileOutputStream(zip);
54: mapProducer.writeTo(output);
55:
56: output.flush();
57: output.close();
58:
59: assertTrue(zip.exists());
60:
61: // unzip and test it
62: ZipFile zipFile = new ZipFile(zip);
63:
64: assertNotNull(zipFile.getEntry("wms.kml"));
65: assertNotNull(zipFile.getEntry("layer_0.png"));
66: assertNotNull(zipFile.getEntry("layer_1.png"));
67:
68: zipFile.close();
69: }
70: }
|