#176 Fix tests related to styles in workspaces

This commit is contained in:
etj 2016-04-08 19:28:54 +02:00
parent 5447c06dbc
commit ff7f383591
4 changed files with 392 additions and 387 deletions

View File

@ -156,7 +156,7 @@ public class GeoserverRESTArcGridTest extends GeoserverRESTTest {
assertTrue(reader.existsCoveragestore(DEFAULT_WS, storeName)); assertTrue(reader.existsCoveragestore(DEFAULT_WS, storeName));
assertTrue(reader.existsCoverage(DEFAULT_WS, storeName, storeName)); assertTrue(reader.existsCoverage(DEFAULT_WS, storeName, storeName));
RESTLayer layer = reader.getLayer(DEFAULT_WS, storeName); RESTLayer layer = reader.getLayer(DEFAULT_WS, storeName);
assertEquals("mystyle", layer.getDefaultStyle()); assertEquals(DEFAULT_WS + ":mystyle", layer.getDefaultStyle());
assertEquals(DEFAULT_WS, layer.getDefaultStyleWorkspace()); assertEquals(DEFAULT_WS, layer.getDefaultStyleWorkspace());
} }

View File

@ -130,7 +130,8 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
} }
@Test @Test
public void testGeoTiffWithStyleInWorkspace() throws IOException { public void testGeoTiffWithStyleInWorkspace() throws IOException
{
if (!enabled()) return; if (!enabled()) return;
deleteAll(); deleteAll();
@ -155,11 +156,11 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
assertNotNull("publish() failed", pub); assertNotNull("publish() failed", pub);
// Test exists // Test exists
assertTrue(reader.existsCoveragestore(DEFAULT_WS, storeName)); assertTrue("New coverage not found", reader.existsCoveragestore(DEFAULT_WS, storeName));
assertTrue(reader.existsCoverage(DEFAULT_WS, storeName, storeName)); assertTrue("New Store not found", reader.existsCoverage(DEFAULT_WS, storeName, storeName));
RESTLayer layer = reader.getLayer(DEFAULT_WS, storeName); RESTLayer layer = reader.getLayer(DEFAULT_WS, storeName);
assertEquals("mystyle", layer.getDefaultStyle()); assertEquals("Bad default style", DEFAULT_WS + ":mystyle", layer.getDefaultStyle());
assertEquals(DEFAULT_WS, layer.getDefaultStyleWorkspace()); assertEquals("Bad workspace for style", DEFAULT_WS, layer.getDefaultStyleWorkspace());
} }
@Test @Test

View File

@ -274,7 +274,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
RESTLayer layer = reader.getLayer(layerName); RESTLayer layer = reader.getLayer(layerName);
// RESTLayer layerDecoder = new RESTLayer(layer); // RESTLayer layerDecoder = new RESTLayer(layer);
LOGGER.info("Layer style is " + layer.getDefaultStyle()); LOGGER.info("Layer style is " + layer.getDefaultStyle());
assertEquals("Style not assigned properly", styleName, layer.getDefaultStyle()); assertEquals("Style not assigned properly", DEFAULT_WS + ":" + styleName, layer.getDefaultStyle());
assertEquals("Style not assigned properly", DEFAULT_WS, layer.getDefaultStyleWorkspace()); assertEquals("Style not assigned properly", DEFAULT_WS, layer.getDefaultStyleWorkspace());
// remove also datastore // remove also datastore

View File

@ -1,380 +1,384 @@
/* /*
* GeoServer-Manager - Simple Manager Library for GeoServer * GeoServer-Manager - Simple Manager Library for GeoServer
* *
* Copyright (C) 2007,2015 GeoSolutions S.A.S. * Copyright (C) 2007-2016 GeoSolutions S.A.S.
* http://www.geo-solutions.it * http://www.geo-solutions.it
* *
* Permission is hereby granted, free of charge, to any person obtaining a copy * Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal * of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights * in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is * copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions: * furnished to do so, subject to the following conditions:
* *
* The above copyright notice and this permission notice shall be included in * The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software. * all copies or substantial portions of the Software.
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
package it.geosolutions.geoserver.rest.publisher; package it.geosolutions.geoserver.rest.publisher;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.publisher; import static it.geosolutions.geoserver.rest.GeoserverRESTTest.publisher;
import static it.geosolutions.geoserver.rest.GeoserverRESTTest.reader; import static it.geosolutions.geoserver.rest.GeoserverRESTTest.reader;
import it.geosolutions.geoserver.rest.decoder.RESTLayer; import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.decoder.RESTStyle; import it.geosolutions.geoserver.rest.decoder.RESTStyle;
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder; import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.Namespace; import org.jdom.Namespace;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
/** /**
* Testcase for publishing layers on geoserver. We need a running GeoServer to * Testcase for publishing layers on geoserver. We need a running GeoServer to
* properly run the tests. If such geoserver instance cannot be contacted, tests * properly run the tests. If such geoserver instance cannot be contacted, tests
* will be skipped. * will be skipped.
* *
* @author etj * @author etj
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/ */
public class GeoserverRESTStyleTest extends GeoserverRESTTest { public class GeoserverRESTStyleTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTStyleTest.class);
.getLogger(GeoserverRESTStyleTest.class);
@Test
@Test public void testStyles() throws IOException
public void testStyles() throws IOException { {
if (!enabled()) if (!enabled()) {
return; return;
deleteAll(); }
deleteAll();
assertEquals(0, reader.getStyles().size());
assertEquals(0, reader.getStyles().size());
final String STYLENAME = "restteststyle";
File sldFile = new ClassPathResource("testdata/restteststyle.sld") final String STYLENAME = "restteststyle";
.getFile(); File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
// insert style // insert style
assertTrue(publisher.publishStyle(sldFile)); assertTrue(publisher.publishStyle(sldFile));
assertTrue(reader.existsStyle(STYLENAME)); assertTrue(reader.existsStyle(STYLENAME));
assertFalse(publisher.publishStyle(sldFile)); assertFalse(publisher.publishStyle(sldFile));
assertTrue(reader.existsStyle(STYLENAME)); assertTrue(reader.existsStyle(STYLENAME));
// insert style v110 // insert style v110
final String STYLENAMEV110 = "restteststyleV110"; final String STYLENAMEV110 = "restteststyleV110";
File sldFileV110 = new ClassPathResource("testdata/" + STYLENAMEV110 + ".sld").getFile(); File sldFileV110 = new ClassPathResource("testdata/" + STYLENAMEV110 + ".sld").getFile();
assertTrue(publisher.publishStyle(sldFileV110, STYLENAMEV110, true)); assertTrue(publisher.publishStyle(sldFileV110, STYLENAMEV110, true));
assertTrue(reader.existsStyle(STYLENAMEV110)); assertTrue(reader.existsStyle(STYLENAMEV110));
assertFalse(publisher.publishStyle(sldFileV110, STYLENAMEV110, true)); assertFalse(publisher.publishStyle(sldFileV110, STYLENAMEV110, true));
RESTStyle style = reader.getStyle(STYLENAME); RESTStyle style = reader.getStyle(STYLENAME);
assertEquals(STYLENAME, style.getName()); assertEquals(STYLENAME, style.getName());
assertNull(style.getWorkspace()); assertNull(style.getWorkspace());
String sld = reader.getSLD(STYLENAME); String sld = reader.getSLD(STYLENAME);
assertNotNull(sld); assertNotNull(sld);
Element styleEl = JDOMBuilder.buildElement(sld); Element styleEl = JDOMBuilder.buildElement(sld);
assertNotNull(styleEl); assertNotNull(styleEl);
Namespace SLDNS = Namespace.getNamespace("sld", Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
"http://www.opengis.net/sld");
try {
try { assertEquals(STYLENAME, styleEl.getChild("NamedLayer", SLDNS)
.getChild("Name", SLDNS).getText());
assertEquals(STYLENAME, styleEl.getChild("NamedLayer", SLDNS) assertEquals("STYLE FOR TESTING PURPOSES",
.getChild("Name", SLDNS).getText()); styleEl.getChild("NamedLayer", SLDNS)
assertEquals("STYLE FOR TESTING PURPOSES", .getChild("UserStyle", SLDNS)
styleEl.getChild("NamedLayer", SLDNS) .getChild("Title", SLDNS).getText());
.getChild("UserStyle", SLDNS) } catch (NullPointerException npe) {
.getChild("Title", SLDNS).getText()); fail("Error in SLD");
} catch (NullPointerException npe) { }
fail("Error in SLD");
} // assertEquals(1475, sld.length());
assertEquals(2, reader.getStyles().size());
// assertEquals(1475, sld.length()); }
assertEquals(2, reader.getStyles().size()); protected void cleanupTestStyle(final String styleName)
} {
// dry run delete to work in a known state
protected void cleanupTestStyle(final String styleName) { if (reader.existsStyle(styleName)) {
// dry run delete to work in a known state LOGGER.info("Clearing stale test style " + styleName);
if (reader.existsStyle(styleName)) { boolean ok = publisher.removeStyle(styleName);
LOGGER.info("Clearing stale test style " + styleName); if (!ok) {
boolean ok = publisher.removeStyle(styleName); fail("Could not unpublish style " + styleName);
if (!ok) { }
fail("Could not unpublish style " + styleName); }
} assertFalse("Cleanup failed", reader.existsStyle(styleName));
} }
assertFalse("Cleanup failed", reader.existsStyle(styleName));
} @Test
public void testPublishDeleteStyleFile() throws FileNotFoundException,
@Test IOException {
public void testPublishDeleteStyleFile() throws FileNotFoundException, if (!enabled()) {
IOException { return;
if (!enabled()) { }
return; // Assume.assumeTrue(enabled);
} final String styleName = "restteststyle";
// Assume.assumeTrue(enabled);
final String styleName = "restteststyle"; File sldFile = new ClassPathResource("testdata/restteststyle.sld")
.getFile();
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
.getFile(); final String STYLENAMEV110 = "restteststyleV110";
File sldFileV110 = new ClassPathResource("testdata/" + STYLENAMEV110 + ".sld")
final String STYLENAMEV110 = "restteststyleV110"; .getFile();
File sldFileV110 = new ClassPathResource("testdata/" + STYLENAMEV110 + ".sld")
.getFile(); // known state?
cleanupTestStyle(styleName);
// known state? cleanupTestStyle(STYLENAMEV110);
cleanupTestStyle(styleName);
cleanupTestStyle(STYLENAMEV110); // test insert
boolean published = publisher.publishStyle(sldFile); // Will take the
// test insert // name from sld
boolean published = publisher.publishStyle(sldFile); // Will take the // contents
// name from sld assertTrue("publish() failed", published);
// contents assertTrue(reader.existsStyle(styleName));
assertTrue("publish() failed", published);
assertTrue(reader.existsStyle(styleName)); sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
published = publisher.updateStyle(sldFile, styleName); // update
sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile(); assertTrue("update() failed", published);
published = publisher.updateStyle(sldFile, styleName); // update
assertTrue("update() failed", published); // test delete
boolean ok = publisher.removeStyle(styleName);
// test delete assertTrue("Unpublish() failed", ok);
boolean ok = publisher.removeStyle(styleName); assertFalse(reader.existsStyle(styleName));
assertTrue("Unpublish() failed", ok);
assertFalse(reader.existsStyle(styleName)); published = publisher.publishStyle(sldFileV110, STYLENAMEV110, true);
published = publisher.publishStyle(sldFileV110, STYLENAMEV110, true); assertTrue("publish() failed", published);
assertTrue(reader.existsStyle(STYLENAMEV110));
assertTrue("publish() failed", published);
assertTrue(reader.existsStyle(STYLENAMEV110)); boolean updated = publisher.updateStyle(sldFileV110, STYLENAMEV110, true);
assertTrue("update() failed", updated);
boolean updated = publisher.updateStyle(sldFileV110, STYLENAMEV110, true);
assertTrue("update() failed", updated); // test delete
ok = publisher.removeStyle(STYLENAMEV110);
// test delete assertTrue("Unpublish() failed", ok);
ok = publisher.removeStyle(STYLENAMEV110); assertFalse(reader.existsStyle(STYLENAMEV110));
assertTrue("Unpublish() failed", ok); }
assertFalse(reader.existsStyle(STYLENAMEV110));
} @Test
public void testPublishDeleteStyleString()
@Test throws FileNotFoundException, IOException
public void testPublishDeleteStyleString() throws FileNotFoundException, {
IOException { if (!enabled()) {
if (!enabled()) { return;
return; }
} // Assume.assumeTrue(enabled);
// Assume.assumeTrue(enabled); String styleName = "restteststyle";
String styleName = "restteststyle";
File sldFile = new ClassPathResource("testdata/restteststyle.sld")
File sldFile = new ClassPathResource("testdata/restteststyle.sld") .getFile();
.getFile();
// known state?
// known state? cleanupTestStyle(styleName);
cleanupTestStyle(styleName);
// test insert
// test insert String sldContent = IOUtils.toString(new FileInputStream(sldFile));
String sldContent = IOUtils.toString(new FileInputStream(sldFile));
boolean published = publisher.publishStyle(sldContent); // Will take the
boolean published = publisher.publishStyle(sldContent); // Will take the // name from sld
// name from sld // contents
// contents assertTrue("publish() failed", published);
assertTrue("publish() failed", published); assertTrue(reader.existsStyle(styleName));
assertTrue(reader.existsStyle(styleName)); // test delete
// test delete boolean ok = publisher.removeStyle(styleName);
boolean ok = publisher.removeStyle(styleName); assertTrue("Unpublish() failed", ok);
assertTrue("Unpublish() failed", ok); assertFalse(reader.existsStyle(styleName));
assertFalse(reader.existsStyle(styleName));
styleName = "restteststyle_with_name";
styleName = "restteststyle_with_name"; // test insert with name
// test insert with name published = publisher.publishStyle(sldContent, styleName); // Will set
published = publisher.publishStyle(sldContent, styleName); // Will set // the name
// the name assertTrue("publish() failed", published);
assertTrue("publish() failed", published); assertTrue(reader.existsStyle(styleName));
assertTrue(reader.existsStyle(styleName)); String newSldContent = sldContent.replace(
String newSldContent = sldContent.replace( "<sld:Title>STYLE FOR TESTING PURPOSES</sld:Title>",
"<sld:Title>STYLE FOR TESTING PURPOSES</sld:Title>", "<sld:Title>MODIFIED STYLE FOR TESTING</sld:Title>");
"<sld:Title>MODIFIED STYLE FOR TESTING</sld:Title>"); published = publisher.updateStyle(newSldContent, styleName); // update
published = publisher.updateStyle(newSldContent, styleName); // update assertTrue("publish() failed", published);
assertTrue("publish() failed", published);
// test delete
// test delete ok = publisher.removeStyle(styleName);
ok = publisher.removeStyle(styleName); assertTrue("Unpublish() failed", ok);
assertTrue("Unpublish() failed", ok); assertFalse(reader.existsStyle(styleName));
assertFalse(reader.existsStyle(styleName));
}
}
@Test
@Test public void testUpdateDefaultStyle()
public void testUpdateDefaultStyle() throws FileNotFoundException, throws FileNotFoundException, IOException
IOException { {
if (!enabled()) { if (!enabled()) {
return; return;
} }
deleteAll(); deleteAll();
String storeName = "resttestshp"; String storeName = "resttestshp";
String layerName = "cities"; String layerName = "cities";
final String styleName = "restteststyle"; final String styleName = "restteststyle";
{ {
File sldFile = new ClassPathResource("testdata/restteststyle.sld") File sldFile = new ClassPathResource("testdata/restteststyle.sld")
.getFile(); .getFile();
cleanupTestStyle(styleName); cleanupTestStyle(styleName);
boolean sldpublished = publisher.publishStyle(sldFile); // Will take boolean sldpublished = publisher.publishStyle(sldFile); // Will take
// the name // the name
// from sld // from sld
// contents // contents
assertTrue("style publish() failed", sldpublished); assertTrue("style publish() failed", sldpublished);
assertTrue(reader.existsStyle(styleName)); assertTrue(reader.existsStyle(styleName));
} }
final String styleName2 = "restteststyle2"; final String styleName2 = "restteststyle2";
{ {
File sldFile = new ClassPathResource("testdata/restteststyle2.sld") File sldFile = new ClassPathResource("testdata/restteststyle2.sld")
.getFile(); .getFile();
cleanupTestStyle(styleName2); cleanupTestStyle(styleName2);
boolean sldpublished = publisher.publishStyle(sldFile, styleName2); boolean sldpublished = publisher.publishStyle(sldFile, styleName2);
assertTrue("style publish() failed", sldpublished); assertTrue("style publish() failed", sldpublished);
assertTrue(reader.existsStyle(styleName2)); assertTrue(reader.existsStyle(styleName2));
} }
File zipFile = new ClassPathResource("testdata/resttestshp.zip") File zipFile = new ClassPathResource("testdata/resttestshp.zip")
.getFile(); .getFile();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
// test insert // test insert
boolean published = publisher.publishShp(DEFAULT_WS, storeName, boolean published = publisher.publishShp(DEFAULT_WS, storeName,
layerName, zipFile, "EPSG:4326", styleName); layerName, zipFile, "EPSG:4326", styleName);
assertTrue("publish() failed", published); assertTrue("publish() failed", published);
assertTrue(existsLayer(layerName)); assertTrue(existsLayer(layerName));
{ {
RESTLayer layer = reader.getLayer(layerName); RESTLayer layer = reader.getLayer(layerName);
LOGGER.info("Layer style is " + layer.getDefaultStyle()); LOGGER.info("Layer style is " + layer.getDefaultStyle());
assertEquals(styleName, layer.getDefaultStyle()); assertEquals(styleName, layer.getDefaultStyle());
} }
GSLayerEncoder le = new GSLayerEncoder(); GSLayerEncoder le = new GSLayerEncoder();
le.setDefaultStyle(styleName2); le.setDefaultStyle(styleName2);
publisher.configureLayer(DEFAULT_WS, layerName, le); publisher.configureLayer(DEFAULT_WS, layerName, le);
{ {
RESTLayer layer = reader.getLayer(layerName); RESTLayer layer = reader.getLayer(layerName);
LOGGER.info("Layer style is " + layer.getDefaultStyle()); LOGGER.info("Layer style is " + layer.getDefaultStyle());
assertEquals(styleName2, layer.getDefaultStyle()); assertEquals(styleName2, layer.getDefaultStyle());
} }
// remove layer and datastore // remove layer and datastore
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName, boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName,
true); true);
assertTrue("removeDatastore() failed", dsRemoved); assertTrue("removeDatastore() failed", dsRemoved);
} }
@Test @Test
public void testStylesInWorkspace() throws IOException { public void testStylesInWorkspace() throws IOException
if (!enabled()) {
return; if (!enabled()) {
deleteAll(); return;
}
final String WORKSPACE = "testWorkspace"; deleteAll();
final String STYLENAME = "restteststyle";
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile(); final String WORKSPACE = "testWorkspace";
final String STYLENAME = "restteststyle";
publisher.createWorkspace(WORKSPACE); File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
assertEquals(0, reader.getStyles().size()); publisher.createWorkspace(WORKSPACE);
assertEquals(0, reader.getStyles(WORKSPACE).size());
assertEquals(0, reader.getStyles().size());
assertEquals(0, reader.getStyles(WORKSPACE).size());
// insert style
assertTrue(publisher.publishStyleInWorkspace(WORKSPACE, sldFile)); // insert style
assertTrue(reader.existsStyle(WORKSPACE, STYLENAME)); assertTrue("Error inserting style", publisher.publishStyleInWorkspace(WORKSPACE, sldFile));
assertFalse(reader.existsStyle(STYLENAME)); assertTrue("Style does not exist in workspace", reader.existsStyle(WORKSPACE, STYLENAME));
// insert style again // this assertion is not enforced by geoserver, which is quite lenient in searching names
assertFalse(publisher.publishStyleInWorkspace(WORKSPACE, sldFile)); //assertFalse("Style should not be global", reader.existsStyle(STYLENAME));
assertTrue(reader.existsStyle(WORKSPACE, STYLENAME));
assertFalse(reader.existsStyle(STYLENAME)); // insert style again
assertFalse("Dup style not trapped", publisher.publishStyleInWorkspace(WORKSPACE, sldFile));
String sld = reader.getSLD(WORKSPACE, STYLENAME); assertTrue("Style does not exist in workspace (2)", reader.existsStyle(WORKSPACE, STYLENAME));
assertNotNull(sld); // this assertion is not enforced by geoserver, which is quite lenient in searching names
//assertFalse("Style should not be global (2)", reader.existsStyle(STYLENAME));
RESTStyle style = reader.getStyle(WORKSPACE, STYLENAME);
assertEquals(STYLENAME, style.getName()); String sld = reader.getSLD(WORKSPACE, STYLENAME);
assertEquals(WORKSPACE, style.getWorkspace()); assertNotNull(sld);
Element styleEl = JDOMBuilder.buildElement(sld); RESTStyle style = reader.getStyle(WORKSPACE, STYLENAME);
assertNotNull(styleEl); assertEquals(STYLENAME, style.getName());
assertEquals(WORKSPACE, style.getWorkspace());
Namespace SLDNS = Namespace.getNamespace("sld",
"http://www.opengis.net/sld"); Element styleEl = JDOMBuilder.buildElement(sld);
assertNotNull(styleEl);
try {
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
assertEquals(STYLENAME, styleEl.getChild("NamedLayer", SLDNS)
.getChild("Name", SLDNS).getText()); try {
assertEquals(
"STYLE FOR TESTING PURPOSES", assertEquals(STYLENAME, styleEl.getChild("NamedLayer", SLDNS)
styleEl.getChild("NamedLayer", SLDNS) .getChild("Name", SLDNS).getText());
.getChild("UserStyle", SLDNS) assertEquals(
.getChild("Title", SLDNS).getText()); "STYLE FOR TESTING PURPOSES",
} catch (NullPointerException npe) { styleEl.getChild("NamedLayer", SLDNS)
fail("Error in SLD"); .getChild("UserStyle", SLDNS)
} .getChild("Title", SLDNS).getText());
} catch (NullPointerException npe) {
// assertEquals(1475, sld.length()); fail("Error in SLD");
}
assertEquals(0, reader.getStyles().size());
assertEquals(1, reader.getStyles(WORKSPACE).size()); // assertEquals(1475, sld.length());
} assertEquals(0, reader.getStyles().size());
assertEquals(1, reader.getStyles(WORKSPACE).size());
@Test }
public void testRemoveStylesInWorkspace() throws IOException {
if (!enabled()) @Test
return; public void testRemoveStylesInWorkspace() throws IOException
deleteAll(); {
if (!enabled()) {
final String WORKSPACE = "testWorkspace"; return;
final String STYLENAME = "restteststyle"; }
final File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile(); deleteAll();
publisher.createWorkspace(WORKSPACE); final String WORKSPACE = "testWorkspace";
final String STYLENAME = "restteststyle";
assertEquals(0, reader.getStyles(WORKSPACE).size()); final File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
// insert style publisher.createWorkspace(WORKSPACE);
assertTrue(publisher.publishStyleInWorkspace(WORKSPACE, sldFile));
assertEquals(1, reader.getStyles(WORKSPACE).size()); assertEquals(0, reader.getStyles(WORKSPACE).size());
assertTrue(reader.existsStyle(WORKSPACE, STYLENAME));
// insert style
// remove style assertTrue(publisher.publishStyleInWorkspace(WORKSPACE, sldFile));
assertTrue(publisher.removeStyleInWorkspace(WORKSPACE, STYLENAME, true)); assertEquals(1, reader.getStyles(WORKSPACE).size());
assertEquals(0, reader.getStyles(WORKSPACE).size()); assertTrue(reader.existsStyle(WORKSPACE, STYLENAME));
assertFalse(reader.existsStyle(WORKSPACE, STYLENAME));
} // remove style
assertTrue(publisher.removeStyleInWorkspace(WORKSPACE, STYLENAME, true));
} assertEquals(0, reader.getStyles(WORKSPACE).size());
assertFalse(reader.existsStyle(WORKSPACE, STYLENAME));
}
}