From c0e4170f5c6c6b402d1bcf18eb3e30a682276129 Mon Sep 17 00:00:00 2001 From: Marco Paulo Ollivier Date: Mon, 11 Apr 2016 17:37:08 -0300 Subject: [PATCH] TestCase of the new publishWorldImage() implementations --- .../rest/GeoServerRESTPublisher.java | 38 ++++++++++--------- .../GeoserverRESTWorldImageTest.java | 23 +++++++++-- 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 07a6b0d..e9bc47e 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -24,6 +24,21 @@ */ package it.geosolutions.geoserver.rest; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.net.URLEncoder; +import java.util.zip.ZipFile; + +import org.apache.commons.httpclient.NameValuePair; +import org.apache.commons.io.FilenameUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.geosolutions.geoserver.rest.decoder.RESTCoverage; import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore; import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList; @@ -43,21 +58,6 @@ import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverag import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager.ConfigureCoveragesOption; import it.geosolutions.geoserver.rest.manager.GeoServerRESTStyleManager; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.net.MalformedURLException; -import java.net.URI; -import java.net.URL; -import java.net.URLEncoder; -import java.util.zip.ZipFile; - -import org.apache.commons.httpclient.NameValuePair; -import org.apache.commons.io.FilenameUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * Connect to a GeoServer instance to publish or modify its contents via REST API. *

@@ -1695,6 +1695,8 @@ public class GeoServerRESTPublisher { /** * Publish a external worldimage file. * + * @author Marco Paulo Ollivier - github.com/marcopollivier/ + * * @param workspace Workspace to use * @param coveragestore Name of the coveragestore * @param fileUri the uri of the file containing the WorldImage. @@ -1707,16 +1709,17 @@ public class GeoServerRESTPublisher { * @return true if the operation completed successfully. */ public boolean publishWorldImage(String workspace, String coveragestore, URI fileURI, - ParameterConfigure configure, NameValuePair... params) throws FileNotFoundException { + ParameterConfigure configure, NameValuePair... params) throws FileNotFoundException { return createCoverageStore(workspace, coveragestore, UploadMethod.EXTERNAL, CoverageStoreExtension.WORLDIMAGE, "text/plain", fileURI, configure, params); - } /** * Publish a external worldimage file. * + * @author Marco Paulo Ollivier - github.com/marcopollivier/ + * * @param workspace Workspace to use * @param coveragestore Name of the coveragestore * @param fileUri the uri of the file containing the WorldImage. @@ -1725,7 +1728,6 @@ public class GeoServerRESTPublisher { public boolean publishWorldImage(String workspace, String coveragestore, URI fileURI) throws FileNotFoundException { return createCoverageStore(workspace, coveragestore, UploadMethod.EXTERNAL, CoverageStoreExtension.WORLDIMAGE, "text/plain", fileURI, ParameterConfigure.FIRST, (NameValuePair) null); - } // ========================================================================== diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java index ec176c8..d2797fd 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java @@ -25,20 +25,20 @@ package it.geosolutions.geoserver.rest.publisher; -import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure; -import it.geosolutions.geoserver.rest.GeoserverRESTTest; +import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; import org.apache.commons.httpclient.NameValuePair; import org.junit.Test; -import static org.junit.Assert.*; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; +import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure; +import it.geosolutions.geoserver.rest.GeoserverRESTTest; + /** * Testcase for publishing layers on geoserver. * We need a running GeoServer to properly run the tests. @@ -92,5 +92,20 @@ public class GeoserverRESTWorldImageTest extends GeoserverRESTTest { assertTrue("Publish worldfile configuring all available layers, failed.", wp); assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true)); + + // -- + + wp = publisher.publishWorldImage(DEFAULT_WS, storeName, worldImageFile.toURI(), ParameterConfigure.FIRST, new NameValuePair("coverageName", "worldImage_test")); + + assertTrue("Publish worldfile configuring all available layers, failed.", wp); + + assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true)); + + wp = publisher.publishWorldImage(DEFAULT_WS, storeName, worldImageFile.toURI()); + + assertTrue("Publish worldfile configuring all available layers, failed.", wp); + + assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true)); + } }