01: package org.vfny.geoserver.wms.responses.featureinfo;
02:
03: import java.util.Iterator;
04:
05: import org.geoserver.data.test.MockData;
06: import org.geoserver.wms.WMSTestSupport;
07: import org.geotools.data.FeatureSource;
08: import org.geotools.feature.Feature;
09: import org.geotools.feature.FeatureCollection;
10: import org.vfny.geoserver.wms.responses.featureInfo.FeatureTemplate;
11: import org.vfny.geoserver.wms.responses.featureinfo.dummy.Dummy;
12:
13: public class FeatureTemplateTest extends WMSTestSupport {
14:
15: public void testWithDateAndBoolean() throws Exception {
16:
17: FeatureSource source = getFeatureSource(MockData.PRIMITIVEGEOFEATURE);
18: FeatureCollection fc = source.getFeatures();
19: Iterator i = fc.iterator();
20: try {
21: Feature f = (Feature) i.next();
22:
23: FeatureTemplate template = new FeatureTemplate();
24: try {
25: template.description(f);
26: } catch (Exception e) {
27: e.printStackTrace();
28: fail("template threw exception on null value");
29: }
30: } finally {
31: fc.close(i);
32: }
33: }
34:
35: public void testRawValue() throws Exception {
36: FeatureSource source = getFeatureSource(MockData.PRIMITIVEGEOFEATURE);
37: FeatureCollection fc = source.getFeatures();
38: Iterator i = fc.iterator();
39: try {
40: Feature f = (Feature) i.next();
41:
42: FeatureTemplate template = new FeatureTemplate();
43: try {
44: template.template(f, "rawValues.ftl",
45: FeatureTemplateTest.class);
46: } catch (Exception e) {
47: e.printStackTrace();
48: throw (e);
49: }
50: } finally {
51: fc.close(i);
52: }
53: }
54:
55: public void testWithNull() throws Exception {
56:
57: FeatureSource source = getFeatureSource(MockData.BASIC_POLYGONS);
58: FeatureCollection fc = source.getFeatures();
59: Iterator i = fc.iterator();
60: try {
61: Feature f = (Feature) i.next();
62:
63: FeatureTemplate template = new FeatureTemplate();
64: template.description(f);
65:
66: //set a value to null
67: f.setAttribute(1, null);
68: try {
69: template.description(f);
70: } catch (Exception e) {
71: e.printStackTrace();
72: fail("template threw exception on null value");
73: }
74:
75: } finally {
76: fc.close(i);
77: }
78:
79: }
80:
81: public void testAlternateLookup() throws Exception {
82:
83: FeatureSource source = getFeatureSource(MockData.PRIMITIVEGEOFEATURE);
84: FeatureCollection fc = source.getFeatures();
85: Feature f = fc.features().next();
86:
87: FeatureTemplate template = new FeatureTemplate();
88: String result = template.template(f, "dummy.ftl", Dummy.class);
89:
90: assertEquals("dummy", result);
91: }
92: }
|