@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"); }
private void testMultipleCrsMatchingGridSubsets( final String srs, final String expectedGridset, long[] tileIndex) throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS(srs); request.setWidth(256); request.setHeight(256); rawKvp.put("layers", "mockLayer"); List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326"); tileLayer = mockTileLayer("mockLayer", gridSetNames); // make the request match a tile in the expected gridset BoundingBox bounds; bounds = tileLayer.getGridSubset(expectedGridset).boundsFromIndex(tileIndex); Envelope reqBbox = new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); request.setBbox(reqBbox); ArgumentCaptor<ConveyorTile> captor = ArgumentCaptor.forClass(ConveyorTile.class); StringBuilder errors = new StringBuilder(); mediator.dispatch(request, errors); assertTrue(errors.toString(), errors.length() == 0); verify(tileLayer, times(1)).getTile(captor.capture()); ConveyorTile tileRequest = captor.getValue(); assertEquals(expectedGridset, tileRequest.getGridSetId()); assertEquals("image/png", tileRequest.getMimeType().getMimeType()); assertTrue( "Expected " + Arrays.toString(tileIndex) + " got " + Arrays.toString(tileRequest.getTileIndex()), Arrays.equals(tileIndex, tileRequest.getTileIndex())); }
@Test public void testDispatchGetMapWithMatchingParameterFilters() throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); request.setFormat("image/png"); request.setSRS("EPSG:900913"); request.setWidth(256); request.setHeight(256); rawKvp.put("layers", tileLayer.getName()); // tileLayer = mockTileLayer("mockLayer", ImmutableList.of("EPSG:900913", "EPSG:4326")); // make the request match a tile in the expected gridset BoundingBox bounds; bounds = tileLayer.getGridSubset("EPSG:900913").boundsFromIndex(new long[] {0, 0, 1}); Envelope reqBbox = new Envelope(bounds.getMinX(), bounds.getMaxX(), bounds.getMinY(), bounds.getMaxY()); request.setBbox(reqBbox); assertTrue(tileLayer.getInfo().cachedStyles().size() > 0); for (String style : tileLayer.getInfo().cachedStyles()) { String rawKvpParamName = "styles"; String rawKvpParamValue = style; testParameterFilter(request, rawKvp, rawKvpParamName, rawKvpParamValue); } request.setEnv(ImmutableMap.of("envKey", "envValue")); updateStringParameterFilter( tileLayerInfo, "ENV", true, "def:devVal", "envKey:envValue", "envKey2:envValue2"); testParameterFilter(request, rawKvp, "env", "envKey:envValue"); updateAcceptAllFloatParameterFilter(tileLayerInfo, "ANGLE", true); request.setAngle(60); testParameterFilter(request, rawKvp, "angle", "60.0"); request.setAngle(61.1); testParameterFilter(request, rawKvp, "angle", "61.1"); }