/** See GEOS-5003 */ @Test public void testNullsInDimensionAndTimeParameters() throws Exception { TileLayerInfoUtil.updateAcceptAllFloatParameterFilter(tileLayerInfo, "ELEVATION", true); TileLayerInfoUtil.updateAcceptAllRegExParameterFilter(tileLayerInfo, "TIME", true); tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo); GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); StringBuilder target = new StringBuilder(); boolean cachingPossible; request.setElevation(Arrays.asList((Object) null)); cachingPossible = mediator.isCachingPossible(tileLayer, request, target); assertTrue(cachingPossible); assertEquals(0, target.length()); request.setElevation(Collections.emptyList()); request.setTime(Arrays.asList((Object) null)); cachingPossible = mediator.isCachingPossible(tileLayer, request, target); assertTrue(cachingPossible); assertEquals(0, target.length()); }
@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"); }
@Test public void testDispatchGetMapNonMatchingParameterFilter() throws Exception { GetMapRequest request = new GetMapRequest(); @SuppressWarnings("unchecked") Map<String, String> rawKvp = new CaseInsensitiveMap(new HashMap<String, String>()); request.setRawKvp(rawKvp); rawKvp.put("layers", tileLayer.getName()); tileLayer.setEnabled(false); assertDispatchMismatch(request, "tile layer disabled"); tileLayer.setEnabled(true); assertTrue(layer.enabled()); request.setRemoteOwsURL(new URL("http://example.com")); assertDispatchMismatch(request, "remote OWS"); request.setRemoteOwsURL(null); request.setRemoteOwsType("WFS"); assertDispatchMismatch(request, "remote OWS"); request.setRemoteOwsType(null); request.setEnv(ImmutableMap.of("envVar", "envValue")); assertDispatchMismatch(request, "no parameter filter exists for ENV"); request.setEnv(null); request.setFormatOptions(ImmutableMap.of("optKey", "optVal")); assertDispatchMismatch(request, "no parameter filter exists for FORMAT_OPTIONS"); request.setFormatOptions(null); request.setAngle(45); assertDispatchMismatch(request, "no parameter filter exists for ANGLE"); request.setAngle(0); rawKvp.put("BGCOLOR", "0xAA0000"); assertDispatchMismatch(request, "no parameter filter exists for BGCOLOR"); rawKvp.remove("BGCOLOR"); request.setBuffer(10); assertDispatchMismatch(request, "no parameter filter exists for BUFFER"); request.setBuffer(0); request.setCQLFilter(Arrays.asList(CQL.toFilter("ATT = 1"))); assertDispatchMismatch(request, "no parameter filter exists for CQL_FILTER"); request.setCQLFilter(null); request.setElevation(10D); assertDispatchMismatch(request, "no parameter filter exists for ELEVATION"); request.setElevation(Collections.emptyList()); request.setFeatureId(Arrays.asList(new FeatureIdImpl("someid"))); assertDispatchMismatch(request, "no parameter filter exists for FEATUREID"); request.setFeatureId(null); request.setFilter(Arrays.asList(CQL.toFilter("ATT = 1"))); assertDispatchMismatch(request, "no parameter filter exists for FILTER"); request.setFilter(null); request.setPalette(PaletteManager.getPalette("SAFE")); assertDispatchMismatch(request, "no parameter filter exists for PALETTE"); request.setPalette(null); request.setStartIndex(10); assertDispatchMismatch(request, "no parameter filter exists for STARTINDEX"); request.setStartIndex(null); request.setMaxFeatures(1); assertDispatchMismatch(request, "no parameter filter exists for MAXFEATURES"); request.setMaxFeatures(null); request.setTime(Arrays.asList((Object) 1, (Object) 2)); assertDispatchMismatch(request, "no parameter filter exists for TIME"); request.setTime(Collections.emptyList()); List<Map<String, String>> viewParams = ImmutableList.of((Map<String, String>) ImmutableMap.of("paramKey", "paramVal")); request.setViewParams(viewParams); assertDispatchMismatch(request, "no parameter filter exists for VIEWPARAMS"); request.setViewParams(null); request.setFeatureVersion("@version"); assertDispatchMismatch(request, "no parameter filter exists for FEATUREVERSION"); request.setFeatureVersion(null); }