WmsLayer extends RenderableLayer { public void setConfiguration(Sector sector, double metersPerPixel, WmsLayerConfig config) { if (sector == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "WmsLayer", "setConfiguration", "missingSector")); } if (metersPerPixel <= 0) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "WmsLayer", "setConfiguration", "invalidResolution")); } if (config == null) { throw new IllegalArgumentException( Logger.logMessage(Logger.ERROR, "WmsLayer", "setConfiguration", "missingConfig")); } double radiansPerPixel = metersPerPixel / WorldWind.WGS84_SEMI_MAJOR_AXIS; LevelSetConfig levelsConfig = new LevelSetConfig(); levelsConfig.sector.set(sector); levelsConfig.numLevels = levelsConfig.numLevelsForResolution(radiansPerPixel); TiledSurfaceImage surfaceImage = (TiledSurfaceImage) this.getRenderable(0); surfaceImage.setLevelSet(new LevelSet(levelsConfig)); surfaceImage.setTileFactory(new WmsTileFactory(config)); } WmsLayer();  WmsLayer(Sector sector, double metersPerPixel, WmsLayerConfig config);  WmsLayer(Sector sector, Globe globe, double metersPerPixel, WmsLayerConfig config); void setConfiguration(Sector sector, double metersPerPixel, WmsLayerConfig config); void setConfiguration(Sector sector, Globe globe, double metersPerPixel, WmsLayerConfig config);  }
@Test public void testSetConfiguration_ThreeParameter_NullParameters() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, metersPerPixel, initialWmsLayerConfig); try { wmsLayer.setConfiguration(null, metersPerPixel, null); fail("provided null arguments"); } catch (IllegalArgumentException ex) { assertNotNull("null exception thrown", ex); } try { wmsLayer.setConfiguration(initialSector, -metersPerPixel, null); fail("provided invalid argument"); } catch (IllegalArgumentException ex) { assertNotNull("null exception thrown", ex); } try { wmsLayer.setConfiguration(initialSector, metersPerPixel, null); fail("provided null arguments"); } catch (IllegalArgumentException ex) { assertNotNull("null exception thrown", ex); } }
@Test public void testSetConfiguration_ThreeParameter_SectorUpdate() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, metersPerPixel, initialWmsLayerConfig); double alternativeLatMin = -45.0; double alternativeLonMin = 50.0; double alternativeDeltaLat = 5.0; double alternativeDeltaLon = 2.0; Sector alternativeSector = new Sector(alternativeLatMin, alternativeLonMin, alternativeDeltaLat, alternativeDeltaLon); wmsLayer.setConfiguration(alternativeSector, metersPerPixel, initialWmsLayerConfig); Sector sector = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().sector; assertEquals("sector updated", alternativeSector, sector); }
@Test public void testSetConfiguration_ThreeParameter_MetersPerPixelUpdate() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, metersPerPixel, initialWmsLayerConfig); double alternativeMetersPerPixel = 10.0; int originalNumberOfLevels = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); wmsLayer.setConfiguration(initialSector, alternativeMetersPerPixel, initialWmsLayerConfig); int numberOfLevels = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); assertFalse("levels updated", originalNumberOfLevels == numberOfLevels); }
@Test public void testSetConfiguration_FourParameter_NullParameters() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; double notionalGlobeRadius = 3000000.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); Globe initialGlobe = PowerMockito.mock(Globe.class); PowerMockito.when(initialGlobe.getEquatorialRadius()).thenReturn(notionalGlobeRadius); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, initialGlobe, metersPerPixel, initialWmsLayerConfig); try { wmsLayer.setConfiguration(null, null, metersPerPixel, null); fail("provided null arguments"); } catch (IllegalArgumentException ex) { assertNotNull(ex); } try { wmsLayer.setConfiguration(initialSector, null, metersPerPixel, null); fail("provided null arguments"); } catch (IllegalArgumentException ex) { assertNotNull(ex); } try { wmsLayer.setConfiguration(initialSector, initialGlobe, -metersPerPixel, null); fail("provided invalid argument"); } catch (IllegalArgumentException ex) { assertNotNull(ex); } try { wmsLayer.setConfiguration(initialSector, initialGlobe, metersPerPixel, null); fail("provided null arguments"); } catch (IllegalArgumentException ex) { assertNotNull(ex); } }
@Test public void testSetConfiguration_FourParameter_SectorUpdate() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; double notionalGlobeRadius = 3000000.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); Globe initialGlobe = PowerMockito.mock(Globe.class); PowerMockito.when(initialGlobe.getEquatorialRadius()).thenReturn(notionalGlobeRadius); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, initialGlobe, metersPerPixel, initialWmsLayerConfig); double alternativeLatMin = -45.0; double alternativeLonMin = 50.0; double alternativeDeltaLat = 5.0; double alternativeDeltaLon = 2.0; Sector alternativeSector = new Sector(alternativeLatMin, alternativeLonMin, alternativeDeltaLat, alternativeDeltaLon); wmsLayer.setConfiguration(alternativeSector, initialGlobe, metersPerPixel, initialWmsLayerConfig); Sector sector = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().sector; assertEquals("sector updated", alternativeSector, sector); }
@Test public void testSetConfiguration_FourParameter_GlobeUpdate() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; double notionalGlobeRadius = 3000000.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); Globe initialGlobe = PowerMockito.mock(Globe.class); PowerMockito.when(initialGlobe.getEquatorialRadius()).thenReturn(notionalGlobeRadius); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, initialGlobe, metersPerPixel, initialWmsLayerConfig); int initialLayers = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); Globe alternativeGlobe = PowerMockito.mock(Globe.class); PowerMockito.when(alternativeGlobe.getEquatorialRadius()).thenReturn(2 * notionalGlobeRadius); wmsLayer.setConfiguration(initialSector, alternativeGlobe, metersPerPixel, initialWmsLayerConfig); int numberOfLevels = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); assertFalse("layer levels updated by globe object change", initialLayers == numberOfLevels); }
@Test public void testSetConfiguration_FourParameter_MetersPerPixelUpdate() { double minLat = 10.0; double deltaLat = 1.0; double minLon = -95.0; double deltaLon = 2.0; double notionalGlobeRadius = 3000000.0; Sector initialSector = new Sector(minLat, minLon, deltaLat, deltaLon); Globe initialGlobe = PowerMockito.mock(Globe.class); PowerMockito.when(initialGlobe.getEquatorialRadius()).thenReturn(notionalGlobeRadius); String initialNotionalServiceAddress = "notionalServiceAddress"; String initialNotionalLayerList = "notionalLayerList"; WmsLayerConfig initialWmsLayerConfig = new WmsLayerConfig(initialNotionalServiceAddress, initialNotionalLayerList); double metersPerPixel = 0.5; WmsLayer wmsLayer = new WmsLayer(initialSector, initialGlobe, metersPerPixel, initialWmsLayerConfig); double alternativeMetersPerPixel = 10.0; int originalNumberOfLevels = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); wmsLayer.setConfiguration(initialSector, initialGlobe, alternativeMetersPerPixel, initialWmsLayerConfig); int numberOfLevels = ((TiledSurfaceImage) wmsLayer.getRenderable(0)).getLevelSet().numLevels(); assertFalse("levels updated", originalNumberOfLevels == numberOfLevels); }