01: package org.vfny.geoserver.wms.responses.featureinfo;
02:
03: import org.geoserver.data.test.MockData;
04: import org.geoserver.wms.WMSTestSupport;
05: import org.geotools.data.FeatureSource;
06: import org.geotools.feature.Feature;
07: import org.geotools.feature.FeatureCollection;
08: import org.geotools.feature.FeatureIterator;
09: import org.vfny.geoserver.wms.responses.featureInfo.FeatureTimeTemplate;
10:
11: public class FeatureTimeTemplateTest extends WMSTestSupport {
12:
13: Feature feature;
14:
15: protected void setUp() throws Exception {
16: super .setUp();
17:
18: FeatureSource source = getFeatureSource(MockData.PRIMITIVEGEOFEATURE);
19: FeatureCollection features = source.getFeatures();
20: FeatureIterator iterator = features.features();
21: while (iterator.hasNext()) {
22: Feature f = iterator.next();
23: if (f.getAttribute("dateProperty") != null) {
24: feature = f;
25: break;
26: }
27: }
28: features.close(iterator);
29: }
30:
31: public void testEmpty() throws Exception {
32: FeatureTimeTemplate template = new FeatureTimeTemplate();
33: String[] result = template.execute(feature);
34:
35: assertEquals(0, result.length);
36: }
37:
38: public void testTimestamp() throws Exception {
39: setupTemplate(MockData.PRIMITIVEGEOFEATURE, "time.ftl",
40: "${dateProperty.value}");
41:
42: FeatureTimeTemplate template = new FeatureTimeTemplate();
43: String[] result = template.execute(feature);
44:
45: assertEquals(1, result.length);
46: assertNotNull(result[0]);
47: }
48:
49: public void testTimeSpan() throws Exception {
50: setupTemplate(MockData.PRIMITIVEGEOFEATURE, "time.ftl",
51: "${dateProperty.value}||${dateProperty.value}");
52: FeatureTimeTemplate template = new FeatureTimeTemplate();
53: String[] result = template.execute(feature);
54:
55: assertEquals(2, result.length);
56: assertNotNull(result[0]);
57: assertNotNull(result[1]);
58: }
59:
60: public void testTimeSpanOpenEndedStart() throws Exception {
61: setupTemplate(MockData.PRIMITIVEGEOFEATURE, "time.ftl",
62: "||${dateProperty.value}");
63: FeatureTimeTemplate template = new FeatureTimeTemplate();
64: String[] result = template.execute(feature);
65:
66: assertEquals(2, result.length);
67: assertNull(result[0]);
68: assertNotNull(result[1]);
69: }
70:
71: public void testTimeSpanOpenEndedEnd() throws Exception {
72: setupTemplate(MockData.PRIMITIVEGEOFEATURE, "time.ftl",
73: "${dateProperty.value}||");
74: FeatureTimeTemplate template = new FeatureTimeTemplate();
75: String[] result = template.execute(feature);
76:
77: assertEquals(2, result.length);
78: assertNotNull(result[0]);
79: assertNull(result[1]);
80: }
81: }
|