/** * This is a READ ONLY TEST so we can use one time setup */ public static Test suite() { return new OneTimeTestSetup(new GWCIntegrationTest()); }
/** * If direct WMS integration is enabled, a GetMap requests that hits the regular WMS but matches * a gwc tile should return with the proper {@code geowebcache-tile-index} HTTP response header. */ public void testDirectWMSIntegration() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); String request; MockHttpServletResponse response; request = buildGetMap(true, layerName, "EPSG:4326", null); response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertNull(response.getHeader("geowebcache-tile-index")); request = request + "&tiled=true"; response = getAsServletResponse(request); assertEquals(200, response.getErrorCode()); assertEquals("image/png", response.getContentType()); }
public void testPngIntegration() throws Exception { String layerId = getLayerId(MockData.BASIC_POLYGONS); MockHttpServletResponse sr = getAsServletResponse("gwc/service/wmts?request=GetTile&layer=" + layerId + "&format=image/png&tilematrixset=EPSG:4326&tilematrix=EPSG:4326:0&tilerow=0&tilecol=0"); assertEquals(200, sr.getErrorCode()); assertEquals("image/png", sr.getContentType()); }
public void testReloadConfiguration() throws Exception { String path = "/gwc/rest/reload"; String content = "reload_configuration=1"; String contentType = "application/x-www-form-urlencoded"; MockHttpServletResponse response = postAsServletResponse(path, content, contentType); assertEquals(200, response.getStatusCode()); }
public void testDirectWMSIntegrationResponseHeaders() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); String request = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertEquals(layerName, response.getHeader("geowebcache-layer")); assertEquals("[0, 0, 0]", response.getHeader("geowebcache-tile-index")); assertEquals("-180.0,-90.0,0.0,90.0", response.getHeader("geowebcache-tile-bounds")); assertEquals("EPSG:4326", response.getHeader("geowebcache-gridset")); assertEquals("EPSG:4326", response.getHeader("geowebcache-crs")); }
/** * See GEOS-5092, check server startup is not hurt by a tile layer out of sync (say someone * manually removed the GeoServer layer) */ public void testMissingGeoServerLayerAtStartUp() throws Exception { Catalog catalog = getCatalog(); GWC mediator = GWC.get(); final String layerName = getLayerId(BASIC_POLYGONS); LayerInfo layerInfo = catalog.getLayerByName(layerName); assertNotNull(layerInfo); TileLayer tileLayer = mediator.getTileLayerByName(layerName); assertNotNull(tileLayer); assertTrue(tileLayer.isEnabled()); MockData testData = getTestData(); testData.removeFeatureType(BASIC_POLYGONS); getGeoServer().reload(); assertNull(catalog.getLayerByName(layerName)); CatalogConfiguration config = GeoServerExtensions.bean(CatalogConfiguration.class); assertNull(config.getTileLayer(layerName)); try { mediator.getTileLayerByName(layerName); fail("Expected IAE"); } catch (IllegalArgumentException e) { assertTrue(true); } }
public void testDirectWMSIntegrationWithVirtualServices() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final String localName = BASIC_POLYGONS.getLocalPart(); final TileLayer tileLayer = gwc.getTileLayerByName(qualifiedName); assertNotNull(tileLayer); boolean directWMSIntegrationEndpoint = true; String request = MockData.CITE_PREFIX + "/" + buildGetMap(directWMSIntegrationEndpoint, localName, "EPSG:4326", null, tileLayer) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); assertEquals(qualifiedName, response.getHeader("geowebcache-layer")); }
public void testDirectWMSIntegrationIfModifiedSinceSupport() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(path); assertEquals(200, response.getStatusCode()); assertEquals("image/png", response.getContentType()); String lastModifiedHeader = response.getHeader("Last-Modified"); assertNotNull(lastModifiedHeader); Date lastModified = DateUtil.parseDate(lastModifiedHeader); MockHttpServletRequest httpReq = createRequest(path); httpReq.setMethod("GET"); httpReq.setBodyContent(new byte[] {}); httpReq.setHeader("If-Modified-Since", lastModifiedHeader); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); // set the If-Modified-Since header to some point in the past of the last modified value Date past = new Date(lastModified.getTime() - 5000); String ifModifiedSince = DateUtil.formatDate(past); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_OK, response.getErrorCode()); Date future = new Date(lastModified.getTime() + 5000); ifModifiedSince = DateUtil.formatDate(future); httpReq.setHeader("If-Modified-Since", ifModifiedSince); response = dispatch(httpReq, "UTF-8"); assertEquals(HttpServletResponse.SC_NOT_MODIFIED, response.getErrorCode()); }
public void testBasicIntegration() throws Exception { Catalog cat = getCatalog(); TileLayerDispatcher tld = GeoWebCacheExtensions.bean(TileLayerDispatcher.class); assertNotNull(tld); assertNotNull(gridSetBroker); assertTrue(foundLakes); assertTrue(epsg4326.getGridSetBounds().equals( new BoundingBox(-180.0, -90.0, 180.0, 90.0))); String mime = tl.getMimeTypes().get(1).getMimeType(); assertTrue(mime.startsWith("image/") || mime.startsWith("application/vnd.google-earth.kml+xml")); assertTrue(foudAGF); assertEquals(layerName, tl.getName()); assertNull(cat.getLayerByName(tl.getName())); fail("Layer should not exist"); } catch (GeoWebCacheException gwce) { assertTrue(true);
/** * Commented out for the moment, we need a new release of GWC public void testPreserveHeaders() throws Exception { MockHttpServletResponse response = getAsServletResponse("gwc/service/wms?service=wms&version=1.1.0&request=GetCapabilities"); assertEquals("application/vnd.ogc.wms_xml", response.getContentType()); assertEquals("inline;filename=wms-getcapabilities.xml", response.getHeader("content-disposition")); } */ public void testSaveConfig() throws Exception { GWCConfig config = GWC.get().getConfig(); // set a large gutter config.setGutter(100); // save the config GWC.get().saveConfig(config); // force a reload getGeoServer().reload(); // grab the config, make sure it was saved as expected assertEquals(100, GWC.get().getConfig().getGutter()); } }
private String buildGetMap(final boolean directWMSIntegrationEndpoint, final String layerName, final String gridsetId, String styles) { final GWC gwc = GWC.get(); final TileLayer tileLayer = gwc.getTileLayerByName(layerName); return buildGetMap(directWMSIntegrationEndpoint, layerName, gridsetId, styles, tileLayer); }
public void testDirectWMSIntegrationWithVirtualServicesHiddenLayer() throws Exception { /* * Nothing special needs to be done at the GWC integration level for this to work. The hard * work should already be done by WMSWorkspaceQualifier so that when the request hits GWC * the layer name is already qualified */ final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final String localName = BASIC_POLYGONS.getLocalPart(); final TileLayer tileLayer = gwc.getTileLayerByName(qualifiedName); assertNotNull(tileLayer); boolean directWMSIntegrationEndpoint = true; String request = MockData.CDF_PREFIX // asking /geoserver/cdf/wms? for cite:BasicPolygons + "/" + buildGetMap(directWMSIntegrationEndpoint, localName, "EPSG:4326", null, tileLayer) + "&tiled=true"; MockHttpServletResponse response = getAsServletResponse(request); assertEquals(200, response.getStatusCode()); assertTrue(response.getContentType(), response.getContentType().startsWith("application/vnd.ogc.se_xml")); assertTrue(response.getOutputStreamContent(), response.getOutputStreamContent() .contains("Could not find layer cdf:BasicPolygons")); }
public void testDirectWMSIntegrationMaxAge() throws Exception { final GWC gwc = GWC.get(); gwc.getConfig().setDirectWMSIntegrationEnabled(true); final String layerName = BASIC_POLYGONS.getPrefix() + ":" + BASIC_POLYGONS.getLocalPart(); final String path = buildGetMap(true, layerName, "EPSG:4326", null) + "&tiled=true"; final String qualifiedName = super.getLayerId(BASIC_POLYGONS); final GeoServerTileLayer tileLayer = (GeoServerTileLayer) gwc.getTileLayerByName(qualifiedName); tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", "true"); tileLayer.getLayerInfo().getResource().getMetadata().put("cacheAgeMax", 3456); MockHttpServletResponse response = getAsServletResponse(path); String cacheControl = response.getHeader("Cache-Control"); assertEquals("max-age=3456", cacheControl); assertNotNull(response.getHeader("Last-Modified")); tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", "false"); response = getAsServletResponse(path); cacheControl = response.getHeader("Cache-Control"); assertEquals("no-cache", cacheControl); // make sure a boolean is handled, too - see comment in CachingWebMapService tileLayer.getLayerInfo().getResource().getMetadata().put("cachingEnabled", Boolean.FALSE); response = getAsServletResponse(path); cacheControl = response.getHeader("Cache-Control"); assertEquals("no-cache", cacheControl); }