01: package org.geotools.renderer.lite;
02:
03: import java.awt.Frame;
04: import java.awt.Graphics;
05: import java.awt.Panel;
06: import java.awt.event.WindowAdapter;
07: import java.awt.event.WindowEvent;
08: import java.awt.image.BufferedImage;
09:
10: import junit.framework.TestCase;
11:
12: import org.geotools.test.TestData;
13: import org.geotools.styling.ExternalGraphic;
14: import org.geotools.styling.StyleFactory;
15: import org.geotools.styling.StyleFactoryFinder;
16:
17: public class SVGGlyphRendererTest extends TestCase {
18:
19: private SVGGlyphRenderer renderer;
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23: renderer = new SVGGlyphRenderer();
24: }
25:
26: public void testCanRender() {
27: // test against the resurgence or
28: // http://jira.codehaus.org/browse/GEOT-920
29: assertTrue(renderer.canRender("image/svg+xml"));
30: }
31:
32: // shape and gradient
33: public void testRenderGradient() throws InterruptedException {
34: StyleFactory sf = StyleFactoryFinder.createStyleFactory();
35: ExternalGraphic eg = sf
36: .createExternalGraphic(this .getClass().getResource(
37: "test-data/gradient.svg"), "image/svg+xml");
38: BufferedImage image = renderer.render(null, eg, null, -1);
39: assertNotNull(image);
40: showImage("Opacity", 1000, image);
41: }
42:
43: // shape and gradient
44: public void testRenderCss() throws InterruptedException {
45: StyleFactory sf = StyleFactoryFinder.createStyleFactory();
46: ExternalGraphic eg = sf.createExternalGraphic(this .getClass()
47: .getResource("test-data/squarecss.svg"),
48: "image/svg+xml");
49: BufferedImage image = renderer.render(null, eg, null, -1);
50: assertNotNull(image);
51: showImage("Opacity", 1000, image);
52: }
53:
54: // text rendering (added just to make sure we have all the jars needed for
55: // batik
56: // since a few things are needed only when using certain SVG features it
57: // seems)
58: public void testRenderText() throws InterruptedException {
59: StyleFactory sf = StyleFactoryFinder.createStyleFactory();
60: ExternalGraphic eg = sf.createExternalGraphic(this .getClass()
61: .getResource("test-data/text.svg"), "image/svg+xml");
62: BufferedImage image = renderer.render(null, eg, null, -1);
63: assertNotNull(image);
64: showImage("Opacity", 1000, image);
65: }
66:
67: private void showImage(final String testName, final int timeout,
68: final BufferedImage image) throws InterruptedException {
69: if ((System.getProperty("java.awt.headless") == null || !System
70: .getProperty("java.awt.headless").equals("true"))
71: && TestData.isInteractiveTest()) {
72: Frame frame = new Frame(testName);
73: frame.addWindowListener(new WindowAdapter() {
74: public void windowClosing(WindowEvent e) {
75: e.getWindow().dispose();
76: }
77: });
78:
79: Panel p = new Panel() {
80: /** <code>serialVersionUID</code> field */
81: private static final long serialVersionUID = 1L;
82:
83: public void paint(Graphics g) {
84: g.drawImage(image, 0, 0, this );
85: }
86: };
87: frame.add(p);
88: frame
89: .setSize(image.getWidth() + 50,
90: image.getHeight() + 50);
91: frame.setVisible(true);
92:
93: Thread.sleep(timeout);
94: frame.dispose();
95: }
96: }
97: }
|