@Test public void testDispatchGetMapDoesntMatchTileCache() throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); rawKvp.put("layers", "more,than,one,layer"); assertDispatchMismatch(request, "more than one layer requested"); rawKvp.put("layers", "SomeNonCachedLayer"); when(tld.getTileLayer(eq("SomeNonCachedLayer"))) .thenThrow(new GeoWebCacheException("layer not found")); assertDispatchMismatch(request, "not a tile layer"); rawKvp.put("layers", tileLayer.getName()); request.setFormat("badFormat"); assertDispatchMismatch(request, "not a GWC supported format"); request.setFormat("image/gif"); assertDispatchMismatch(request, "no tile cache for requested format"); request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType()); request.setSRS("EPSG:4326"); request.setBbox(new Envelope(10, 10, 20, 20)); assertDispatchMismatch(request, "request does not align to grid"); request.setSRS("EPSG:23036"); assertDispatchMismatch(request, "no cache exists for requested CRS"); request.setSRS("badCRS"); assertDispatchMismatch(request, "exception occurred"); request.setSRS("EPSG:4326"); request.setWidth(128); request.setHeight(256); assertDispatchMismatch(request, "request does not align to grid"); request.setWidth(256); request.setHeight(128); assertDispatchMismatch(request, "request does not align to grid"); request.setSRS("EPSG:4326"); request.setWidth(256); request.setHeight(256); assertDispatchMismatch(request, "request does not align to grid"); }
@Test public void testTruncateByLayerAndStyle() throws Exception { String layerName = tileLayer.getName(); String styleName = "notACachedStyle"; mediator.truncateByLayerAndStyle(layerName, styleName); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); styleName = layer.getDefaultStyle().getName(); mediator.truncateByLayerAndStyle(layerName, styleName); int expected = tileLayer.getGridSubsets().size() * tileLayer.getMimeTypes().size(); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); }
private GeoServerTileLayer mockTileLayer(String layerName, List<String> gridSetNames) throws Exception { GeoServerTileLayer tileLayer = mock(GeoServerTileLayer.class); when(tld.layerExists(eq(layerName))).thenReturn(true); when(tld.getTileLayer(eq(layerName))).thenReturn(tileLayer); when(tileLayer.getName()).thenReturn(layerName); when(tileLayer.isEnabled()).thenReturn(true); final MimeType mimeType1 = MimeType.createFromFormat("image/png"); final MimeType mimeType2 = MimeType.createFromFormat("image/jpeg"); when(tileLayer.getMimeTypes()).thenReturn(ImmutableList.of(mimeType1, mimeType2)); Map<String, GridSubset> subsets = Maps.newHashMap(); Multimap<SRS, GridSubset> bySrs = LinkedHashMultimap.create(); GridSetBroker broker = gridSetBroker; for (String gsetName : gridSetNames) { GridSet gridSet = broker.get(gsetName); XMLGridSubset xmlGridSubset = new XMLGridSubset(); String gridSetName = gridSet.getName(); xmlGridSubset.setGridSetName(gridSetName); GridSubset gridSubSet = xmlGridSubset.getGridSubSet(broker); subsets.put(gsetName, gridSubSet); bySrs.put(gridSet.getSrs(), gridSubSet); when(tileLayer.getGridSubset(eq(gsetName))).thenReturn(gridSubSet); } for (SRS srs : bySrs.keySet()) { List<GridSubset> list = ImmutableList.copyOf(bySrs.get(srs)); when(tileLayer.getGridSubsetsForSRS(eq(srs))).thenReturn(list); } when(tileLayer.getGridSubsets()).thenReturn(subsets.keySet()); // sanity check for (String gsetName : gridSetNames) { assertTrue(tileLayer.getGridSubsets().contains(gsetName)); assertNotNull(tileLayer.getGridSubset(gsetName)); } return tileLayer; }
@Test public void testTruncateByBounds() throws Exception { String layerName = tileLayer.getName(); ReferencedEnvelope bounds; // bounds outside layer bounds (which are -180,0,0,90) bounds = new ReferencedEnvelope(10, 20, 10, 20, DefaultGeographicCRS.WGS84); BoundingBox layerBounds = tileLayer.getGridSubset("EPSG:4326").getGridSet().getOriginalExtent(); assertFalse(bounds.intersects(layerBounds.getMinX(), layerBounds.getMinY())); assertFalse(bounds.intersects(layerBounds.getMaxX(), layerBounds.getMaxY())); mediator.truncate(layerName, bounds); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); // bounds intersecting layer bounds bounds = new ReferencedEnvelope(-10, -10, 10, 10, DefaultGeographicCRS.WGS84); mediator.truncate(layerName, bounds); int numGridsets = tileLayer.getGridSubsets().size(); int numFormats = tileLayer.getMimeTypes().size(); int numStyles = 1 /* default */ + tileLayer.getInfo().cachedStyles().size(); final int expected = numGridsets * numFormats * numStyles; verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = bounds.transform(CRS.decode("EPSG:900913"), true); mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:2083")); // Terra del Fuego mediator.truncate(layerName, bounds); verify(tileBreeder, never()).dispatchTasks(any(GWCTask[].class)); reset(tileBreeder); bounds = mediator.getAreaOfValidity(CRS.decode("EPSG:26986")); // Massachussets mediator.truncate(layerName, bounds); verify(tileBreeder, times(expected)).dispatchTasks(any(GWCTask[].class)); }