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;
06:
07: import org.geotools.image.ImageWorker;
08: import org.vfny.geoserver.wms.responses.DefaultRasterMapProducer;
09: import org.vfny.geoserver.wms.responses.DefaultRasterMapProducerTest;
10: import org.vfny.geoserver.wms.responses.map.gif.GIFMapProducer;
11: import java.awt.image.BufferedImage;
12: import java.awt.image.RenderedImage;
13: import java.io.File;
14: import java.io.FileOutputStream;
15: import java.io.OutputStream;
16: import javax.imageio.ImageIO;
17:
18: /**
19: * @task TODO: do some decent testing
20: *
21: * @author Gabriel Roldan, Axios Engineering
22: * @version $Id: GIFMapProducerTest.java 7467 2007-08-28 22:29:03Z afabiani $
23: */
24: public class GIFMapProducerTest extends DefaultRasterMapProducerTest {
25: /**
26: *
27: */
28: public GIFMapProducerTest() {
29: super ();
30: }
31:
32: protected DefaultRasterMapProducer getProducerInstance() {
33: return new GIFMapProducer("image/gif", null); //DJB: set content enconding correctly
34: }
35:
36: /**
37: * DOCUMENT ME!
38: *
39: * @param testName DOCUMENT ME!
40: * @param producer DOCUMENT ME!
41: */
42: protected void assertNotBlank(String testName,
43: DefaultRasterMapProducer producer) {
44: RenderedImage image = producer.getImage();
45:
46: BufferedImage product = null;
47: File tmpGif = null;
48:
49: try {
50: tmpGif = File.createTempFile(testName, ".gif");
51: tmpGif.deleteOnExit();
52:
53: //tmpGif.deleteOnExit();
54: OutputStream out = new FileOutputStream(tmpGif);
55: producer.writeTo(out);
56: out.flush();
57: out.close();
58:
59: product = ImageWorker.loadPlanarImageImage(
60: tmpGif.getAbsolutePath(), null, 0, true)
61: .getAsBufferedImage();
62: } catch (Exception e) {
63: e.printStackTrace();
64: fail(e.getMessage());
65: }
66:
67: int w = image.getWidth();
68: int h = image.getHeight();
69:
70: assertNotNull(product);
71: assertEquals(w, product.getWidth());
72: assertEquals(h, product.getHeight());
73:
74: System.out.println("width=" + w + ", height=" + h);
75:
76: showImage(testName, product);
77: }
78:
79: public static void main(String[] args) {
80: junit.textui.TestRunner.run(GIFMapProducerTest.class);
81: }
82: }
|