added worldimage, imagemosaic and fixed geotiff publication. Added tests and splitted Test classes.
This commit is contained in:
parent
1961ecd8b7
commit
e0a033ea71
2
README
2
README
@ -4,4 +4,4 @@ The purpose of this project is to hold a REST client library to interact with Ge
|
|||||||
|
|
||||||
For more information see this page:
|
For more information see this page:
|
||||||
|
|
||||||
http://code.google.com/p/geoserver-manager/
|
https://github.com/geosolutions-it/geoserver-manager
|
||||||
4
pom.xml
4
pom.xml
@ -129,8 +129,8 @@
|
|||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>2.0.2</version>
|
<version>2.0.2</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.5</source>
|
<source>1.6</source>
|
||||||
<target>1.5</target>
|
<target>1.6</target>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
|||||||
@ -40,13 +40,11 @@ import java.net.MalformedURLException;
|
|||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
import org.apache.commons.io.FilenameUtils;
|
import org.apache.commons.io.FilenameUtils;
|
||||||
import org.apache.log4j.Level;
|
import org.apache.log4j.Level;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.Priority;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connect to a GeoServer instance to publish or modify data.
|
* Connect to a GeoServer instance to publish or modify data.
|
||||||
@ -257,7 +255,7 @@ public class GeoServerRESTPublisher {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||||
layerEncoder.addDefaultStyle(defaultStyle);
|
layerEncoder.setDefaultStyle(defaultStyle);
|
||||||
configureLayer(workspace, layerName, layerEncoder);
|
configureLayer(workspace, layerName, layerEncoder);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.warn("Error in publishing shapefile " + e.getMessage(),
|
LOGGER.warn("Error in publishing shapefile " + e.getMessage(),
|
||||||
@ -334,17 +332,7 @@ public class GeoServerRESTPublisher {
|
|||||||
.append("/datastores/").append(storename).append("/file.shp?");
|
.append("/datastores/").append(storename).append("/file.shp?");
|
||||||
|
|
||||||
// append parameters
|
// append parameters
|
||||||
if (params != null) {
|
sbUrl.append(appendParameters(params));
|
||||||
final int paramsSize = params.length;
|
|
||||||
if (paramsSize > 0) {
|
|
||||||
sbUrl.append(params[0].getName()).append("=")
|
|
||||||
.append(params[0].getValue());
|
|
||||||
for (int i = 1; i < paramsSize; i++) {
|
|
||||||
sbUrl.append("&").append(params[i].getName()).append("=")
|
|
||||||
.append(params[i].getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (workspace != null) {
|
// if (workspace != null) {
|
||||||
// sbUrl.append("namespace=").append(workspace);
|
// sbUrl.append("namespace=").append(workspace);
|
||||||
@ -492,7 +480,7 @@ public class GeoServerRESTPublisher {
|
|||||||
/**
|
/**
|
||||||
* The configure parameter is used to control how the data store is
|
* The configure parameter is used to control how the data store is
|
||||||
* configured upon file upload. It can take one of the three values “first”,
|
* configured upon file upload. It can take one of the three values “first”,
|
||||||
* “none”, or “all”. <br>
|
* <i>none</i>, or <i>all</i>. <br>
|
||||||
* first - Only setup the first feature type available in the data store.
|
* first - Only setup the first feature type available in the data store.
|
||||||
* This is the default. <br>
|
* This is the default. <br>
|
||||||
* none - Do not configure any feature types.<br>
|
* none - Do not configure any feature types.<br>
|
||||||
@ -516,7 +504,7 @@ public class GeoServerRESTPublisher {
|
|||||||
* The update parameter is used to control how existing data is handled when
|
* The update parameter is used to control how existing data is handled when
|
||||||
* the file is PUT into a datastore that (a) already exists and (b) already
|
* the file is PUT into a datastore that (a) already exists and (b) already
|
||||||
* contains a schema that matches the content of the file. It can take one
|
* contains a schema that matches the content of the file. It can take one
|
||||||
* of the two values “append”, or “overwrite”.<br>
|
* of the two values <i>append</i>, or <i>overwrite</i>.<br>
|
||||||
* append - Data being uploaded is appended to the existing data. This is
|
* append - Data being uploaded is appended to the existing data. This is
|
||||||
* the default.<br>
|
* the default.<br>
|
||||||
* overwrite - Data being uploaded replaces any existing data.<br>
|
* overwrite - Data being uploaded replaces any existing data.<br>
|
||||||
@ -537,6 +525,75 @@ public class GeoServerRESTPublisher {
|
|||||||
// === COVERAGES
|
// === COVERAGES
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Publish a zipped worldimage file. It is assumed that the the zip-file
|
||||||
|
* contain the *.prj to set the srs.
|
||||||
|
* <P>
|
||||||
|
* This is equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* <PRE>
|
||||||
|
* {@code
|
||||||
|
* curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
|
||||||
|
*
|
||||||
|
* --data-binary @$ZIPFILE \
|
||||||
|
*
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* @param workspace
|
||||||
|
* Workspace to use
|
||||||
|
* @param coveragestore
|
||||||
|
* Name of the coveragestore
|
||||||
|
* @param file
|
||||||
|
* zip file to upload
|
||||||
|
* @param configure
|
||||||
|
* Configure parameter. It may be null.
|
||||||
|
* @param params
|
||||||
|
* parameters to append to the url (can be null).<br>
|
||||||
|
* Accepted parameters are:
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* <b>coverageName=name</b> coverageName parameter to append. Only
|
||||||
|
* works if configure is not set to ParameterConfigure.NONE.
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
* @see #{@link ParameterConfigure}
|
||||||
|
* @return true if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
private boolean publishCoverage(String workspace, String coveragestore, String format, String mimeType,
|
||||||
|
File file, ParameterConfigure configure, NameValuePair... params)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
// build full URL
|
||||||
|
StringBuilder sbUrl = new StringBuilder(restURL)
|
||||||
|
.append("/rest/workspaces/").append(workspace)
|
||||||
|
.append("/coveragestores/").append(coveragestore)
|
||||||
|
.append("/file.").append(format);
|
||||||
|
|
||||||
|
if (configure != null) {
|
||||||
|
sbUrl.append("?configure=").append(configure);
|
||||||
|
if (params!= null && !configure.equals(ParameterConfigure.NONE)){
|
||||||
|
final String paramString=appendParameters(params);
|
||||||
|
if (!paramString.isEmpty()){
|
||||||
|
sbUrl.append("&").append(paramString);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String sentResult = HTTPUtils.put(sbUrl.toString(), file,
|
||||||
|
mimeType, gsuser, gspass);
|
||||||
|
boolean fileSent = sentResult != null;
|
||||||
|
|
||||||
|
if (fileSent) {
|
||||||
|
if (LOGGER.isInfoEnabled())
|
||||||
|
LOGGER.info("File successfully uploaded ( " + file
|
||||||
|
+ ")");
|
||||||
|
} else {
|
||||||
|
if (LOGGER.isEnabledFor(Level.WARN))
|
||||||
|
LOGGER.warn("Error in sending file " + file);
|
||||||
|
}
|
||||||
|
return fileSent;
|
||||||
|
}
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// === GEOTIFF
|
// === GEOTIFF
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
@ -555,16 +612,10 @@ public class GeoServerRESTPublisher {
|
|||||||
* </PRE>
|
* </PRE>
|
||||||
*
|
*
|
||||||
* @return true if the operation completed successfully.
|
* @return true if the operation completed successfully.
|
||||||
* @deprecated UNTESTED
|
|
||||||
*/
|
*/
|
||||||
public boolean publishGeoTIFF(String workspace, String storeName,
|
public boolean publishGeoTIFF(String workspace, String storeName,
|
||||||
File geotiff) throws FileNotFoundException {
|
File geotiff) throws FileNotFoundException {
|
||||||
String sUrl = restURL + "/rest/workspaces/" + workspace
|
return publishCoverage(workspace, storeName, "geotiff", "image/geotiff", geotiff, ParameterConfigure.FIRST, (NameValuePair[])null);
|
||||||
+ "/coveragestores/" + storeName + "/geotiff";
|
|
||||||
String sendResult = HTTPUtils
|
|
||||||
.put(sUrl, geotiff, "text", gsuser, gspass); // CHECKME: text?!?
|
|
||||||
boolean sent = sendResult != null;
|
|
||||||
return sent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -629,10 +680,85 @@ public class GeoServerRESTPublisher {
|
|||||||
return store;
|
return store;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ==========================================================================
|
||||||
|
// === WORLDIMAGE
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@link #publishWorldImage(String, String, File, ParameterConfigure, NameValuePair...)}
|
||||||
|
*/
|
||||||
|
public boolean publishWorldImage(String workspace, String coveragestore, File zipFile)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
return publishWorldImage(workspace, coveragestore, zipFile, ParameterConfigure.FIRST,(NameValuePair)null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Publish a zipped worldimage file. It is assumed that the the zip-file
|
||||||
|
* contain the *.prj to set the srs.
|
||||||
|
* <P>
|
||||||
|
* This is equivalent call with cUrl:
|
||||||
|
*
|
||||||
|
* <PRE>
|
||||||
|
* {@code
|
||||||
|
* curl -u admin:geoserver -XPUT -H 'Content-type: application/zip' \
|
||||||
|
*
|
||||||
|
* --data-binary @$ZIPFILE \
|
||||||
|
*
|
||||||
|
* http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/coveragestores/$COVERAGESTORE/file.worldimage
|
||||||
|
* </PRE>
|
||||||
|
*
|
||||||
|
* @param workspace
|
||||||
|
* Workspace to use
|
||||||
|
* @param coveragestore
|
||||||
|
* Name of the coveragestore
|
||||||
|
* @param zipFile
|
||||||
|
* zip file to upload
|
||||||
|
* @param configure
|
||||||
|
* Configure parameter. It may be null.
|
||||||
|
* @param params
|
||||||
|
* parameters to append to the url (can be null).<br>
|
||||||
|
* Accepted parameters are:
|
||||||
|
* <ul>
|
||||||
|
* <li>
|
||||||
|
* <b>coverageName=name</b> coverageName parameter to append. Only
|
||||||
|
* works if configure is not set to ParameterConfigure.NONE.
|
||||||
|
* </li>
|
||||||
|
* </ul>
|
||||||
|
* @see #{@link ParameterConfigure}
|
||||||
|
* @return true if the operation completed successfully.
|
||||||
|
*/
|
||||||
|
public boolean publishWorldImage(String workspace, String coveragestore,
|
||||||
|
File zipFile, ParameterConfigure configure, NameValuePair... params)
|
||||||
|
throws FileNotFoundException {
|
||||||
|
return publishCoverage(workspace, coveragestore, "worldimage", "application/zip", zipFile, configure, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// === MOSAIC
|
// === MOSAIC
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish imagemosaic as zip file
|
||||||
|
*
|
||||||
|
* @see {@link #publishWorldImage(String, String, File)}
|
||||||
|
*/
|
||||||
|
public boolean publishImageMosaic(String workspace, String storeName,
|
||||||
|
File zipFile) throws FileNotFoundException {
|
||||||
|
return publishCoverage(workspace, storeName, "imagemosaic", "application/zip", zipFile, ParameterConfigure.FIRST, (NameValuePair[])null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Publish imagemosaic as zip file
|
||||||
|
*
|
||||||
|
* @see {@link #publishWorldImage(String, String, File, ParameterConfigure, NameValuePair...)}
|
||||||
|
*/
|
||||||
|
public boolean publishImageMosaic(String workspace, String storeName,
|
||||||
|
File zipFile, ParameterConfigure configure, NameValuePair... params) throws FileNotFoundException {
|
||||||
|
return publishCoverage(workspace, storeName, "imagemosaic", "application/zip", zipFile, configure, params);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Publish a Mosaic from a filesystem currently readable by GeoServer.
|
* Publish a Mosaic from a filesystem currently readable by GeoServer.
|
||||||
*
|
*
|
||||||
@ -659,7 +785,7 @@ public class GeoServerRESTPublisher {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Carlo (23 Nov 2011): commented out since this directory should be
|
* Carlo (23 Nov 2011): commented out since this directory should be
|
||||||
* readable by targhet GeoServer not the calling client!
|
* readable by target GeoServer not the calling client!
|
||||||
*/
|
*/
|
||||||
if (!mosaicDir.isDirectory()) {
|
if (!mosaicDir.isDirectory()) {
|
||||||
if (LOGGER.isEnabledFor(Level.WARN))
|
if (LOGGER.isEnabledFor(Level.WARN))
|
||||||
@ -779,7 +905,7 @@ public class GeoServerRESTPublisher {
|
|||||||
|
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
LOGGER.warn("Unable to get the store" + workspace + ":" + storeName
|
LOGGER.warn("Unable to get the store" + workspace + ":" + storeName
|
||||||
+ " from the targhet geoserver.");
|
+ " from the target geoserver.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1054,7 +1180,8 @@ public class GeoServerRESTPublisher {
|
|||||||
if (workspace == null || storename == null)
|
if (workspace == null || storename == null)
|
||||||
throw new IllegalArgumentException("Arguments may not be null!");
|
throw new IllegalArgumentException("Arguments may not be null!");
|
||||||
if (workspace.isEmpty() || storename.isEmpty())
|
if (workspace.isEmpty() || storename.isEmpty())
|
||||||
throw new IllegalArgumentException("Arguments may not be empty!");
|
throw new IllegalArgumentException(
|
||||||
|
"Arguments may not be empty!");
|
||||||
|
|
||||||
final StringBuilder url = new StringBuilder(restURL);
|
final StringBuilder url = new StringBuilder(restURL);
|
||||||
url.append("/rest/workspaces/").append(workspace)
|
url.append("/rest/workspaces/").append(workspace)
|
||||||
@ -1113,12 +1240,14 @@ public class GeoServerRESTPublisher {
|
|||||||
* @return <TT>true</TT> if the CoverageStore was successfully removed.
|
* @return <TT>true</TT> if the CoverageStore was successfully removed.
|
||||||
*/
|
*/
|
||||||
public boolean removeCoverageStore(final String workspace,
|
public boolean removeCoverageStore(final String workspace,
|
||||||
final String storename, final boolean recurse) throws IllegalArgumentException {
|
final String storename, final boolean recurse)
|
||||||
|
throws IllegalArgumentException {
|
||||||
try {
|
try {
|
||||||
if (workspace == null || storename == null)
|
if (workspace == null || storename == null)
|
||||||
throw new IllegalArgumentException("Arguments may not be null!");
|
throw new IllegalArgumentException("Arguments may not be null!");
|
||||||
if (workspace.isEmpty() || storename.isEmpty())
|
if (workspace.isEmpty() || storename.isEmpty())
|
||||||
throw new IllegalArgumentException("Arguments may not be empty!");
|
throw new IllegalArgumentException(
|
||||||
|
"Arguments may not be empty!");
|
||||||
|
|
||||||
final StringBuilder url = new StringBuilder(restURL);
|
final StringBuilder url = new StringBuilder(restURL);
|
||||||
url.append("/rest/workspaces/").append(workspace)
|
url.append("/rest/workspaces/").append(workspace)
|
||||||
@ -1173,17 +1302,19 @@ public class GeoServerRESTPublisher {
|
|||||||
* The recurse parameter is used to recursively delete all
|
* The recurse parameter is used to recursively delete all
|
||||||
* resources contained by the specified workspace. This includes
|
* resources contained by the specified workspace. This includes
|
||||||
* data stores, coverage stores, feature types, etc... Allowable
|
* data stores, coverage stores, feature types, etc... Allowable
|
||||||
* values for this parameter are “true” or “false”. The default
|
* values for this parameter are <i>true</i> or <i>false</i>. The
|
||||||
* value is “false”.
|
* default value is <i>false</i>.
|
||||||
* @return <TT>true</TT> if the WorkSpace was successfully removed.
|
* @return <TT>true</TT> if the WorkSpace was successfully removed.
|
||||||
*/
|
*/
|
||||||
public boolean removeWorkspace(String workspace, boolean recurse) throws IllegalArgumentException {
|
public boolean removeWorkspace(String workspace, boolean recurse)
|
||||||
|
throws IllegalArgumentException {
|
||||||
workspace = sanitize(workspace);
|
workspace = sanitize(workspace);
|
||||||
try {
|
try {
|
||||||
if (workspace == null)
|
if (workspace == null)
|
||||||
throw new IllegalArgumentException("Arguments may not be null!");
|
throw new IllegalArgumentException("Arguments may not be null!");
|
||||||
if (workspace.isEmpty())
|
if (workspace.isEmpty())
|
||||||
throw new IllegalArgumentException("Arguments may not be empty!");
|
throw new IllegalArgumentException(
|
||||||
|
"Arguments may not be empty!");
|
||||||
|
|
||||||
StringBuffer url = new StringBuffer(restURL).append(
|
StringBuffer url = new StringBuffer(restURL).append(
|
||||||
"/rest/workspaces/").append(workspace);
|
"/rest/workspaces/").append(workspace);
|
||||||
@ -1315,8 +1446,8 @@ public class GeoServerRESTPublisher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows to configure some layer attributes such and DefaultStyle TODO
|
* Allows to configure some layer attributes such and DefaultStyle
|
||||||
* WmsPath
|
* @TODO WmsPath
|
||||||
*/
|
*/
|
||||||
public boolean configureLayer(final String workspace,
|
public boolean configureLayer(final String workspace,
|
||||||
final String layerName, final GSLayerEncoder layer) {
|
final String layerName, final GSLayerEncoder layer) {
|
||||||
@ -1492,7 +1623,8 @@ public class GeoServerRESTPublisher {
|
|||||||
* coverage name (if != null will override the CoverageEncoder
|
* coverage name (if != null will override the CoverageEncoder
|
||||||
* name)
|
* name)
|
||||||
* @return true if success
|
* @return true if success
|
||||||
* @deprecated use {@link GeoServerRESTPublisher#configureCoverage(GSCoverageEncoder, String, String)}
|
* @deprecated use
|
||||||
|
* {@link GeoServerRESTPublisher#configureCoverage(GSCoverageEncoder, String, String)}
|
||||||
*/
|
*/
|
||||||
protected boolean configureCoverage(final GSCoverageEncoder ce,
|
protected boolean configureCoverage(final GSCoverageEncoder ce,
|
||||||
final String wsname, final String csname, String cname) {
|
final String wsname, final String csname, String cname) {
|
||||||
@ -1514,6 +1646,34 @@ public class GeoServerRESTPublisher {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Append params generating a string in the form: <br>
|
||||||
|
* <p>
|
||||||
|
* NAME_0=VALUE_0&NAME_1=VALUE_1&....&NAME_n-1=VALUE_n-1
|
||||||
|
* </p>
|
||||||
|
* </br>
|
||||||
|
*
|
||||||
|
* @param params
|
||||||
|
* an array of NameValuePair
|
||||||
|
* @return the parameter string or empty an string
|
||||||
|
*/
|
||||||
|
private String appendParameters(NameValuePair... params) {
|
||||||
|
StringBuilder sbUrl = new StringBuilder();
|
||||||
|
// append parameters
|
||||||
|
if (params != null) {
|
||||||
|
final int paramsSize = params.length;
|
||||||
|
if (paramsSize > 0) {
|
||||||
|
sbUrl.append(params[0].getName()).append("=")
|
||||||
|
.append(params[0].getValue());
|
||||||
|
for (int i = 1; i < paramsSize; i++) {
|
||||||
|
sbUrl.append("&").append(params[i].getName()).append("=")
|
||||||
|
.append(params[i].getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return sbUrl.toString();
|
||||||
|
}
|
||||||
|
|
||||||
protected String encode(String s) {
|
protected String encode(String s) {
|
||||||
// try {
|
// try {
|
||||||
// return URLEncoder.encode(s,"UTF-8");
|
// return URLEncoder.encode(s,"UTF-8");
|
||||||
|
|||||||
@ -1,478 +0,0 @@
|
|||||||
/*
|
|
||||||
* GeoServer-Manager - Simple Manager Library for GeoServer
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
|
||||||
* http://www.geo-solutions.it
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* 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
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
|
||||||
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
|
||||||
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import org.apache.commons.httpclient.NameValuePair;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.log4j.Logger;
|
|
||||||
import org.jdom.Element;
|
|
||||||
import org.jdom.Namespace;
|
|
||||||
import org.springframework.core.io.ClassPathResource;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Testcase for publishing layers on geoserver.
|
|
||||||
* We need a running GeoServer to properly run the tests.
|
|
||||||
* If such geoserver instance cannot be contacted, tests will be skipped.
|
|
||||||
*
|
|
||||||
* @author etj
|
|
||||||
*/
|
|
||||||
public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
|
||||||
|
|
||||||
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
|
|
||||||
|
|
||||||
public GeoserverRESTPublisherTest(String testName) {
|
|
||||||
super(testName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testWorkspaces() {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
assertEquals(0, reader.getWorkspaces().size());
|
|
||||||
|
|
||||||
assertTrue(publisher.createWorkspace("WS1"));
|
|
||||||
assertTrue(publisher.createWorkspace("WS2"));
|
|
||||||
assertEquals(2, reader.getWorkspaces().size());
|
|
||||||
|
|
||||||
assertFalse(publisher.createWorkspace("WS2"));
|
|
||||||
assertEquals(2, reader.getWorkspaces().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* remove workspace and all of its contents
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public void testWorkspaceRemoval() throws IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
String storeName = "testRESTStoreGeotiff";
|
|
||||||
String layerName = "resttestdem";
|
|
||||||
|
|
||||||
assertTrue(reader.getWorkspaces().isEmpty());
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
assertFalse("Cleanup failed", existsLayer(layerName));
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
|
||||||
|
|
||||||
// remove workspace and all of its contents
|
|
||||||
assertTrue(publisher.removeWorkspace(DEFAULT_WS,true));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testStyles() throws IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
assertEquals(0, reader.getStyles().size());
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// insert style
|
|
||||||
assertTrue(publisher.publishStyle(sldFile));
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
assertFalse(publisher.publishStyle(sldFile));
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
String sld = reader.getSLD(styleName);
|
|
||||||
assertNotNull(sld);
|
|
||||||
|
|
||||||
Element styleEl = JDOMBuilder.buildElement(sld);
|
|
||||||
assertNotNull(styleEl);
|
|
||||||
|
|
||||||
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
|
|
||||||
|
|
||||||
try{
|
|
||||||
|
|
||||||
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS).getChild("Name",SLDNS).getText());
|
|
||||||
assertEquals("STYLE FOR TESTING PURPOSES", styleEl.getChild("NamedLayer", SLDNS).getChild("UserStyle", SLDNS).getChild("Title", SLDNS).getText());
|
|
||||||
} catch(NullPointerException npe) {
|
|
||||||
fail("Error in SLD");
|
|
||||||
}
|
|
||||||
|
|
||||||
// assertEquals(1475, sld.length());
|
|
||||||
|
|
||||||
assertEquals(1, reader.getStyles().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testExternalGeotiff() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) return;
|
|
||||||
deleteAll();
|
|
||||||
|
|
||||||
String storeName = "testRESTStoreGeotiff";
|
|
||||||
String layerName = "resttestdem";
|
|
||||||
|
|
||||||
assertTrue(reader.getWorkspaces().isEmpty());
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
assertFalse("Cleanup failed", existsLayer(layerName));
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
|
||||||
assertNotNull("publish() failed", pc);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
LOGGER.info(pc);
|
|
||||||
RESTCoverageStore reloadedCS = reader.getCoverageStore(DEFAULT_WS, storeName);
|
|
||||||
|
|
||||||
assertEquals(pc.getName(), reloadedCS.getName());
|
|
||||||
assertEquals(pc.getWorkspaceName(), reloadedCS.getWorkspaceName());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
assertTrue("Unpublish() failed", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
|
||||||
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName));
|
|
||||||
assertFalse("Bad unpublish()", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanupTestFT(String layerName, String ns, String storeName) {
|
|
||||||
// dry run delete to work in a known state
|
|
||||||
RESTLayer testLayer = reader.getLayer(layerName);
|
|
||||||
if (testLayer != null) {
|
|
||||||
LOGGER.info("Clearing stale test layer " + layerName);
|
|
||||||
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
|
||||||
if (!ok) {
|
|
||||||
fail("Could not unpublish layer " + layerName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (publisher.removeDatastore(ns, storeName)) {
|
|
||||||
LOGGER.info("Cleared stale datastore " + storeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
assertFalse("Cleanup failed", existsLayer(layerName));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void cleanupTestStyle(final String styleName) {
|
|
||||||
// dry run delete to work in a known state
|
|
||||||
if (reader.existsStyle(styleName)) {
|
|
||||||
LOGGER.info("Clearing stale test style " + styleName);
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
if (!ok) {
|
|
||||||
fail("Could not unpublish style " + styleName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assertFalse("Cleanup failed", reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
deleteAllWorkspaces();
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestFT(layerName, DEFAULT_WS, storeName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
|
|
||||||
// remove also datastore
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName,false);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String ns = "geosolutions";
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
|
||||||
cleanupTestFT(layerName, ns, storeName);
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// insert style
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
// RESTLayer layerDecoder = new RESTLayer(layer);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals("Style not assigned properly", styleName, layer.getDefaultStyle());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
|
|
||||||
// remove also datastore
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(ns, storeName);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
|
|
||||||
//test delete style
|
|
||||||
boolean oksld = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", oksld);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
deleteAllWorkspaces();
|
|
||||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
|
||||||
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestFT(layerName, DEFAULT_WS, storeName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile,"EPSG:4326",new NameValuePair("charset","UTF-8"));
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
|
|
||||||
// remove also datastore
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPublishDeleteStyleString() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
String sldContent = IOUtils.toString(new FileInputStream(sldFile));
|
|
||||||
|
|
||||||
boolean published = publisher.publishStyle(sldContent); // Will take the name from sld contents
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
|
|
||||||
//test delete
|
|
||||||
boolean ok = publisher.removeStyle(styleName);
|
|
||||||
assertTrue("Unpublish() failed", ok);
|
|
||||||
assertFalse(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
String layerName = "this_layer_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.unpublishCoverage(wsName, storeName, layerName);
|
|
||||||
assertFalse("unpublished not existing layer", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
String layerName = "this_layer_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.unpublishFeatureType(wsName, storeName, layerName);
|
|
||||||
assertFalse("unpublished not existing layer", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Assume.assumeTrue(enabled);
|
|
||||||
|
|
||||||
String wsName = "this_ws_does_not_exist";
|
|
||||||
String storeName = "this_store_does_not_exist";
|
|
||||||
|
|
||||||
boolean ok = publisher.removeDatastore(wsName, storeName);
|
|
||||||
assertFalse("removed not existing datastore", ok);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void testUpdateDefaultStyle() throws FileNotFoundException, IOException {
|
|
||||||
if (!enabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String storeName = "resttestshp";
|
|
||||||
String layerName = "cities";
|
|
||||||
|
|
||||||
final String styleName = "restteststyle";
|
|
||||||
{
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName);
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName));
|
|
||||||
}
|
|
||||||
|
|
||||||
final String styleName2 = "restteststyle2";
|
|
||||||
{
|
|
||||||
File sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
|
|
||||||
cleanupTestStyle(styleName2);
|
|
||||||
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
|
||||||
assertTrue("style publish() failed", sldpublished);
|
|
||||||
assertTrue(reader.existsStyle(styleName2));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
|
||||||
|
|
||||||
// known state?
|
|
||||||
cleanupTestFT(layerName, DEFAULT_WS, storeName);
|
|
||||||
|
|
||||||
// test insert
|
|
||||||
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
|
||||||
assertTrue("publish() failed", published);
|
|
||||||
assertTrue(existsLayer(layerName));
|
|
||||||
|
|
||||||
{
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals(styleName, layer.getDefaultStyle());
|
|
||||||
}
|
|
||||||
|
|
||||||
GSLayerEncoder le = new GSLayerEncoder();
|
|
||||||
le.addDefaultStyle(styleName2);
|
|
||||||
publisher.configureLayer(DEFAULT_WS, layerName, le);
|
|
||||||
|
|
||||||
{
|
|
||||||
RESTLayer layer = reader.getLayer(layerName);
|
|
||||||
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
|
||||||
assertEquals(styleName2, layer.getDefaultStyle());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// remove layer and datastore
|
|
||||||
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
|
||||||
assertFalse(existsLayer(layerName));
|
|
||||||
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
|
|
||||||
assertTrue("removeDatastore() failed", dsRemoved);
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
|
||||||
// String wsName = "this_ws_does_not_exist";
|
|
||||||
// String storeName = "this_store_does_not_exist";
|
|
||||||
// String layerName = "this_layer_does_not_exist";
|
|
||||||
//
|
|
||||||
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
|
||||||
// assertFalse("unpublished not existing layer", ok);
|
|
||||||
// }
|
|
||||||
private boolean existsLayer(String layername) {
|
|
||||||
return reader.getLayer(layername) != null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -284,4 +284,8 @@ public abstract class GeoserverRESTTest extends TestCase {
|
|||||||
removed);
|
removed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean existsLayer(String layername) {
|
||||||
|
return reader.getLayer(layername) != null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTGeoTiffTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTGeoTiffTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testExternalGeotiff() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
||||||
|
assertNotNull("publish() failed", pc);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
LOGGER.info(pc);
|
||||||
|
RESTCoverageStore reloadedCS = reader.getCoverageStore(DEFAULT_WS, storeName);
|
||||||
|
|
||||||
|
assertEquals(pc.getName(), reloadedCS.getName());
|
||||||
|
assertEquals(pc.getWorkspaceName(), reloadedCS.getWorkspaceName());
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
assertTrue("Unpublish() failed", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName));
|
||||||
|
assertFalse("Bad unpublish()", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName));
|
||||||
|
assertFalse(existsLayer(layerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGeotiff() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean pub = publisher.publishGeoTIFF(DEFAULT_WS, storeName, geotiff);
|
||||||
|
|
||||||
|
assertNotNull("publish() failed", pub);
|
||||||
|
|
||||||
|
//delete
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName,true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,9 +23,10 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||||
@ -23,9 +23,10 @@
|
|||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package it.geosolutions.geoserver.rest;
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTPublisherTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTPublisherTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanupTestFT(String layerName, String ns, String storeName) {
|
||||||
|
// dry run delete to work in a known state
|
||||||
|
RESTLayer testLayer = reader.getLayer(layerName);
|
||||||
|
if (testLayer != null) {
|
||||||
|
LOGGER.info("Clearing stale test layer " + layerName);
|
||||||
|
boolean ok = publisher.unpublishFeatureType(ns, storeName, layerName);
|
||||||
|
if (!ok) {
|
||||||
|
fail("Could not unpublish layer " + layerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (publisher.removeDatastore(ns, storeName)) {
|
||||||
|
LOGGER.info("Cleared stale datastore " + storeName);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
String layerName = "this_layer_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.unpublishCoverage(wsName, storeName, layerName);
|
||||||
|
assertFalse("unpublished not existing layer", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
String layerName = "this_layer_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.unpublishFeatureType(wsName, storeName, layerName);
|
||||||
|
assertFalse("unpublished not existing layer", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String wsName = "this_ws_does_not_exist";
|
||||||
|
String storeName = "this_store_does_not_exist";
|
||||||
|
|
||||||
|
boolean ok = publisher.removeDatastore(wsName, storeName);
|
||||||
|
assertFalse("removed not existing datastore", ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
||||||
|
// String wsName = "this_ws_does_not_exist";
|
||||||
|
// String storeName = "this_store_does_not_exist";
|
||||||
|
// String layerName = "this_layer_does_not_exist";
|
||||||
|
//
|
||||||
|
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
||||||
|
// assertFalse("unpublished not existing layer", ok);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTShapeTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTShapeTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTShapeTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
deleteAllWorkspaces();
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(existsLayer(layerName));
|
||||||
|
|
||||||
|
// remove also datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName,false);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
|
||||||
|
String ns = "geosolutions";
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
publisher.removeDatastore(DEFAULT_WS, storeName,true);
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
|
||||||
|
// insert style
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(ns, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
// RESTLayer layerDecoder = new RESTLayer(layer);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals("Style not assigned properly", styleName, layer.getDefaultStyle());
|
||||||
|
|
||||||
|
// remove also datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(ns, storeName,true);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
|
||||||
|
//test delete style
|
||||||
|
boolean oksld = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", oksld);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
deleteAllWorkspaces();
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
publisher.removeDatastore(DEFAULT_WS, storeName,true);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile,"EPSG:4326",new NameValuePair("charset","UTF-8"));
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
boolean ok = publisher.unpublishFeatureType(DEFAULT_WS, storeName, layerName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(existsLayer(layerName));
|
||||||
|
|
||||||
|
// remove also datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public void testDeleteUnexistingFT() throws FileNotFoundException, IOException {
|
||||||
|
// String wsName = "this_ws_does_not_exist";
|
||||||
|
// String storeName = "this_store_does_not_exist";
|
||||||
|
// String layerName = "this_layer_does_not_exist";
|
||||||
|
//
|
||||||
|
// boolean ok = publisher.unpublishFT(wsName, storeName, layerName);
|
||||||
|
// assertFalse("unpublished not existing layer", ok);
|
||||||
|
// }
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,213 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTLayer;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.utils.JDOMBuilder;
|
||||||
|
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.jdom.Element;
|
||||||
|
import org.jdom.Namespace;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTStyleTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTStyleTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTStyleTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testStyles() throws IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
assertEquals(0, reader.getStyles().size());
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
|
||||||
|
// insert style
|
||||||
|
assertTrue(publisher.publishStyle(sldFile));
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
assertFalse(publisher.publishStyle(sldFile));
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
String sld = reader.getSLD(styleName);
|
||||||
|
assertNotNull(sld);
|
||||||
|
|
||||||
|
Element styleEl = JDOMBuilder.buildElement(sld);
|
||||||
|
assertNotNull(styleEl);
|
||||||
|
|
||||||
|
Namespace SLDNS = Namespace.getNamespace("sld", "http://www.opengis.net/sld");
|
||||||
|
|
||||||
|
try{
|
||||||
|
|
||||||
|
assertEquals(styleName, styleEl.getChild("NamedLayer", SLDNS).getChild("Name",SLDNS).getText());
|
||||||
|
assertEquals("STYLE FOR TESTING PURPOSES", styleEl.getChild("NamedLayer", SLDNS).getChild("UserStyle", SLDNS).getChild("Title", SLDNS).getText());
|
||||||
|
} catch(NullPointerException npe) {
|
||||||
|
fail("Error in SLD");
|
||||||
|
}
|
||||||
|
|
||||||
|
// assertEquals(1475, sld.length());
|
||||||
|
|
||||||
|
assertEquals(1, reader.getStyles().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void cleanupTestStyle(final String styleName) {
|
||||||
|
// dry run delete to work in a known state
|
||||||
|
if (reader.existsStyle(styleName)) {
|
||||||
|
LOGGER.info("Clearing stale test style " + styleName);
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
if (!ok) {
|
||||||
|
fail("Could not unpublish style " + styleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertFalse("Cleanup failed", reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishDeleteStyleString() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Assume.assumeTrue(enabled);
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
String sldContent = IOUtils.toString(new FileInputStream(sldFile));
|
||||||
|
|
||||||
|
boolean published = publisher.publishStyle(sldContent); // Will take the name from sld contents
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
|
||||||
|
//test delete
|
||||||
|
boolean ok = publisher.removeStyle(styleName);
|
||||||
|
assertTrue("Unpublish() failed", ok);
|
||||||
|
assertFalse(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testUpdateDefaultStyle() throws FileNotFoundException, IOException {
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "resttestshp";
|
||||||
|
String layerName = "cities";
|
||||||
|
|
||||||
|
final String styleName = "restteststyle";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
cleanupTestStyle(styleName);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile); // Will take the name from sld contents
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName));
|
||||||
|
}
|
||||||
|
|
||||||
|
final String styleName2 = "restteststyle2";
|
||||||
|
{
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle2.sld").getFile();
|
||||||
|
cleanupTestStyle(styleName2);
|
||||||
|
boolean sldpublished = publisher.publishStyle(sldFile,styleName2);
|
||||||
|
assertTrue("style publish() failed", sldpublished);
|
||||||
|
assertTrue(reader.existsStyle(styleName2));
|
||||||
|
}
|
||||||
|
|
||||||
|
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
boolean published = publisher.publishShp(DEFAULT_WS, storeName, layerName, zipFile, "EPSG:4326", styleName);
|
||||||
|
assertTrue("publish() failed", published);
|
||||||
|
assertTrue(existsLayer(layerName));
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
GSLayerEncoder le = new GSLayerEncoder();
|
||||||
|
le.setDefaultStyle(styleName2);
|
||||||
|
publisher.configureLayer(DEFAULT_WS, layerName, le);
|
||||||
|
|
||||||
|
{
|
||||||
|
RESTLayer layer = reader.getLayer(layerName);
|
||||||
|
LOGGER.info("Layer style is " + layer.getDefaultStyle());
|
||||||
|
assertEquals(styleName2, layer.getDefaultStyle());
|
||||||
|
}
|
||||||
|
|
||||||
|
// remove layer and datastore
|
||||||
|
boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storeName, true);
|
||||||
|
assertTrue("removeDatastore() failed", dsRemoved);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author etj
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTWorkspaceTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTWorkspaceTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testWorkspaces() {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
assertEquals(0, reader.getWorkspaces().size());
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace("WS1"));
|
||||||
|
assertTrue(publisher.createWorkspace("WS2"));
|
||||||
|
assertEquals(2, reader.getWorkspaces().size());
|
||||||
|
|
||||||
|
assertFalse(publisher.createWorkspace("WS2"));
|
||||||
|
assertEquals(2, reader.getWorkspaces().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove workspace and all of its contents
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public void testWorkspaceRemoval() throws IOException {
|
||||||
|
if (!enabled()) return;
|
||||||
|
deleteAll();
|
||||||
|
|
||||||
|
String storeName = "testRESTStoreGeotiff";
|
||||||
|
String layerName = "resttestdem";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File geotiff = new ClassPathResource("testdata/resttestdem.tif").getFile();
|
||||||
|
|
||||||
|
// known state?
|
||||||
|
assertFalse("Cleanup failed", existsLayer(layerName));
|
||||||
|
|
||||||
|
// test insert
|
||||||
|
RESTCoverageStore pc = publisher.publishExternalGeoTIFF(DEFAULT_WS, storeName, geotiff, null, null);
|
||||||
|
|
||||||
|
// remove workspace and all of its contents
|
||||||
|
assertTrue(publisher.removeWorkspace(DEFAULT_WS,true));
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* GeoServer-Manager - Simple Manager Library for GeoServer
|
||||||
|
*
|
||||||
|
* Copyright (C) 2007,2011 GeoSolutions S.A.S.
|
||||||
|
* http://www.geo-solutions.it
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* 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
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package it.geosolutions.geoserver.rest.publisher;
|
||||||
|
|
||||||
|
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||||
|
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.ParameterConfigure;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.apache.commons.httpclient.NameValuePair;
|
||||||
|
import org.apache.log4j.Logger;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Testcase for publishing layers on geoserver.
|
||||||
|
* We need a running GeoServer to properly run the tests.
|
||||||
|
* If such geoserver instance cannot be contacted, tests will be skipped.
|
||||||
|
*
|
||||||
|
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||||
|
*/
|
||||||
|
public class GeoserverRESTWorldImageTest extends GeoserverRESTTest {
|
||||||
|
|
||||||
|
private final static Logger LOGGER = Logger.getLogger(GeoserverRESTWorldImageTest.class);
|
||||||
|
|
||||||
|
public GeoserverRESTWorldImageTest(String testName) {
|
||||||
|
super(testName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testPublishWorldImage() throws IOException {
|
||||||
|
|
||||||
|
if (!enabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
deleteAll();
|
||||||
|
String storeName = "testWorldimage";
|
||||||
|
|
||||||
|
assertTrue(reader.getWorkspaces().isEmpty());
|
||||||
|
|
||||||
|
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||||
|
|
||||||
|
File worldImageFile = new ClassPathResource(
|
||||||
|
"testdata/sw.zip").getFile();
|
||||||
|
|
||||||
|
// test publish
|
||||||
|
|
||||||
|
boolean wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.NONE, null);
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile with no layer configured, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
// create default style
|
||||||
|
File sldFile = new ClassPathResource("testdata/restteststyle.sld").getFile();
|
||||||
|
assertTrue(publisher.publishStyle(sldFile,"raster"));
|
||||||
|
|
||||||
|
wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.FIRST, new NameValuePair("coverageName", "worldImage_test"));
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile configuring layer name, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
|
||||||
|
wp = publisher.publishWorldImage(DEFAULT_WS, storeName,
|
||||||
|
worldImageFile, ParameterConfigure.ALL,null);
|
||||||
|
|
||||||
|
assertTrue("Publish worldfile configuring all available layers, failed.", wp);
|
||||||
|
|
||||||
|
assertTrue("Unpublish() failed", publisher.removeCoverageStore(DEFAULT_WS, storeName, true));
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
src/test/resources/testdata/sw.zip
vendored
Normal file
BIN
src/test/resources/testdata/sw.zip
vendored
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user