private WebMap dispatchGetMap(final ConveyorTile tile, final MetaTile metaTile) throws Exception { Map<String, String> params = buildGetMap(tile, metaTile); WebMap map; try { HttpServletRequest actualRequest = tile.servletReq; Cookie[] cookies = actualRequest == null ? null : actualRequest.getCookies(); GWC.get().dispatchOwsRequest(params, cookies); map = WEB_MAP.get(); if (!(map instanceof WebMap)) { throw new IllegalStateException("Expected: RenderedImageMap, got " + map); } } finally { WEB_MAP.remove(); } return map; }
private RenderedImageMap dispatchGetMap(final ConveyorTile tile, final MetaTile metaTile) throws Exception { Map<String, String> params = buildGetMap(tile, metaTile); WebMap map; try { HttpServletRequest actualRequest = tile.servletReq; Cookie[] cookies = actualRequest == null ? null : actualRequest.getCookies(); GWC.get().dispatchOwsRequest(params, cookies); map = WEB_MAP.get(); if (!(map instanceof RenderedImageMap)) { throw new IllegalStateException("Expected: RenderedImageMap, got " + map); } } finally { WEB_MAP.remove(); } return (RenderedImageMap) map; }
/** * @see org.geowebcache.layer.TileLayer#getFeatureInfo * @see GWC#dispatchOwsRequest */ @Override public Resource getFeatureInfo(ConveyorTile convTile, BoundingBox bbox, int height, int width, int x, int y) throws GeoWebCacheException { Map<String, String> params = buildGetFeatureInfo(convTile, bbox, height, width, x, y); Resource response; try { response = GWC.get().dispatchOwsRequest(params, (Cookie[]) null); } catch (Exception e) { throw new GeoWebCacheException(e); } return response; }
/** * @see org.geowebcache.layer.TileLayer#getFeatureInfo * @see GWC#dispatchOwsRequest */ @Override public Resource getFeatureInfo( ConveyorTile convTile, BoundingBox bbox, int height, int width, int x, int y) throws GeoWebCacheException { Map<String, String> params = buildGetFeatureInfo(convTile, bbox, height, width, x, y); Resource response; try { response = GWC.get().dispatchOwsRequest(params, (Cookie[]) null); } catch (Exception e) { throw new GeoWebCacheException(e); } return response; }
Mockito.when(mockGWC.dispatchOwsRequest(argument.capture(), (Cookie[]) anyObject())) .thenReturn(mockResult); assertEquals("50", capturedParams.get("Y")); verify(mockGWC, times(1)).dispatchOwsRequest((Map) anyObject(), (Cookie[]) anyObject()); when(mockGWC.dispatchOwsRequest((Map) anyObject(), (Cookie[]) anyObject())).thenThrow( new RuntimeException("mock exception")); try {
@SuppressWarnings({ "unchecked", "rawtypes" }) public void testGetTile() throws Exception { Resource mockResult = mock(Resource.class); ArgumentCaptor<Map> argument = ArgumentCaptor.forClass(Map.class); Mockito.when(mockGWC.dispatchOwsRequest(argument.capture(), (Cookie[]) anyObject())) .thenReturn(mockResult); BufferedImage image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB); RenderedImageMap fakeDispatchedMap = new RenderedImageMap(new WMSMapContent(), image, "image/png"); RenderedImageMapResponse fakeResponseEncoder = mock(RenderedImageMapResponse.class); MimeType mimeType = MimeType.createFromFormat("image/png"); when(mockGWC.getResponseEncoder(eq(mimeType), (RenderedImageMap) anyObject())).thenReturn( fakeResponseEncoder); StorageBroker storageBroker = mock(StorageBroker.class); when(storageBroker.get((TileObject) anyObject())).thenReturn(false); layerInfoTileLayer = new GeoServerTileLayer(layerInfo, defaults, gridSetBroker); MockHttpServletRequest servletReq = new MockHttpServletRequest(); HttpServletResponse servletResp = new MockHttpServletResponse(); long[] tileIndex = { 0, 0, 0 }; ConveyorTile tile = new ConveyorTile(storageBroker, layerInfoTileLayer.getName(), "EPSG:4326", tileIndex, mimeType, null, servletReq, servletResp); GeoServerTileLayer.WEB_MAP.set(fakeDispatchedMap); ConveyorTile returned = layerInfoTileLayer.getTile(tile); assertNotNull(returned); assertNotNull(returned.getBlob()); assertEquals(CacheResult.MISS, returned.getCacheResult()); assertEquals(200, returned.getStatus()); verify(storageBroker, atLeastOnce()).get((TileObject) anyObject()); verify(mockGWC, times(1)).getResponseEncoder(eq(mimeType), isA(RenderedImageMap.class)); }