1
2
3
4
5
6
7 package nl.mineleni.cbsviewer.servlet.wms;
8
9 import static org.custommonkey.xmlunit.XMLAssert.assertXpathEvaluatesTo;
10 import static org.custommonkey.xmlunit.XMLAssert.assertXpathExists;
11 import static org.custommonkey.xmlunit.XMLAssert.assertXpathValuesEqual;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertSame;
15
16 import java.io.IOException;
17
18 import nl.mineleni.cbsviewer.util.LabelsBundle;
19 import nl.mineleni.cbsviewer.util.xml.LayerDescriptor;
20
21 import org.custommonkey.xmlunit.XMLUnit;
22 import org.junit.Before;
23 import org.junit.Test;
24
25
26
27
28
29
30 public class FeatureInfoResponseConverterTest {
31
32 private static final LabelsBundle RESOURCES = new LabelsBundle();
33
34
35 private LayerDescriptor layer;
36
37
38
39
40
41
42
43 @Before
44 public void setUp() throws Exception {
45 XMLUnit.setIgnoreWhitespace(true);
46 XMLUnit.setIgnoreComments(true);
47
48 this.layer = new LayerDescriptor();
49
50 this.layer
51 .setId("wijkenbuurten2011_thema_gemeenten2011_aantal_inwoners");
52 this.layer.setName("CBS Gemeenten 2011 - Aantal inwoners");
53 this.layer.setLayers("gemeenten2011");
54 this.layer
55 .setUrl("http://geodata.nationaalgeoregister.nl/wijkenbuurten2011/wms");
56 this.layer
57 .setStyles("wijkenbuurten2011_thema_gemeenten2011_aantal_inwoners");
58 this.layer.setAttributes("gemeentecode,aantal_inwoners");
59
60 this.layer
61 .setLink("http://geodata.nationaalgeoregister.nl/wijkenbuurten2011/wfs?request=GetFeature&typeName=wijkenbuurten2011:gemeenten2011&outputFormat=SHAPE-ZIP");
62
63 }
64
65
66
67
68
69
70
71
72
73 @Test
74 public final void testConvertToHTMLTableGML0() throws Exception {
75 final String testXML = FeatureInfoResponseConverter
76 .convertToHTMLTable(this.getClass().getClassLoader()
77 .getResourceAsStream("GetFeatureInfoResponse0.gml"),
78 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
79 this.layer);
80 assertNotNull(testXML);
81 assertEquals(new LabelsBundle().getString("KEY_INFO_GEEN_FEATURES"),
82 testXML);
83 }
84
85
86
87
88
89
90
91
92
93 @Test
94 public final void testConvertToHTMLTableGML1() throws Exception {
95 final String[] colNames = this.layer.getAttributes().split(",\\s*");
96 final String testXML = FeatureInfoResponseConverter
97 .convertToHTMLTable(this.getClass().getClassLoader()
98 .getResourceAsStream("GetFeatureInfoResponse1.gml"),
99 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
100 this.layer);
101 assertNotNull(testXML);
102
103
104
105
106 assertXpathExists("//caption", testXML);
107 assertXpathExists("/table/caption", testXML);
108 assertXpathEvaluatesTo("" + colNames.length, "count(//th)", testXML);
109 assertXpathEvaluatesTo(colNames[0], "/table//th[@scope='col']", testXML);
110 assertXpathEvaluatesTo(colNames[1], "/table//th[2][@scope='col']",
111 testXML);
112 }
113
114
115
116
117
118
119
120
121
122 @Test
123 public final void testConvertToHTMLTableGML3() throws Exception {
124 final String[] colNames = this.layer.getAttributes().split(",\\s*");
125
126 final String testXML = FeatureInfoResponseConverter
127 .convertToHTMLTable(this.getClass().getClassLoader()
128 .getResourceAsStream("GetFeatureInfoResponse3.gml"),
129 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
130 this.layer);
131 assertNotNull(testXML);
132 assertXpathExists("//caption", testXML);
133 assertXpathExists("/table/caption", testXML);
134 assertXpathEvaluatesTo("" + colNames.length, "count(//th)", testXML);
135 assertXpathEvaluatesTo(colNames[0], "/table//th[@scope='col']", testXML);
136 assertXpathEvaluatesTo(colNames[1], "/table//th[2][@scope='col']",
137 testXML);
138 assertXpathEvaluatesTo("3", "count(//tbody/tr)", testXML);
139 assertXpathValuesEqual("//tbody/tr[@class='even']", "//tbody/tr[2]",
140 testXML);
141 assertXpathValuesEqual("//tbody/tr[@class='odd'][2]", "//tbody/tr[3]",
142 testXML);
143 }
144
145
146
147
148
149
150
151
152
153 @Test
154 public final void testConvertToHTMLTableHTML0() throws IOException {
155 final String test = FeatureInfoResponseConverter.convertToHTMLTable(
156 this.getClass().getClassLoader()
157 .getResourceAsStream("GetFeatureInfoResponse0.html"),
158 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
159 this.layer);
160 assertNotNull(test);
161 assertSame(RESOURCES.getString("KEY_INFO_GEEN_FEATURES"), test);
162 }
163
164
165
166
167
168
169
170
171
172 @Test
173 public final void testConvertToHTMLTableHTML1() throws IOException {
174 final String test = FeatureInfoResponseConverter.convertToHTMLTable(
175 this.getClass().getClassLoader()
176 .getResourceAsStream("GetFeatureInfoResponse1.html"),
177 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
178 this.layer);
179 assertNotNull(test);
180 }
181
182
183
184
185
186
187
188
189
190 @Test
191 public final void testConvertToHTMLTableHTML3() throws IOException {
192 final String test = FeatureInfoResponseConverter.convertToHTMLTable(
193 this.getClass().getClassLoader()
194 .getResourceAsStream("GetFeatureInfoResponse3.html"),
195 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
196 this.layer);
197 assertNotNull(test);
198 }
199
200
201
202
203
204
205
206 public final void testConvert0() throws IOException {
207 final String testHTML = FeatureInfoResponseConverter
208 .convertToHTMLTable(this.getClass().getClassLoader()
209 .getResourceAsStream("GetFeatureInfoResponse0.html"),
210 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
211 this.layer);
212 final String testXML = FeatureInfoResponseConverter
213 .convertToHTMLTable(this.getClass().getClassLoader()
214 .getResourceAsStream("GetFeatureInfoResponse0.gml"),
215 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
216 this.layer);
217 assertEquals(testHTML, testXML);
218 }
219
220
221
222
223
224
225
226 public final void testConvert2() throws IOException {
227 final String testHTML = FeatureInfoResponseConverter
228 .convertToHTMLTable(this.getClass().getClassLoader()
229 .getResourceAsStream("GetFeatureInfoResponse1.html"),
230 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
231 this.layer);
232 final String testXML = FeatureInfoResponseConverter
233 .convertToHTMLTable(this.getClass().getClassLoader()
234 .getResourceAsStream("GetFeatureInfoResponse1.gml"),
235 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
236 this.layer);
237 assertEquals(testHTML, testXML);
238 }
239
240
241
242
243
244
245
246 public final void testConvert3() throws IOException {
247 final String testHTML = FeatureInfoResponseConverter
248 .convertToHTMLTable(this.getClass().getClassLoader()
249 .getResourceAsStream("GetFeatureInfoResponse3.html"),
250 FeatureInfoResponseConverter.CONVERTER_TYPE.HTMLTYPE,
251 this.layer);
252 final String testXML = FeatureInfoResponseConverter
253 .convertToHTMLTable(this.getClass().getClassLoader()
254 .getResourceAsStream("GetFeatureInfoResponse3.gml"),
255 FeatureInfoResponseConverter.CONVERTER_TYPE.GMLTYPE,
256 this.layer);
257 assertEquals(testHTML, testXML);
258 }
259 }