public void testAddGridset() throws Exception { try { mediator.addGridSet(null); fail(); } catch (NullPointerException e) { assertTrue(true); } GridSet gset = mock(GridSet.class); GridSet gset2 = mock(GridSet.class); doThrow(new IOException("fake")).when(tld).addGridSet(same(gset)); try { mediator.addGridSet(gset); fail(); } catch (IOException e) { assertEquals("fake", e.getMessage()); } mediator.addGridSet(gset2); verify(tld, times(1)).addGridSet(same(gset2)); }
public void testIsInternalGridset() { Set<String> embeddedNames = gridSetBroker.getEmbeddedNames(); for (String name : embeddedNames) { assertTrue(mediator.isInternalGridSet(name)); } assertFalse(mediator.isInternalGridSet("somethingelse")); }
private void assertDispatchMismatch(GetMapRequest request, String expectedReason) { StringBuilder target = new StringBuilder(); assertNull(mediator.dispatch(request, target)); assertTrue("mismatch reason '" + target + "' does not contain '" + expectedReason + "'", target.toString().contains(expectedReason)); }
private void testParameterFilter(GetMapRequest request, Map<String, String> rawKvp, String rawKvpParamName, String rawKvpParamValue) { // set up raw kvp rawKvp.put(rawKvpParamName, rawKvpParamValue); StringBuilder errors = new StringBuilder(); ConveyorTile tileRequest = mediator.prepareRequest(tileLayer, request, errors); assertTrue(errors.toString(), errors.length() == 0); Map<String, String> fullParameters = tileRequest.getFullParameters(); assertEquals(fullParameters.toString(), rawKvpParamValue, fullParameters.get(rawKvpParamName.toUpperCase())); } }
public void testModifyGridsetPreconditions() throws Exception { GridSet oldGridset = gridSetBroker.get("EPSG:4326"); try { mediator.modifyGridSet(null, oldGridset); fail(); } catch (NullPointerException e) { assertTrue(true); } try { mediator.modifyGridSet("oldname", null); fail(); } catch (NullPointerException e) { assertTrue(true); } try { mediator.modifyGridSet("wrongOldName", oldGridset); fail(); } catch (IllegalArgumentException e) { assertTrue(e.getMessage().contains("does not exist")); } }
assertFalse(insaneDefaults.isSane()); try { mediator.autoConfigureLayers(Arrays.asList(tileLayer.getName()), insaneDefaults); } catch (IllegalArgumentException e) { assertTrue(true); fail("expected IAE, layer exists"); } catch (IllegalArgumentException e) { assertTrue(true); GeoServerTileLayerInfo actual2 = addCaptor.getAllValues().get(1).getInfo(); assertEquals(expected1, actual1); assertEquals(expected2, actual2);
public void testModifyGridsetNoNeedToTruncate() throws Exception { final String oldName = "EPSG:4326"; final String newName = "MyEPSG:4326"; final GridSet oldGridset = gridSetBroker.get(oldName); final GridSet newGridset; { XMLGridSet xmlGridSet = new XMLGridSet(oldGridset); xmlGridSet.setName(newName); newGridset = xmlGridSet.makeGridSet(); } XMLConfiguration xmlConfig = mock(XMLConfiguration.class); mediator = spy(mediator); when(mediator.getXmlConfiguration()).thenReturn(xmlConfig); assertNotNull(tileLayer.getGridSubset(oldName)); assertNotNull(tileLayerGroup.getGridSubset(oldName)); when(tld.getConfiguration(same(tileLayer))).thenReturn(config); when(tld.getConfiguration(same(tileLayerGroup))).thenReturn(config); mediator.modifyGridSet(oldName, newGridset); assertNull(tileLayer.getGridSubset(oldName)); assertNull(tileLayerGroup.getGridSubset(oldName)); assertNotNull(tileLayer.getGridSubset(newName)); assertNotNull(tileLayerGroup.getGridSubset(newName)); verify(xmlConfig, times(1)).removeGridset(eq(oldName)); verify(xmlConfig, times(1)).addOrReplaceGridSet(eq(new XMLGridSet(newGridset))); verify(xmlConfig, times(1)).save(); assertNull(gridSetBroker.get(oldName)); assertEquals(newGridset, gridSetBroker.get(newName)); verify(config, times(1)).save(); }
List<String> gridSetNames = Arrays.asList("GlobalCRS84Pixel", "GlobalCRS84Scale", "EPSG:4326"); tileLayer = mockTileLayer("mockLayer", gridSetNames); assertTrue(errors.toString(), errors.length() == 0); assertEquals(expectedGridset, tileRequest.getGridSetId()); assertEquals("image/png", tileRequest.getMimeType().getMimeType()); assertTrue( "Expected " + Arrays.toString(tileIndex) + " got " + Arrays.toString(tileRequest.getTileIndex()),
assertTrue(tileLayer.getGridSubsets().contains(gsetName)); assertNotNull(tileLayer.getGridSubset(gsetName));
@Override protected void setUp() throws Exception { catalog = mock(Catalog.class); layer = mockLayer("testLayer", new String[]{"style1", "style2"}, LayerInfo.Type.RASTER); layerGroup = mockGroup("testGroup", layer); mockCatalog(); defaults = GWCConfig.getOldDefaults(); gwcConfigPersister = mock(GWCConfigPersister.class); when(gwcConfigPersister.getConfig()).thenReturn(defaults); storageBroker = mock(StorageBroker.class); gridSetBroker = new GridSetBroker(true, true); tileLayerInfo = TileLayerInfoUtil.loadOrCreate(layer, defaults); tileLayerGroupInfo = TileLayerInfoUtil.loadOrCreate(layerGroup, defaults); tileLayer = new GeoServerTileLayer(layer, gridSetBroker, tileLayerInfo); tileLayerGroup = new GeoServerTileLayer(layerGroup, gridSetBroker, tileLayerGroupInfo); tld = mock(TileLayerDispatcher.class); mockTileLayerDispatcher(); config = mock(Configuration.class); tileBreeder = mock(TileBreeder.class); quotaStore = mock(QuotaStore.class); diskQuotaMonitor = mock(DiskQuotaMonitor.class); owsDispatcher = mock(Dispatcher.class); mediator = new GWC(gwcConfigPersister, storageBroker, tld, gridSetBroker, tileBreeder, quotaStore, diskQuotaMonitor, owsDispatcher, catalog); GWC.set(mediator); }
assertDispatchMismatch(request, "tile layer disabled"); assertTrue(layer.enabled()); assertDispatchMismatch(request, "remote OWS"); request.setRemoteOwsURL(null); assertDispatchMismatch(request, "remote OWS"); request.setRemoteOwsType(null); assertDispatchMismatch(request, "no parameter filter exists for ENV"); request.setEnv(null); assertDispatchMismatch(request, "no parameter filter exists for FORMAT_OPTIONS"); request.setFormatOptions(null); assertDispatchMismatch(request, "no parameter filter exists for ANGLE"); request.setAngle(0); assertDispatchMismatch(request, "no parameter filter exists for BGCOLOR"); rawKvp.remove("BGCOLOR"); assertDispatchMismatch(request, "no parameter filter exists for BUFFER"); request.setBuffer(0); assertDispatchMismatch(request, "no parameter filter exists for CQL_FILTER"); request.setCQLFilter(null); assertDispatchMismatch(request, "no parameter filter exists for ELEVATION");
request.setBbox(reqBbox); assertTrue(tileLayer.getInfo().cachedStyles().size() > 0); String rawKvpParamValue = style; testParameterFilter(request, rawKvp, rawKvpParamName, rawKvpParamValue); updateStringParameterFilter(tileLayerInfo, "ENV", true, "def:devVal", "envKey:envValue", "envKey2:envValue2"); testParameterFilter(request, rawKvp, "env", "envKey:envValue"); testParameterFilter(request, rawKvp, "angle", "60.0"); testParameterFilter(request, rawKvp, "angle", "61.1");
public void testDestroy() throws Exception { mediator.destroy(); ArgumentCaptor<CatalogListener> captor = ArgumentCaptor.forClass(CatalogListener.class); verify(catalog, times(2)).removeListener(captor.capture()); for (CatalogListener captured : captor.getAllValues()) { assertTrue(captured instanceof CatalogLayerEventListener || captured instanceof CatalogStyleChangeListener); } }
public void testReloadAndLayerRemovedExternally() throws Exception { final String removedLayer = tileLayer.getName(); final String remainingLayer = tileLayerGroup.getName(); final Set<String> layerNames = Sets.newHashSet(removedLayer, remainingLayer); when(tld.getLayerNames()).thenReturn(layerNames); doAnswer(new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { layerNames.remove(removedLayer); return null; } }).when(tld).reInit(); ArgumentCaptor<String> argCaptor = ArgumentCaptor.forClass(String.class); mediator = spy(mediator); doReturn(true).when(mediator).layerRemoved(argCaptor.capture()); mediator.reload(); verify(tld, times(1)).reInit(); assertEquals(1, argCaptor.getAllValues().size()); assertEquals(removedLayer, argCaptor.getValue()); }
assertDispatchMismatch(request, "more than one layer requested"); assertDispatchMismatch(request, "not a tile layer"); assertDispatchMismatch(request, "not a GWC supported format"); assertDispatchMismatch(request, "no tile cache for requested format"); request.setFormat(tileLayer.getMimeTypes().get(0).getMimeType()); assertDispatchMismatch(request, "request does not align to grid"); assertDispatchMismatch(request, "no cache exists for requested CRS"); assertDispatchMismatch(request, "exception occurred"); request.setSRS("EPSG:4326"); assertDispatchMismatch(request, "request does not align to grid"); assertDispatchMismatch(request, "request does not align to grid"); assertDispatchMismatch(request, "request does not align to grid");
.getOriginalExtent(); assertFalse(bounds.intersects(layerBounds.getMinX(), layerBounds.getMinY())); assertFalse(bounds.intersects(layerBounds.getMaxX(), layerBounds.getMaxY()));
public void testLayerRenamed() throws Exception { mediator.layerRenamed("old", "new"); verify(storageBroker, times(1)).rename(eq("old"), eq("new")); doThrow(new StorageException("target directory already exists")).when(storageBroker) .rename(eq("old"), eq("new")); try { mediator.layerRenamed("old", "new"); fail("Expected RTE"); } catch (RuntimeException e) { assertTrue(e.getCause() instanceof StorageException); } }
/** * See GEOS-5003 */ 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()); }
public void testRemoveTileLayers() throws Exception { try { mediator.removeTileLayers(null); } catch (NullPointerException e) { assertTrue(true); } when(tld.removeLayer(eq(tileLayer.getName()))).thenReturn(config); when(tld.removeLayer(eq(tileLayerGroup.getName()))).thenReturn(config); List<String> layerNames = Arrays.asList(tileLayer.getName(), tileLayerGroup.getName()); mediator.removeTileLayers(layerNames); verify(tld, times(1)).removeLayer(eq(tileLayer.getName())); verify(tld, times(1)).removeLayer(eq(tileLayerGroup.getName())); verify(config, times(1)).save(); }
public void testReload() throws Exception { mediator.reload(); verify(tld, times(1)).reInit(); doThrow(new RuntimeException("fake")).when(tld).reInit(); try { mediator.reload(); fail("Expected RTE"); } catch (RuntimeException e) { assertTrue(true); } }