Refine search
@Test public void testStyleWithExternalEntities() throws Exception { StyleInfo si = getCatalog().getStyleByName(EXTERNAL_ENTITIES); try { si.getStyle(); fail("Should have failed with a parse error"); } catch (Exception e) { String message = e.getMessage(); assertThat(message, containsString("Entity resolution disallowed")); assertThat(message, containsString("/this/file/does/not/exist")); } }
@Test public void testRemoveDefaultStyle() { addWorkspace(); addDefaultStyle(); StyleInfo s = catalog.getStyleByName(StyleInfo.DEFAULT_LINE); try { catalog.remove(s); fail("removing default style should fail"); } catch (Exception e) { } }
@Test public void testGetStyleByNameWithWorkspace() { addWorkspace(); addStyle(); StyleInfo s2 = catalog.getFactory().createStyle(); s2.setName("styleNameWithWorkspace"); s2.setFilename("styleFilenameWithWorkspace"); s2.setWorkspace(ws); catalog.add(s2); assertNotNull(catalog.getStyleByName("styleNameWithWorkspace")); assertNotNull(catalog.getStyleByName(ws.getName(), "styleNameWithWorkspace")); assertNotNull(catalog.getStyleByName(ws, "styleNameWithWorkspace")); assertNull(catalog.getStyleByName((WorkspaceInfo) null, "styleNameWithWorkspace")); assertNull(catalog.getStyleByName(ws.getName(), "styleName")); assertNull(catalog.getStyleByName(ws, "styleName")); assertNotNull(catalog.getStyleByName((WorkspaceInfo) null, "styleName")); }
@Test public void testStyleWithExternalEntities() throws Exception { GeoServerDataDirectory dd = getDataDirectory(); StyleInfo si = getCatalog().getStyleByName(EXTERNAL_ENTITIES); try { dd.parsedStyle(si); fail("Should have failed with a parse error"); } catch (Exception e) { String message = e.getMessage(); assertThat(message, containsString("Entity resolution disallowed")); assertThat(message, containsString("/this/file/does/not/exist")); } } }
@Test public void testParseExternalMark() throws Exception { StyleInfo si = getCatalog().getStyleByName(HUMANS); // used to blow here with an NPE Style s = si.getStyle(); s.accept( new AbstractStyleVisitor() { @Override public void visit(Mark mark) { assertEquals( "ttf://Webdings", mark.getExternalMark() .getOnlineResource() .getLinkage() .toASCIIString()); } }); }
@Test public void testModifyStyle() throws Exception { testAddStyle(); StyleInfo s = catalog.getStyleByName("foostyle"); s.setFilename("foostyle2.sld"); catalog.save(s); File f = new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml"); Document dom = dom(f); assertXpathEvaluatesTo("foostyle2.sld", "/style/filename", dom); }
@Test public void testCascadeStyle() { Catalog catalog = getCatalog(); StyleInfo style = catalog.getStyleByName(LAKES.getLocalPart()); assertNotNull(style); new CascadeDeleteVisitor(catalog).visit(style); assertNull(catalog.getStyleByName(LAKES.getLocalPart())); LayerInfo layer = catalog.getLayerByName(getLayerId(LAKES)); assertEquals("polygon", layer.getDefaultStyle().getName()); } }
@Test public void testGetStyles() throws IOException { SLDNamedLayerRenameHelper helper = new SLDNamedLayerRenameHelper(getCatalog(), true); helper.registerLayerRename("Streams", "Stream"); List<StyleInfo> stylesToRename = helper.visitStyles(false); assertEquals(1, stylesToRename.size()); assertTrue(stylesToRename.contains(getCatalog().getStyleByName("singleStyleGroup"))); }
@Test public void testModifyStyleChangeWorkspace2() throws Exception { testAddStyle(); // copy an sld into place FileUtils.copyURLToFile( getClass().getResource("default_line.sld"), new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld")); assertTrue(new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml").exists()); assertTrue(new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld").exists()); StyleInfo s = catalog.getStyleByName("foostyle"); s.setWorkspace(catalog.getDefaultWorkspace()); catalog.save(s); assertFalse(new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml").exists()); assertFalse(new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld").exists()); assertTrue( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml") .exists()); assertTrue( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.sld") .exists()); }
@Test public void testGetStyleByName() { addStyle(); StyleInfo s2 = catalog.getStyleByName(s.getName()); assertNotNull(s2); assertNotSame(s, s2); assertEquals(s, s2); }
@Test public void testAddLayerGroup() throws Exception { testAddLayer(); // testAddStyle(); File f = new File(testData.getDataDirectoryRoot(), "layergroups/lg.xml"); assertFalse(f.exists()); LayerGroupInfo lg = catalog.getFactory().createLayerGroup(); lg.setName("lg"); lg.getLayers().add(catalog.getLayerByName("foo")); lg.getStyles().add(catalog.getStyleByName("foostyle")); lg.getLayers().add(catalog.getLayerByName("foo")); lg.getStyles().add(/* default style */ null); lg.getLayers().add(catalog.getLayerByName("foo")); lg.getStyles().add(catalog.getStyleByName("foostyle")); catalog.add(lg); assertTrue(f.exists()); }
@Test public void testReloadDefaultStyles() throws Exception { // clear up all "point" styles final Resource styles = getDataDirectory().getStyles(); styles.list() .stream() .filter(r -> r.getType() == Resource.Type.RESOURCE && r.name().contains("point")) .forEach(r -> r.delete()); // reload getGeoServer().reload(); // check the default point style has been re-created final StyleInfo point = getCatalog().getStyleByName("point"); assertNotNull(point); }
@Test public void testModifyStyleChangeWorkspaceToGlobal() throws Exception { testAddStyleWithWorkspace(); // copy an sld into place FileUtils.copyURLToFile( getClass().getResource("default_line.sld"), new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.sld")); assertTrue( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml") .exists()); assertTrue( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.sld") .exists()); StyleInfo s = catalog.getStyleByName("foostyle"); s.setWorkspace(null); catalog.save(s); assertTrue(new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml").exists()); assertTrue(new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld").exists()); assertFalse( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml") .exists()); assertFalse( new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.sld") .exists()); }
@Test public void testRenameStyleConflict() throws Exception { testAddStyle(); File sldFile = new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld"); sldFile.createNewFile(); File conflictingFile = new File(testData.getDataDirectoryRoot(), "styles/boostyle.sld"); conflictingFile.createNewFile(); StyleInfo s = catalog.getStyleByName("foostyle"); s.setName("boostyle"); catalog.save(s); File f = new File(testData.getDataDirectoryRoot(), "styles/boostyle.xml"); Document dom = dom(f); assertXpathEvaluatesTo("boostyle1.sld", "/style/filename", dom); File renamedSldFile = new File(testData.getDataDirectoryRoot(), "styles/boostyle1.sld"); assertThat(sldFile, not(fileExists())); assertThat(renamedSldFile, fileExists()); }
@Test public void testModifyStyleChangeWorkspace() throws Exception { testAddStyle(); StyleInfo s = catalog.getStyleByName("foostyle"); s.setFilename("foostyle2.sld"); s.setWorkspace(catalog.getDefaultWorkspace()); catalog.save(s); File f = new File(testData.getDataDirectoryRoot(), "styles/foostyle.xml"); assertFalse(f.exists()); f = new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml"); Document dom = dom(f); assertXpathEvaluatesTo("foostyle2.sld", "/style/filename", dom); }
@Test public void testRenameStyleWithExistingIncrementedVersion() throws Exception { testAddStyle(); File sldFile = new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld"); sldFile.createNewFile(); File sldFile1 = new File(testData.getDataDirectoryRoot(), "styles/foostyle1.sld"); sldFile1.createNewFile(); File xmlFile1 = new File(testData.getDataDirectoryRoot(), "styles/foostyle1.xml"); xmlFile1.createNewFile(); File sldFile2 = new File(testData.getDataDirectoryRoot(), "styles/foostyle2.sld"); StyleInfo s = catalog.getStyleByName("foostyle"); s.setName("foostyle"); catalog.save(s); assertThat(sldFile, not(fileExists())); assertThat(sldFile1, fileExists()); assertThat(xmlFile1, fileExists()); assertThat(sldFile2, fileExists()); sldFile1.delete(); xmlFile1.delete(); }
@Test public void testRenameStyle() throws Exception { testAddStyle(); File sldFile = new File(testData.getDataDirectoryRoot(), "styles/foostyle.sld"); sldFile.createNewFile(); StyleInfo s = catalog.getStyleByName("foostyle"); s.setName("boostyle"); catalog.save(s); File f = new File(testData.getDataDirectoryRoot(), "styles/boostyle.xml"); Document dom = dom(f); assertXpathEvaluatesTo("boostyle.sld", "/style/filename", dom); File renamedSldFile = new File(testData.getDataDirectoryRoot(), "styles/boostyle.sld"); assertThat(sldFile, not(fileExists())); assertThat(renamedSldFile, fileExists()); }
@Test public void testModifyDefaultStyle() { addWorkspace(); addDefaultStyle(); StyleInfo s = catalog.getStyleByName(StyleInfo.DEFAULT_LINE); s.setName("foo"); try { catalog.save(s); fail("changing name of default style should fail"); } catch (Exception e) { } s = catalog.getStyleByName(StyleInfo.DEFAULT_LINE); s.setWorkspace(ws); try { catalog.save(s); fail("changing workspace of default style should fail"); } catch (Exception e) { } }
@Test public void testGeneratedStyles() throws Exception { XStreamPersisterFactory xpf = new XStreamPersisterFactory(); XStreamPersister xp = xpf.createXMLPersister(); xp.setCatalog(catalog); loader.initializeStyles(catalog, xp); StyleInfo polygon = catalog.getStyleByName(StyleInfo.DEFAULT_POLYGON); assertEquals("default_polygon.sld", polygon.getFilename()); }
@Test public void testRemoveStyleWithWorkspace() throws Exception { StyleInfo s = catalog.getFactory().createStyle(); s.setName("foostyle"); s.setFilename("foostyle.sld"); s.setWorkspace(catalog.getDefaultWorkspace()); catalog.add(s); File f = new File(testData.getDataDirectoryRoot(), "workspaces/gs/styles/foostyle.xml"); assertTrue(f.exists()); s = catalog.getStyleByName("foostyle"); assertNotNull(s); s = catalog.getStyleByName(catalog.getDefaultWorkspace(), "foostyle"); catalog.remove(s); assertFalse(f.exists()); }