Skip to content

Commit f5c5b2d

Browse files
committed
Test that a layer with multiple gridsets has only one ows:WGS84BoundingBox in WMTS Capabilities
1 parent 53cae4f commit f5c5b2d

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

geowebcache/wmts/src/test/java/org/geowebcache/service/wmts/WMTSServiceTest.java

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.geowebcache.conveyor.Conveyor;
3232
import org.geowebcache.conveyor.ConveyorTile;
3333
import org.geowebcache.filter.parameters.ParameterFilter;
34+
import org.geowebcache.grid.BoundingBox;
3435
import org.geowebcache.grid.GridSet;
3536
import org.geowebcache.grid.GridSetBroker;
3637
import org.geowebcache.grid.GridSubset;
@@ -188,6 +189,76 @@ public void testGetCap() throws Exception {
188189
assertEquals("1", xpath.evaluate("count(//wmts:Contents/wmts:Layer/wmts:Style/ows:Identifier)", doc));
189190
assertEquals("", xpath.evaluate("//wmts:Contents/wmts:Layer/wmts:Style/ows:Identifier", doc));
190191
}
192+
193+
public void testGetCapOneWGS84BBox() throws Exception {
194+
195+
GeoWebCacheDispatcher gwcd = mock(GeoWebCacheDispatcher.class);
196+
when(gwcd.getServletPrefix()).thenReturn(null);
197+
198+
service = new WMTSService(sb, tld,null , mock(RuntimeStats.class));
199+
200+
@SuppressWarnings("unchecked")
201+
Map<String, String> kvp = new CaseInsensitiveMap();
202+
kvp.put("service", "WMTS");
203+
kvp.put("version", "1.0.0");
204+
kvp.put("request", "GetCapabilities");
205+
206+
207+
HttpServletRequest req = mock(HttpServletRequest.class);
208+
MockHttpServletResponse resp = new MockHttpServletResponse();
209+
when(req.getCharacterEncoding()).thenReturn("UTF-8");
210+
when(req.getParameterMap()).thenReturn(kvp);
211+
212+
213+
{
214+
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale","EPSG:4326", "EPSG:900913");
215+
216+
TileLayer tileLayer = mockTileLayer("mockLayer", gridSetNames, Collections.<ParameterFilter>emptyList());
217+
TileLayer tileLayerUn = mockTileLayer("mockLayerUnadv", gridSetNames, Collections.<ParameterFilter>emptyList(), false);
218+
when(tld.getLayerList()).thenReturn(Arrays.asList(tileLayer, tileLayerUn));
219+
GridSubset wgs84Subset = mock(GridSubset.class);
220+
when(wgs84Subset.getOriginalExtent()).thenReturn(new BoundingBox(-42d, -24d, 40d, 50d));
221+
GridSubset googleSubset = mock(GridSubset.class);
222+
when(googleSubset.getOriginalExtent()).thenReturn(new BoundingBox(1_000_000d, 2_000_000d, 1_000_000d, 2_000_000d));
223+
when(tileLayer.getGridSubsetForSRS(SRS.getEPSG4326())).thenReturn(wgs84Subset);
224+
when(tileLayer.getGridSubsetForSRS(SRS.getEPSG900913())).thenReturn(googleSubset);
225+
}
226+
227+
Conveyor conv = service.getConveyor(req, resp);
228+
assertNotNull(conv);
229+
230+
final String layerName = conv.getLayerId();
231+
assertNull(layerName);
232+
233+
assertEquals(Conveyor.RequestHandler.SERVICE,conv.reqHandler);
234+
WMTSGetCapabilities wmsCap = new WMTSGetCapabilities(tld,gridsetBroker, conv.servletReq,"http://localhost:8080", "/service/wms", new NullURLMangler());
235+
wmsCap.writeResponse(conv.servletResp,mock(RuntimeStats.class));
236+
assertTrue(resp.containsHeader("content-disposition"));
237+
assertEquals("inline;filename=wmts-getcapabilities.xml", resp.getHeader("content-disposition"));
238+
239+
// System.out.println(resp.getOutputStreamContent());
240+
241+
String result = resp.getOutputStreamContent();
242+
243+
// Ensure the advertised Layer is contained and the unadvertised not
244+
assertTrue(result.contains("mockLayer"));
245+
assertFalse(result.contains("mockLayerUnadv"));
246+
247+
//Validator validator = new Validator(result);
248+
//validator.useXMLSchema(true);
249+
//validator.assertIsValid();
250+
251+
Document doc = XMLUnit.buildTestDocument(result);
252+
Map<String, String> namespaces = new HashMap<String, String>();
253+
namespaces.put("xlink", "http://www.w3.org/1999/xlink");
254+
namespaces.put("xsi", "http://www.w3.org/2001/XMLSchema-instance");
255+
namespaces.put("ows", "http://www.opengis.net/ows/1.1");
256+
namespaces.put("wmts", "http://www.opengis.net/wmts/1.0");
257+
XMLUnit.setXpathNamespaceContext(new SimpleNamespaceContext(namespaces));
258+
XpathEngine xpath = XMLUnit.newXpathEngine();
259+
260+
assertEquals("1", xpath.evaluate("count(//ows:WGS84BoundingBox)", doc));
261+
}
191262

192263
public void testGetCapUnboundedStyleFilter() throws Exception {
193264

0 commit comments

Comments
 (0)