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.featureinfo;
06:
07: import com.vividsolutions.jts.geom.Coordinate;
08: import com.vividsolutions.jts.geom.GeometryFactory;
09: import freemarker.template.Configuration;
10: import freemarker.template.Template;
11: import junit.framework.TestCase;
12: import org.geoserver.template.FeatureWrapper;
13: import org.geotools.data.DataUtilities;
14: import org.geotools.feature.DefaultFeature;
15: import org.geotools.feature.DefaultFeatureCollection;
16: import org.geotools.feature.DefaultFeatureCollections;
17: import org.geotools.feature.DefaultFeatureType;
18: import org.geotools.feature.FeatureCollection;
19: import org.geotools.feature.FeatureCollections;
20: import org.geotools.feature.FeatureType;
21: import org.vfny.geoserver.wms.responses.featureInfo.FeatureTemplate;
22: import org.w3c.dom.Document;
23: import java.io.ByteArrayInputStream;
24: import java.io.ByteArrayOutputStream;
25: import java.io.OutputStreamWriter;
26: import javax.xml.parsers.DocumentBuilder;
27: import javax.xml.parsers.DocumentBuilderFactory;
28:
29: public class FeatureDescriptionTemplateTest extends TestCase {
30: public void testTemplate() throws Exception {
31: Configuration cfg = new Configuration();
32: cfg.setObjectWrapper(new FeatureWrapper());
33: cfg.setClassForTemplateLoading(FeatureTemplate.class, "");
34:
35: Template template = cfg.getTemplate("description.ftl");
36: assertNotNull(template);
37:
38: //create some data
39: GeometryFactory gf = new GeometryFactory();
40: FeatureType featureType = DataUtilities.createType("testType",
41: "string:String,int:Integer,double:Double,geom:Point");
42:
43: DefaultFeature f = new DefaultFeature(
44: (DefaultFeatureType) featureType, new Object[] {
45: "three", new Integer(3), new Double(3.3),
46: gf.createPoint(new Coordinate(3, 3)) }, "fid.3") {
47: };
48:
49: ByteArrayOutputStream output = new ByteArrayOutputStream();
50: template.process(f, new OutputStreamWriter(output));
51: template.process(f, new OutputStreamWriter(System.out));
52:
53: DocumentBuilder docBuilder = DocumentBuilderFactory
54: .newInstance().newDocumentBuilder();
55: Document document = docBuilder.parse(new ByteArrayInputStream(
56: output.toByteArray()));
57:
58: assertNotNull(document);
59:
60: assertEquals("table", document.getDocumentElement()
61: .getNodeName());
62: }
63:
64: // public void testFeatureCollection() throws Exception {
65: // Configuration cfg = new Configuration();
66: // cfg.setObjectWrapper(new FeatureWrapper());
67: // cfg.setClassForTemplateLoading(FeatureDescriptionTemplate.class, "");
68: //
69: // Template template = cfg.getTemplate("description.ftl");
70: // assertNotNull(template);
71: //
72: // //create some data
73: // GeometryFactory gf = new GeometryFactory();
74: // FeatureType featureType = DataUtilities.createType("testType",
75: // "string:String,int:Integer,double:Double,geom:Point");
76: //
77: // DefaultFeature f = new DefaultFeature((DefaultFeatureType) featureType,
78: // new Object[] {
79: // "three", new Integer(3), new Double(3.3), gf.createPoint(new Coordinate(3, 3))
80: // }, "fid.3") {
81: // };
82: // DefaultFeature f4 = new DefaultFeature((DefaultFeatureType) featureType,
83: // new Object[] {
84: // "four", new Integer(4), new Double(4.4), gf.createPoint(new Coordinate(4, 4))
85: // }, "fid.4") {
86: // };
87: // FeatureCollection features = new DefaultFeatureCollection(null,null) {};
88: // features.add( f );
89: // features.add( f4 );
90: //
91: // template.process(features, new OutputStreamWriter( System.out ));
92: //
93: // }
94: }
|