/** @see TileLayerConfiguration#getTileLayerCount() */ @Deprecated public int getTileLayerCount() { return getLayerCount(); }
@Test public void testRemoveLayer() { try { config.removeLayer("nonExistent"); fail("Expected exception removing nonExistant layer"); } catch (Exception e) { } Set<String> tileLayerNames = config.getLayerNames(); for (String name : tileLayerNames) { int count = config.getLayerCount(); config.removeLayer(name); assertEquals(count - 1, config.getLayerCount()); } }
@Test public void testAddLayer() throws Exception { int count = config.getLayerCount(); TileLayer tl = createTestLayer("testLayer"); config.addLayer(tl); assertEquals(count + 1, config.getLayerCount()); assertSame(tl, config.getLayer("testLayer").get()); try { config.addLayer(tl); fail("Expected IllegalArgumentException on duplicate layer name"); } catch (IllegalArgumentException e) { assertEquals("Layer 'testLayer' already exists", e.getMessage()); } }
@Test public void testTemplate() throws Exception { assertTrue(configFile.delete()); config.setTemplate("/geowebcache_empty.xml"); config.setGridSetBroker(gridSetBroker); config.deinitialize(); config.reinitialize(); config.getLayerCount(); assertEquals(0, config.getLayerCount()); assertTrue(configFile.delete()); config.setTemplate("/geowebcache.xml"); config.setGridSetBroker(gridSetBroker); config.deinitialize(); config.reinitialize(); config.getLayerCount(); assertEquals(3, config.getLayerCount()); // WMTS CITE strict compliance should be deactivated assertThat(config.isWmtsCiteCompliant(), is(false)); }
@Test public void testWmtsCiteStrictComplianceIsActivated() throws Exception { // delete existing GWC configuration file assertThat(configFile.delete(), is(true)); // instantiate a new one based with strict CITE compliance activated config.setTemplate("/geowebcache_cite.xml"); config.setGridSetBroker(gridSetBroker); config.deinitialize(); config.reinitialize(); config.getLayerCount(); // CITE strict compliance should be activated for WMTS assertThat(config.isWmtsCiteCompliant(), is(true)); } }
@Test public void testDefaultToCacheDir() throws Exception { shouldLoadFrom(cacheDir); XMLConfiguration config = new XMLConfiguration(provider, storageFinder); config.setGridSetBroker(broker); config.afterPropertiesSet(); config.getLayerCount(); assertThat(config.getLayer(MARKED_LAYER), notNullValue()); }
@Test public void testSaveCurrentVersion() throws Exception { URL source = XMLConfiguration.class.getResource( XMLConfigurationBackwardsCompatibilityTest.GWC_125_CONFIG_FILE); configFile = new File(configDir, "geowebcache.xml"); FileUtils.copyURLToFile(source, configFile); gridSetBroker = new GridSetBroker(true, true); config = new XMLConfiguration(null, configDir.getAbsolutePath()); config.setGridSetBroker(gridSetBroker); config.afterPropertiesSet(); config.getLayerCount(); final String previousVersion = config.getVersion(); assertNotNull(previousVersion); // Do a modify without any changes to trigger a save; config.modifyLayer(config.getLayer(config.getLayerNames().iterator().next()).get()); final String currVersion = XMLConfiguration.getCurrentSchemaVersion(); assertNotNull(currVersion); assertFalse(previousVersion.equals(currVersion)); config = new XMLConfiguration(null, configDir.getAbsolutePath()); config.setGridSetBroker(gridSetBroker); config.afterPropertiesSet(); config.getLayerCount(); final String savedVersion = config.getVersion(); assertEquals(currVersion, savedVersion); }
@Test public void testOverrideWithProperty() throws Exception { shouldLoadFrom(configDir); shouldNotLoadFrom(cacheDir); gwcConfigDirProp.setValue(configDir.getCanonicalPath()); XMLConfiguration config = new XMLConfiguration(provider, storageFinder); config.setGridSetBroker(broker); config.afterPropertiesSet(); config.getLayerCount(); assertThat(config.getLayer(MARKED_LAYER), notNullValue()); }
@Test public void testOverrideWithPropertyRelative() throws Exception { shouldLoadFrom(configDir); shouldNotLoadFrom(cacheDir); gwcConfigDirProp.setValue(configDir.getName()); XMLConfiguration config = new XMLConfiguration(provider, storageFinder); config.setGridSetBroker(broker); config.afterPropertiesSet(); config.getLayerCount(); assertThat(config.getLayer(MARKED_LAYER), notNullValue()); }
@Test public void testModifyLayer() throws Exception { WMSLayer layer1 = createTestLayer("testLayer"); config.addLayer(layer1); int count = config.getLayerCount(); WMSLayer layer2 = createTestLayer("testLayer"); config.modifyLayer(layer2); assertEquals(count, config.getLayerCount()); assertSame(layer2, config.getLayer("testLayer").get()); layer1 = createTestLayer("another"); try { config.modifyLayer(layer1); fail("Expected NoSuchElementException"); } catch (NoSuchElementException e) { assertTrue(true); } }
config2.setGridSetBroker(new GridSetBroker(true, true)); config2.afterPropertiesSet(); config2.getLayerCount();
config2.setGridSetBroker(gridSetBroker2); config2.afterPropertiesSet(); config2.getLayerCount();
@Test public void testSave() throws Exception { for (String name : config.getLayerNames()) { int count = config.getLayerCount(); config.removeLayer(name); assertEquals(count - 1, config.getLayerCount()); config2.setGridSetBroker(gridSetBroker); config2.afterPropertiesSet(); config2.getLayerCount(); assertEquals(1, config2.getLayerCount()); assertThat(config2.getLayer("testLayer"), TestUtils.isPresent());