diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java index 944c709..6197063 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java @@ -54,7 +54,6 @@ import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -202,6 +201,17 @@ public class GeoServerRESTReader { public boolean existsStyle(String styleName) throws RuntimeException { return styleManager.existsStyle(styleName); } + + /** + * Check if a Style exists in the configured GeoServer instance. + * @param styleName the name of the style to check for. + * @param quietOnNotFound if true, mute exception if false is returned + * @return true on HTTP 200, false on HTTP 404 + * @throws RuntimeException if any other HTTP code than 200 or 404 was retrieved. + */ + public boolean existsStyle(String styleName, boolean quietOnNotFound) throws RuntimeException { + return styleManager.existsStyle(styleName, quietOnNotFound); + } /** * @see GeoServerRESTStyleManager#existsStyle(java.lang.String, java.lang.String) @@ -310,6 +320,31 @@ public class GeoServerRESTReader { String response = loadFullURL(url); return RESTDataStore.build(response); } + + /** + * Checks if the selected DataStore is present + * + * @param workspace workspace of the datastore + * @param dsName name of the datastore + * @return boolean indicating if the datastore exists + */ + public boolean existsDatastore(String workspace, String dsName){ + return existsDatastore(workspace, dsName, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } + + /** + * Checks if the selected DataStore is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the datastore + * @param dsName name of the datastore + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the datastore exists + */ + public boolean existsDatastore(String workspace, String dsName, boolean quietOnNotFound){ + String url = baseurl + "/rest/workspaces/" + workspace + "/datastores/" + dsName + ".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } //========================================================================== //=== FEATURETYPES @@ -330,6 +365,33 @@ public class GeoServerRESTReader { return RESTFeatureType.build(response); } + /** + * Checks if the selected FeatureType is present. + * + * @param workspace workspace of the datastore + * @param dsName name of the datastore + * @param ftName name of the featuretype + * @return boolean indicating if the featuretype exists + */ + public boolean existsFeatureType(String workspace, String dsName, String ftName){ + return existsFeatureType(workspace, dsName, ftName, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } + + /** + * Checks if the selected FeatureType is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the datastore + * @param dsName name of the datastore + * @param ftName name of the featuretype + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the featuretype exists + */ + public boolean existsFeatureType(String workspace, String dsName, String ftName, boolean quietOnNotFound){ + String url = baseurl + "/rest/workspaces/" + workspace + "/datastores/" + dsName + "/featuretypes/" + ftName +".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + //========================================================================== //=== COVERAGESTORES //========================================================================== @@ -379,6 +441,31 @@ public class GeoServerRESTReader { String response = loadFullURL(url); return RESTCoverageStore.build(response); } + + /** + * Checks if the selected Coverage store is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the coveragestore + * @param dsName name of the coveragestore + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the coveragestore exists + */ + public boolean existsCoveragestore(String workspace, String csName, boolean quietOnNotFound){ + String url = baseurl + "/rest/workspaces/" + workspace + "/coveragestores/" + csName + ".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected Coverage store is present. + * + * @param workspace workspace of the coveragestore + * @param dsName name of the coveragestore + * @return boolean indicating if the coveragestore exists + */ + public boolean existsCoveragestore(String workspace, String csName){ + return existsCoveragestore(workspace, csName, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } //========================================================================== //=== COVERAGES @@ -415,6 +502,33 @@ public class GeoServerRESTReader { } return RESTCoverage.build(load(url)); } + + /** + * Checks if the selected Coverage is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the coveragestore + * @param dsName name of the coveragestore + * @param name name of the coverage + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the coverage exists + */ + public boolean existsCoverage(String workspace, String store, String name, boolean quietOnNotFound){ + String url = baseurl + "/rest/workspaces/" + workspace + "/coveragestores/" + store + "/coverages/"+name+".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected Coverage is present. + * + * @param workspace workspace of the coveragestore + * @param store name of the coveragestore + * @param name name of the coverage + * @return boolean indicating if the coverage exists + */ + public boolean existsCoverage(String workspace, String store, String name){ + return existsCoverage(workspace, store, name, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } /** * Get detailed info about a Coverage given the Layer where it's published with. @@ -508,7 +622,35 @@ public class GeoServerRESTReader { return getLayerGroup(null, name); } - + /** + * Checks if the selected LayerGroup is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the LayerGroup + * @param name name of the LayerGroup + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the LayerGroup exists + */ + public boolean existsLayerGroup(String workspace, String name, boolean quietOnNotFound){ + String url; + if (workspace == null) { + url = baseurl + "/rest/layergroups/" + name + ".xml"; + } else { + url = baseurl + "/rest/workspaces/" + workspace + "/layergroups/" + name + ".xml"; + } + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected LayerGroup is present. + * + * @param workspace workspace of the LayerGroup + * @param name name of the LayerGroup + * @return boolean indicating if the LayerGroup exists + */ + public boolean existsLayerGroup(String workspace, String name){ + return existsLayerGroup(workspace, name, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } //========================================================================== //=== LAYERS @@ -582,6 +724,36 @@ public class GeoServerRESTReader { } return layer; } + + /** + * Checks if the selected Layer is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the Layer + * @param name name of the Layer + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the Layer exists + */ + public boolean existsLayer(String workspace, String name, boolean quietOnNotFound){ + String url; + if (workspace == null) { + url = baseurl + "/rest/layers/" + name + ".xml"; + } else { + url = baseurl + "/rest/layers/" + workspace + ":" + name + ".xml"; + } + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected Layer is present. + * + * @param workspace workspace of the Layer + * @param name name of the Layer + * @return boolean indicating if the Layer exists + */ + public boolean existsLayer(String workspace, String name){ + return existsLayerGroup(workspace, name, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } //========================================================================== //=== NAMESPACES @@ -634,6 +806,32 @@ public class GeoServerRESTReader { return names; } + /** + * Checks if the selected Namespace is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param prefix namespace prefix. + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the Namespace exists + */ + public boolean existsNamespace(String prefix, boolean quietOnNotFound) { + if (prefix == null || prefix.isEmpty()) { + throw new IllegalArgumentException("Namespace prefix cannot be null or empty"); + } + String url = baseurl + "/rest/namespaces/" + prefix + ".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected Namespace is present. + * + * @param prefix namespace prefix. + * @return boolean indicating if the Namespace exists + */ + public boolean existsNamespace(String prefix){ + return existsNamespace(prefix, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } + //========================================================================== //=== WORKSPACES //========================================================================== @@ -669,7 +867,37 @@ public class GeoServerRESTReader { } return names; } + + /** + * Checks if the selected Workspace is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param prefix Workspace prefix. + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the Workspace exists + */ + public boolean existsWorkspace(String prefix, boolean quietOnNotFound) { + if (prefix == null || prefix.isEmpty()) { + throw new IllegalArgumentException("Workspace prefix cannot be null or empty"); + } + String url = baseurl + "/rest/workspaces/" + prefix + ".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + /** + * Checks if the selected Workspace is present. + * + * @param prefix Workspace prefix. + * @return boolean indicating if the Workspace exists + */ + public boolean existsWorkspace(String prefix){ + return existsWorkspace(prefix, Util.DEFAULT_QUIET_ON_NOT_FOUND); + } + + //========================================================================== + //=== Structured Coverages + //========================================================================== + /** * Get information about a granule for a structured coverage. * @@ -702,6 +930,38 @@ public class GeoServerRESTReader { } return null; } + + /** + * Checks if the selected Granule is present. Parameter quietOnNotFound can be used for controlling the logging when 404 is returned. + * + * @param workspace workspace of the coveragestore + * @param coverageStore name of the coveragestore + * @param coverage name of the coverage + * @param id id of the granule + * @param quietOnNotFound if true, no exception is logged + * @return boolean indicating if the Granule exists + */ + public boolean existsGranule(String workspace, String coverageStore, String coverage, + String id, boolean quietOnNotFound) { + String url = baseurl + "/rest/workspaces/" + workspace + "/coveragestores/" + coverageStore + + "/coverages/" + coverage + "/index/granules/" + id + ".xml"; + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed, username, password); + } + + /** + * Checks if the selected Granule is present. + * + * @param workspace workspace of the coveragestore + * @param coverageStore name of the coveragestore + * @param coverage name of the coverage + * @param id id of the granule + * @return boolean indicating if the Granule exists + */ + public boolean existsGranule(String workspace, String coverageStore, String coverage, String id) { + return existsGranule(workspace, coverageStore, coverage, id, + Util.DEFAULT_QUIET_ON_NOT_FOUND); + } /** * Get information about the schema of the index for a structured coverage. diff --git a/src/main/java/it/geosolutions/geoserver/rest/Util.java b/src/main/java/it/geosolutions/geoserver/rest/Util.java index 6cee565..20a5175 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/Util.java +++ b/src/main/java/it/geosolutions/geoserver/rest/Util.java @@ -34,6 +34,10 @@ import java.util.List; * @author ETj (etj at geo-solutions.it) */ public class Util { + + public static final String QUIET_ON_NOT_FOUND_PARAM = "quietOnNotFound="; + + public static final boolean DEFAULT_QUIET_ON_NOT_FOUND = true; /** * Search for a stylename in global and in all workspaces. @@ -54,4 +58,16 @@ public class Util { return styles; } + + /** + * Append the quietOnNotFound parameter to the input URL + * @param quietOnNotFound parameter + * @param url input url + * @return a composed url with the parameter appended + */ + public static String appendQuietOnNotFound(boolean quietOnNotFound, String url) { + boolean contains = url.contains("?"); + String composed = url + (contains ? "&":"?") + QUIET_ON_NOT_FOUND_PARAM + quietOnNotFound; + return composed; + } } diff --git a/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java b/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java index 18ff1ad..ff4b37a 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java +++ b/src/main/java/it/geosolutions/geoserver/rest/manager/GeoServerRESTStyleManager.java @@ -26,6 +26,7 @@ package it.geosolutions.geoserver.rest.manager; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher; import it.geosolutions.geoserver.rest.HTTPUtils; +import it.geosolutions.geoserver.rest.Util; import it.geosolutions.geoserver.rest.decoder.RESTStyle; import it.geosolutions.geoserver.rest.decoder.RESTStyleList; import java.io.File; @@ -61,9 +62,21 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager { * @throws RuntimeException if any other HTTP code than 200 or 404 was retrieved. */ public boolean existsStyle(String name) throws RuntimeException { - String url = buildXmlUrl(null, name); - return HTTPUtils.exists(url, gsuser, gspass); + return existsStyle(name, Util.DEFAULT_QUIET_ON_NOT_FOUND); } + + /** + * Check if a Style exists in the configured GeoServer instance. User can choose if log a possible exception or not + * @param name the name of the style to check for. + * @param quietOnNotFound if true, mute exception if false is returned + * @return true on HTTP 200, false on HTTP 404 + * @throws RuntimeException if any other HTTP code than 200 or 404 was retrieved. + */ + public boolean existsStyle(String name, boolean quietOnNotFound) { + String url = buildXmlUrl(null, name); + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed , gsuser, gspass); + } /** * Get summary info about all Styles. @@ -111,9 +124,18 @@ public class GeoServerRESTStyleManager extends GeoServerRESTAbstractManager { * @since GeoServer 2.2 */ public boolean existsStyle(String workspace, String name) { - String url = buildXmlUrl(workspace, name); - return HTTPUtils.exists(url, gsuser, gspass); + return existsStyle(workspace, name, Util.DEFAULT_QUIET_ON_NOT_FOUND); } + + /** + * + * @since GeoServer 2.6 + */ + public boolean existsStyle(String workspace, String name, boolean quietOnNotFound) { + String url = buildXmlUrl(workspace, name); + String composed = Util.appendQuietOnNotFound(quietOnNotFound, url); + return HTTPUtils.exists(composed , gsuser, gspass); + } /** * Get summary info about Styles in a workspace. diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoderTest.java index f626bff..79ad6dc 100755 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSLayerGroupEncoderTest.java @@ -92,6 +92,8 @@ public class GSLayerGroupEncoderTest extends GeoserverRESTTest { groupWriter.addLayer("topp:boundaries"); groupWriter.addLayer("topp:cities"); assertTrue(publisher.createLayerGroup(groupName, groupWriter)); + // Test exists + assertTrue(reader.existsLayerGroup(null, groupName)); try { RESTLayerGroup groupReader = reader.getLayerGroup(groupName); assertNull(groupReader.getWorkspace()); @@ -114,6 +116,8 @@ public class GSLayerGroupEncoderTest extends GeoserverRESTTest { } } finally { assertTrue(publisher.removeLayerGroup(groupName)); + // Test not exists + assertFalse(reader.existsLayerGroup(null, groupName)); } } @@ -129,6 +133,8 @@ public class GSLayerGroupEncoderTest extends GeoserverRESTTest { groupWriter.addLayer("topp:boundaries"); groupWriter.addLayer("topp:cities"); assertTrue(publisher.createLayerGroup("topp", groupName, groupWriter)); + // Test exists + assertTrue(reader.existsLayerGroup("topp", groupName)); try { RESTLayerGroup groupReader = reader.getLayerGroup("topp", groupName); assertEquals("topp", groupReader.getWorkspace()); @@ -151,6 +157,8 @@ public class GSLayerGroupEncoderTest extends GeoserverRESTTest { } } finally { assertTrue(publisher.removeLayerGroup("topp", groupName)); + // Test not exists + assertFalse(reader.existsLayerGroup("topp", groupName)); } } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java index 1eaf9df..7056b2f 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java @@ -67,11 +67,15 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest { // known state? assertFalse("Cleanup failed", existsLayer(layerName)); + + // Test exists + assertFalse(reader.existsLayer(DEFAULT_WS, layerName)); // test insert boolean pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, layerName,"EPSG:4326",ProjectionPolicy.FORCE_DECLARED,"raster"); assertTrue("publish() failed", pc); assertTrue(existsLayer(layerName)); + assertFalse(reader.existsLayer(DEFAULT_WS, layerName)); LOGGER.info("Published "+pc); RESTCoverageStore reloadedCS = reader.getCoverageStore(DEFAULT_WS, storeName); @@ -102,6 +106,9 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest { boolean pub = publisher.publishGeoTIFF(DEFAULT_WS, storeName, geotiff); assertNotNull("publish() failed", pub); + // Test exists + assertTrue(reader.existsCoveragestore(DEFAULT_WS, storeName)); + assertTrue(reader.existsCoverage(DEFAULT_WS, storeName, storeName)); pub = publisher.publishGeoTIFF(DEFAULT_WS, storeName+"another", "layername", geotiff); @@ -114,6 +121,8 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest { //delete assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName,true)); + // Test not exists + assertFalse(reader.existsCoveragestore(DEFAULT_WS, storeName)); } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java index 93582c3..7e8d33e 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java @@ -29,6 +29,7 @@ package it.geosolutions.geoserver.rest.publisher; import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure; import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore; +import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList; import it.geosolutions.geoserver.rest.decoder.about.GSVersionDecoder; import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; @@ -40,6 +41,8 @@ import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder.Pr import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; @@ -77,7 +80,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImageMosaicTest.class); @Test - public void testCreateDeleteImageMosaicDatastore() { + public void testCreateDeleteImageMosaicDatastore() throws MalformedURLException, UnsupportedEncodingException { if (!enabled()) { return; } @@ -169,7 +172,14 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest { e.printStackTrace(); fail(e.getLocalizedMessage()); } - + // Get a Granule + String coverageName = "time_geotiff"; + RESTStructuredCoverageGranulesList granules = reader.getGranules(wsName, coverageStoreName, coverageName, null, null, null); + String granuleId = granules.get(0).getFid(); + // Test Granule Exists + assertTrue(reader.existsGranule(wsName, coverageStoreName, coverageName, granuleId)); + // test a Granule does not exists + assertFalse(reader.existsGranule(wsName, coverageStoreName, coverageName, granuleId.substring(0, granuleId.indexOf(".")) + "." + granules.size() + 1)); // removing recursively coveragestore boolean removed = publisher.removeCoverageStore(coverageStore.getWorkspaceName(), coverageStore.getName(), true); diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java index cc30caf..4296b65 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java @@ -58,6 +58,10 @@ public class GeoserverRESTNamespaceTest extends GeoserverRESTTest { assertTrue(publisher.createNamespace("NS2", URI.create("http://b.example.com"))); assertEquals(2, reader.getNamespaces().size()); + // Test Namespace exists + assertTrue(reader.existsNamespace("NS1")); + assertTrue(reader.existsNamespace("NS2")); + // When creating a namespace, its associated workspace will be automatically created: assertEquals(2, reader.getWorkspaces().size()); @@ -96,5 +100,7 @@ public class GeoserverRESTNamespaceTest extends GeoserverRESTTest { assertEquals(0, reader.getNamespaces().size()); assertEquals(0, reader.getWorkspaces().size()); + // Test non existens + assertFalse(reader.existsNamespace("NS1")); } } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java index 3611d73..39ceae0 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java @@ -101,6 +101,10 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile); assertTrue("publish() failed", published); assertTrue(existsLayer(layerName)); + // Test exists datastore + assertTrue(reader.existsDatastore(DEFAULT_WS, storeName)); + // Test exists featuretype + assertTrue(reader.existsFeatureType(DEFAULT_WS, storeName, layerName)); RESTLayer layer = reader.getLayer(layerName); @@ -110,10 +114,16 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName); assertTrue("Unpublish() failed", ok); assertFalse(existsLayer(layerName)); + + // Test not exists featuretype + assertFalse(reader.existsFeatureType(DEFAULT_WS, storeName, layerName)); // remove also datastore boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName,false); assertTrue("removeDatastore() failed", dsRemoved); + + // Test not exists datastore + assertFalse(reader.existsDatastore(DEFAULT_WS, storeName)); } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java index 79c104d..4f5ca12 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java @@ -78,6 +78,8 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest { assertTrue(reader.getWorkspaces().isEmpty()); assertTrue(publisher.createWorkspace(DEFAULT_WS)); + // test exists + assertTrue(reader.existsWorkspace(DEFAULT_WS)); File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile(); @@ -89,5 +91,7 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest { // remove workspace and all of its contents assertTrue(publisher.removeWorkspace(DEFAULT_WS,true)); + // Test not exists + assertFalse(reader.existsWorkspace(DEFAULT_WS)); } }