Merge 0220c64288 into d518e9e5a4
This commit is contained in:
commit
de81e2d051
@ -29,14 +29,8 @@ import it.geosolutions.geoserver.rest.decoder.RESTCoverageStore;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTStructuredCoverageGranulesList;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTStyleList;
|
||||
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSBackupEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerGroupEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSNamespaceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.*;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSWorkspaceEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureTypeEncoder;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStructuredGridCoverageReaderManager;
|
||||
@ -587,6 +581,7 @@ public class GeoServerRESTPublisher {
|
||||
* <UL>
|
||||
* <LI>{@link #DATASTORES} vector based data sources.
|
||||
* <LI>{@link #COVERAGESTORES} raster based data sources.
|
||||
* <LI>{@link #WMSSTORES} web map service data store</LI>
|
||||
* </UL>
|
||||
*
|
||||
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
|
||||
@ -600,8 +595,11 @@ public class GeoServerRESTPublisher {
|
||||
* Vector based data sources. Can be a file in the case of a Shapefile, a database connection in the case of PostGIS, or a server in the case
|
||||
* of a remote Web Feature Service.
|
||||
*/
|
||||
DATASTORES;
|
||||
|
||||
DATASTORES,
|
||||
/**
|
||||
* Remote Web Map Service data source
|
||||
*/
|
||||
WMSSTORES;
|
||||
/**
|
||||
* Get the type name of a StoreType with the specified format.
|
||||
*
|
||||
@ -636,6 +634,8 @@ public class GeoServerRESTPublisher {
|
||||
return "coverages"; // Format
|
||||
case DATASTORES:
|
||||
return "featureTypes";
|
||||
case WMSSTORES:
|
||||
return "wmslayers";
|
||||
default:
|
||||
return "coverages";
|
||||
}
|
||||
@ -653,6 +653,8 @@ public class GeoServerRESTPublisher {
|
||||
return "coverageStore"; // Format
|
||||
case DATASTORES:
|
||||
return "dataStore";
|
||||
case WMSSTORES:
|
||||
return "wmsStore";
|
||||
default:
|
||||
return "coverageStore";
|
||||
}
|
||||
@ -1030,6 +1032,66 @@ public class GeoServerRESTPublisher {
|
||||
return published && configured;
|
||||
}
|
||||
|
||||
/**
|
||||
* Publish and configure a new layer from an existing WMS DataStore.
|
||||
*
|
||||
* @param workspace Workspace name where DataStore is.
|
||||
* @param storename DataStore name.
|
||||
* @param lte WMSLayer configuration details using a {@link GSWMSLayerEncoder}.
|
||||
* @return {@code true} if layer is successfully created.
|
||||
*/
|
||||
public boolean publishWMSLayer(final String workspace, final String storename,
|
||||
final GSWMSLayerEncoder lte, final GSLayerEncoder layerEncoder) {
|
||||
/*
|
||||
* This is the equivalent call with cUrl:
|
||||
*
|
||||
* {@code curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \ -d
|
||||
* "<featureType><name>easia_gaul_1_aggr</name><nativeCRS>EPSG:4326</nativeCRS><enabled>true</enabled></featureType>" \
|
||||
* http://localhost:8080/geoserver/rest/workspaces/it.geosolutions/ wmsstores/pg_kids/wmslayers }
|
||||
*
|
||||
* and a PUT to <BR> restURL + "/rest/layers/" workspace + : + layerName
|
||||
*/
|
||||
String ftypeXml = lte.toString();
|
||||
StringBuilder postUrl = new StringBuilder(restURL).append("/rest/workspaces/")
|
||||
.append(workspace).append("/wmsstores/").append(storename).append("/wmslayers");
|
||||
|
||||
final String layername = lte.getName();
|
||||
if (layername == null || layername.isEmpty()) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error("GSWMSLayerEncoder has no valid name associated, try using GSWMSLayerEncoder.setName(String)");
|
||||
return false;
|
||||
}
|
||||
|
||||
String configuredResult = HTTPUtils.postXml(postUrl.toString(), ftypeXml, this.gsuser,
|
||||
this.gspass);
|
||||
boolean published = configuredResult != null;
|
||||
boolean configured = false;
|
||||
|
||||
if (!published) {
|
||||
LOGGER.warn("Error in publishing (" + configuredResult + ") " + workspace + ":"
|
||||
+ storename + "/" + layername);
|
||||
} else {
|
||||
LOGGER.info("WMS layer successfully added (layer:" + layername + ")");
|
||||
|
||||
if (layerEncoder == null) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error("GSLayerEncoder is null: Unable to find the defaultStyle for this layer");
|
||||
return false;
|
||||
}
|
||||
|
||||
configured = configureLayer(workspace, layername, layerEncoder);
|
||||
|
||||
if (!configured) {
|
||||
LOGGER.warn("Error in configuring (" + configuredResult + ") " + workspace + ":"
|
||||
+ storename + "/" + layername);
|
||||
} else {
|
||||
LOGGER.info("WMS layer successfully configured (layer:" + layername + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return published && configured;
|
||||
}
|
||||
|
||||
// ==========================================================================
|
||||
// === SHAPEFILES
|
||||
// ==========================================================================
|
||||
@ -2201,6 +2263,63 @@ public class GeoServerRESTPublisher {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the wms layer.
|
||||
* <P>
|
||||
* You may also want to {@link #removeDatastore(String, String) remove the datastore}.
|
||||
*
|
||||
* @return true if the operation completed successfully.
|
||||
*/
|
||||
public boolean unpublishWmsLayer(String workspace, String storename, String layerName) {
|
||||
try {
|
||||
|
||||
final String fqLayerName;
|
||||
// this null check is here only for backward compatibility.
|
||||
// workspace
|
||||
// shall be mandatory.
|
||||
if (workspace == null) {
|
||||
|
||||
fqLayerName = layerName;
|
||||
|
||||
if (LOGGER.isWarnEnabled()) {
|
||||
LOGGER.warn("Null workspace while configuring layer : " + layerName
|
||||
+ " -- This behavior is deprecated.");
|
||||
}
|
||||
} else {
|
||||
fqLayerName = workspace + ":" + layerName;
|
||||
}
|
||||
// delete related layer
|
||||
URL deleteLayerUrl = new URL(restURL + "/rest/layers/" + fqLayerName);
|
||||
boolean layerDeleted = HTTPUtils
|
||||
.delete(deleteLayerUrl.toExternalForm(), gsuser, gspass);
|
||||
if (!layerDeleted) {
|
||||
LOGGER.warn("Could not delete layer '" + fqLayerName + "'");
|
||||
return false;
|
||||
}
|
||||
// delete the wms layer
|
||||
URL deleteFtUrl = new URL(restURL + "/rest/workspaces/" + workspace + "/wmsstores/"
|
||||
+ storename + "/wmslayers/" + layerName);
|
||||
boolean ftDeleted = HTTPUtils.delete(deleteFtUrl.toExternalForm(), gsuser, gspass);
|
||||
if (!ftDeleted) {
|
||||
LOGGER.warn("Could not delete wms layer " + workspace + ":" + storename + "/"
|
||||
+ layerName + ", but layer was deleted.");
|
||||
} else {
|
||||
LOGGER.info("Wms layer successfully deleted " + workspace + ":" + storename + "/"
|
||||
+ layerName);
|
||||
}
|
||||
|
||||
return ftDeleted;
|
||||
|
||||
// the store is still there: should we delete it?
|
||||
|
||||
} catch (MalformedURLException ex) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error(ex.getLocalizedMessage(), ex);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the featuretype and the associated layer.
|
||||
* <P>
|
||||
@ -2818,6 +2937,79 @@ public class GeoServerRESTPublisher {
|
||||
return sendResult != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure an existing coverage in a given workspace and coverage store
|
||||
*
|
||||
* @param ce contains the coverage name to configure and the configuration to apply
|
||||
* @param wsname the workspace to search for existent coverage
|
||||
* @param csname the coverage store to search for existent coverage
|
||||
* @return true if success
|
||||
*/
|
||||
public boolean configureWmsLayer(final GSCoverageEncoder ce, final String wsname,
|
||||
final String wmsStoreName) {
|
||||
return configureWmsLayer(ce, wsname, wmsStoreName, ce.getName());
|
||||
}
|
||||
|
||||
private boolean configureWmsLayer(GSCoverageEncoder ce, String wsname, String wmsStoreName, String layerName) {
|
||||
if (wsname == null) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error("Unable to configure a wmsstore with no name try using GSCoverageEncoder.setName(String)");
|
||||
return false;
|
||||
}
|
||||
// retrieve coverage name
|
||||
GeoServerRESTReader reader;
|
||||
try {
|
||||
reader = new GeoServerRESTReader(restURL, gsuser, gspass);
|
||||
} catch (MalformedURLException e) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error(e.getLocalizedMessage(), e);
|
||||
return false;
|
||||
}
|
||||
|
||||
// optimized search, left the old code for reference
|
||||
RESTCoverage coverage = reader.getCoverage(wsname, wmsStoreName, layerName);
|
||||
// final RESTCoverageList covList = reader.getCoverages(wsname, csname);
|
||||
// if (covList==null||covList.isEmpty()) {
|
||||
// if (LOGGER.isErrorEnabled())
|
||||
// LOGGER.error("No coverages found in new coveragestore " + csname);
|
||||
// return false;
|
||||
// }
|
||||
// final Iterator<NameLinkElem> it = covList.iterator();
|
||||
// while (it.hasNext()) {
|
||||
// NameLinkElem nameElem = it.next();
|
||||
// if (nameElem.getName().equals(coverageName)) {
|
||||
// found = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if no coverage to configure is found return false
|
||||
if (coverage==null) {
|
||||
if (LOGGER.isErrorEnabled())
|
||||
LOGGER.error("No layers found in new coveragestore " + wmsStoreName + " called "
|
||||
+ layerName);
|
||||
return false;
|
||||
}
|
||||
|
||||
// configure the selected coverage
|
||||
final String url = restURL + "/rest/workspaces/" + wsname + "/wmsstores/" + wmsStoreName
|
||||
+ "/wmslayers/" + layerName + ".xml";
|
||||
|
||||
final String xmlBody = ce.toString();
|
||||
final String sendResult = HTTPUtils.putXml(url, xmlBody, gsuser, gspass);
|
||||
if (sendResult != null) {
|
||||
if (LOGGER.isDebugEnabled()) {
|
||||
LOGGER.debug("Wms layer successfully configured " + wsname + ":" + wmsStoreName + ":"
|
||||
+ layerName);
|
||||
}
|
||||
} else {
|
||||
if (LOGGER.isWarnEnabled())
|
||||
LOGGER.warn("Error configuring coverage " + wsname + ":" + wmsStoreName + ":" + layerName
|
||||
+ " (" + sendResult + ")");
|
||||
}
|
||||
|
||||
return sendResult != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use {@link #createCoverage(String, String, GSCoverageEncoder)}
|
||||
*/
|
||||
|
||||
@ -0,0 +1,76 @@
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.FeatureTypeAttribute;
|
||||
import it.geosolutions.geoserver.rest.encoder.feature.GSAttributeEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.GSFeatureDimensionInfoEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.metadata.virtualtable.GSVirtualTableEncoder;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* Created by drakiko on 02/09/2015.
|
||||
*/
|
||||
public class GSWMSLayerEncoder extends GSResourceEncoder {
|
||||
|
||||
public final static String ATTRIBUTES = "attributes";
|
||||
|
||||
final private Element attributes = new Element(ATTRIBUTES);
|
||||
|
||||
public GSWMSLayerEncoder() {
|
||||
super("wmsLayer");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link GSResourceEncoder#addMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||
* @param key
|
||||
* @param dimensionInfo
|
||||
*
|
||||
*/
|
||||
protected void addMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
||||
super.addMetadata(key, dimensionInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link GSResourceEncoder#setMetadataDimension(String, GSDimensionInfoEncoder)} this method will be removed soon
|
||||
* @param key
|
||||
* @param dimensionInfo
|
||||
*
|
||||
*/
|
||||
public void setMetadata(String key, GSFeatureDimensionInfoEncoder dimensionInfo) {
|
||||
super.setMetadata(key, dimensionInfo);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* delete a keyword from the list
|
||||
*
|
||||
* @param keyword
|
||||
* @return true if something is removed, false otherwise
|
||||
*/
|
||||
public boolean delAttribute(final String keyword) {
|
||||
final Element el = new Element("string");
|
||||
el.setText(keyword);
|
||||
return (attributes.removeContent(GSAttributeEncoder.getFilterByName(keyword))).size() == 0 ? false
|
||||
: true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute the attribute to add
|
||||
*/
|
||||
protected void addAttribute(GSAttributeEncoder attribute) {
|
||||
attributes.addContent(attribute.getRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param attribute the attribute to set (overriding an attribute with the same name if present)
|
||||
*/
|
||||
public void setAttribute(GSAttributeEncoder attribute) {
|
||||
delAttribute(attribute.getAttribute(FeatureTypeAttribute.name));
|
||||
addAttribute(attribute);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,114 @@
|
||||
package it.geosolutions.geoserver.rest.encoder.wmsstore;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* Created by drakiko on 15/09/2015.
|
||||
*/
|
||||
public class GSWmsStoreEncoder extends GSAbstractStoreEncoder {
|
||||
|
||||
static final String TYPE = "WMS";
|
||||
|
||||
final static String ROOT = "wmsStore";
|
||||
|
||||
static final String DEFAULT_MIN_CONNECTIONS = "1";
|
||||
static final String DEFAULT_MAX_CONNECTIONS = "6";
|
||||
static final String DEFAULT_CONNECTION_TIMEOUT = "30";
|
||||
static final String DEFAULT_READ_TIMEOUT = "60";
|
||||
|
||||
|
||||
public GSWmsStoreEncoder(String storeName, URL url) {
|
||||
super(GeoServerRESTPublisher.StoreType.WMSSTORES, ROOT);
|
||||
setType(TYPE);
|
||||
ensureValidName(storeName);
|
||||
setName(storeName);
|
||||
|
||||
ensureValidURL(url);
|
||||
setCapabilitiesURL(url.toString());
|
||||
|
||||
setMaxConnections(DEFAULT_MAX_CONNECTIONS);
|
||||
setConnectTimeout(DEFAULT_CONNECTION_TIMEOUT);
|
||||
setReadTimeout(DEFAULT_READ_TIMEOUT);
|
||||
}
|
||||
|
||||
public void setCapabilitiesURL(String capabilitiesURL){
|
||||
set("capabilitiesURL", capabilitiesURL);
|
||||
}
|
||||
|
||||
public String getCapabilitiesURL(){
|
||||
Element e = ElementUtils.contains(getRoot(), "capabilitiesURL");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
set("user", user);
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
Element e = ElementUtils.contains(getRoot(), "user");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
set("password", password);
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
Element e = ElementUtils.contains(getRoot(), "password");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
|
||||
public void setMaxConnections(String maxConnections) {
|
||||
set("maxConnections", maxConnections);
|
||||
}
|
||||
|
||||
public String getMaxConnections() {
|
||||
Element e = ElementUtils.contains(getRoot(), "maxConnections");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
|
||||
public void setReadTimeout(String readTimeout) {
|
||||
set("readTimeout", readTimeout);
|
||||
}
|
||||
|
||||
public String getReadTimeout() {
|
||||
Element e = ElementUtils.contains(getRoot(), "readTimeout");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
|
||||
public void setConnectTimeout(String connectTimeout) {
|
||||
set("connectTimeout", connectTimeout);
|
||||
}
|
||||
|
||||
public String getConnectTimeout() {
|
||||
Element e = ElementUtils.contains(getRoot(), "connectTimeout");
|
||||
return e!=null?e.getTextTrim():null;
|
||||
}
|
||||
/**
|
||||
* @return {@value #TYPE}
|
||||
*/
|
||||
protected String getValidType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check url validity.
|
||||
*
|
||||
* @param url the url
|
||||
* @throws IllegalArgumentException if url is null or empty
|
||||
*/
|
||||
private static void ensureValidURL(URL url) {
|
||||
if (url == null || url.toString().isEmpty()) {
|
||||
throw new IllegalArgumentException(
|
||||
"Wms store URL cannot be null or empty");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,49 @@
|
||||
package it.geosolutions.geoserver.rest.encoder;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* Created by drakiko on 14/09/2015.
|
||||
*/
|
||||
public class GSWMSLayerEncoderTest {
|
||||
|
||||
GSWMSLayerEncoder gswmsLayerEncoder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
gswmsLayerEncoder = new GSWMSLayerEncoder();
|
||||
|
||||
gswmsLayerEncoder.setName("WMS_NAME");
|
||||
|
||||
gswmsLayerEncoder.setNativeName("WMS_NATIVE_NAME");
|
||||
gswmsLayerEncoder.setTitle("WMS_TITLE");
|
||||
gswmsLayerEncoder.setNativeCRS("EPSG:4326");
|
||||
gswmsLayerEncoder.setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link GSWMSLayerEncoder#GSWMSLayerEncoder()}.
|
||||
*/
|
||||
@Test
|
||||
public void testProperties() {
|
||||
Assert.assertEquals(
|
||||
true,
|
||||
Boolean.parseBoolean(gswmsLayerEncoder.getRoot().getChild("enabled")
|
||||
.getValue()));
|
||||
Assert.assertEquals(
|
||||
"WMS_NAME",
|
||||
gswmsLayerEncoder.getRoot().getChild("name").getValue());
|
||||
Assert.assertEquals(
|
||||
"WMS_NATIVE_NAME",
|
||||
gswmsLayerEncoder.getRoot().getChild("nativeName").getValue());
|
||||
Assert.assertEquals(
|
||||
"WMS_TITLE",
|
||||
gswmsLayerEncoder.getRoot().getChild("title").getValue());
|
||||
Assert.assertEquals(
|
||||
"EPSG:4326",
|
||||
gswmsLayerEncoder.getRoot().getChild("nativeCRS").getValue());
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,68 @@
|
||||
package it.geosolutions.geoserver.rest.publisher;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSWMSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Testcase for publishing wms 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 draktina
|
||||
*/
|
||||
public class GeoserverRESTPublisherWmsTest extends GeoserverRESTTest {
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPublisherWmsTest.class);
|
||||
|
||||
|
||||
@After
|
||||
public void cleanUp(){
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPublishUnexistingWmsLayer(){
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String wsName = "this_ws_does_not_exist";
|
||||
String storeName = "this_store_does_not_exist";
|
||||
String layerName ="this_layer_does_not_exist";
|
||||
|
||||
GSWMSLayerEncoder gswmsLayerEncoder = new GSWMSLayerEncoder();
|
||||
gswmsLayerEncoder.setName(layerName);
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
|
||||
boolean ok = publisher.publishWMSLayer(wsName, storeName, gswmsLayerEncoder, layerEncoder);
|
||||
assertFalse("added not existing layer", ok);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUnpublishUnexistingWmsLayer() throws IOException {
|
||||
if (!enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
String wsName = "this_ws_does_not_exist";
|
||||
String storeName = "this_store_does_not_exist";
|
||||
String layerName ="this_layer_does_not_exist";
|
||||
|
||||
boolean ok = publisher.unpublishWmsLayer(wsName, storeName, layerName);
|
||||
assertFalse("removed not existing layer", ok);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
package it.geosolutions.geoserver.rest.wmsstore;
|
||||
|
||||
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.wmsstore.GSWmsStoreEncoder;
|
||||
import java.net.URL;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
/**
|
||||
* Created by drakiko on 15/09/2015.
|
||||
*/
|
||||
public class WmsStoreEncoderTest extends WmsStoreIntegrationTest{
|
||||
|
||||
public WmsStoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
|
||||
super(System.getProperty("wmsIgnore", "true").equalsIgnoreCase("true"));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public GSAbstractStoreEncoder getStoreEncoderTest() {
|
||||
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(System.getProperty("wmsStoreUrl", "test"));
|
||||
} catch (MalformedURLException e) {
|
||||
//
|
||||
}
|
||||
|
||||
GSWmsStoreEncoder wmsStoreEncoder = new GSWmsStoreEncoder(System.getProperty("wmsDataStoreName", "testWmsIntegration"), url);
|
||||
|
||||
wmsStoreEncoder.setEnabled(true);
|
||||
|
||||
return wmsStoreEncoder;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,166 @@
|
||||
package it.geosolutions.geoserver.rest.wmsstore;
|
||||
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import it.geosolutions.geoserver.rest.decoder.RESTWmsStore;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.GSWMSLayerEncoder;
|
||||
import it.geosolutions.geoserver.rest.encoder.wmsstore.GSWmsStoreEncoder;
|
||||
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* <P>
|
||||
* Since these tests require a running Store instance, this is more like integration tests.<br/>
|
||||
*
|
||||
* For testing that a wmsstore is properly configured, a layer publication has to be attempted
|
||||
*
|
||||
* @see GeoserverRESTTest
|
||||
*/
|
||||
public abstract class WmsStoreIntegrationTest extends GeoserverRESTTest {
|
||||
|
||||
protected final GeoServerRESTStoreManager storeManager;
|
||||
|
||||
/**
|
||||
* ignore integration tests
|
||||
*/
|
||||
protected final boolean ignore;
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(WmsStoreIntegrationTest.class);
|
||||
|
||||
public boolean isIgnore() {
|
||||
return ignore;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param ignore true if this test should be disabled
|
||||
* @throws IllegalArgumentException
|
||||
* @throws MalformedURLException
|
||||
*/
|
||||
public WmsStoreIntegrationTest(boolean ignore) throws IllegalArgumentException,
|
||||
MalformedURLException {
|
||||
super();
|
||||
this.storeManager = new GeoServerRESTStoreManager(URL, RESTUSER, RESTPW);
|
||||
this.ignore = ignore;
|
||||
}
|
||||
|
||||
public abstract GSAbstractStoreEncoder getStoreEncoderTest();
|
||||
|
||||
@Test
|
||||
public void testCreateWmsStore() throws IllegalArgumentException, MalformedURLException {
|
||||
if (!enabled() || ignore) {
|
||||
return;
|
||||
}
|
||||
// deleteAll();
|
||||
|
||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||
|
||||
// creation test
|
||||
GSAbstractStoreEncoder storeEncoder = getStoreEncoderTest();
|
||||
|
||||
String storeName = storeEncoder.getName();
|
||||
// String description = storeEncoder.getDescription();
|
||||
|
||||
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
|
||||
|
||||
assertTrue("*** store " + storeName + " has not been created.", created);
|
||||
|
||||
RESTWmsStore wmsStore = reader.getWmsStore(DEFAULT_WS, storeName);
|
||||
assertNotNull(wmsStore);
|
||||
|
||||
// check if the wmsstore is properly configured in GS for publishing layers
|
||||
String layername = "wmsStoreLayer";
|
||||
|
||||
if (storeEncoder instanceof GSWmsStoreEncoder)
|
||||
layername = layername.toUpperCase();
|
||||
|
||||
GSWMSLayerEncoder fte = new GSWMSLayerEncoder();
|
||||
fte.setName(layername);
|
||||
fte.setNativeName(layername);
|
||||
fte.setTitle(layername);
|
||||
fte.setNativeCRS("EPSG:4326");
|
||||
fte.setEnabled(true);
|
||||
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setEnabled(true);
|
||||
layerEncoder.setQueryable(true);
|
||||
layerEncoder.setDefaultStyle("polygon");
|
||||
|
||||
boolean published = publisher.publishWMSLayer(DEFAULT_WS, storeName, fte, layerEncoder);
|
||||
|
||||
assertTrue("*** Test layer " + layername
|
||||
+ " has not been published. Problem in wms store configuration", published);
|
||||
|
||||
// removing test
|
||||
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
|
||||
assertTrue("*** Wmsstore " + storeName + " has not been removed.", removed);
|
||||
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnpublishWmsStore() throws IllegalArgumentException, MalformedURLException {
|
||||
if (!enabled() || ignore) {
|
||||
return;
|
||||
}
|
||||
// deleteAll();
|
||||
|
||||
assertTrue(publisher.createWorkspace(DEFAULT_WS));
|
||||
|
||||
// creation test
|
||||
GSAbstractStoreEncoder storeEncoder = getStoreEncoderTest();
|
||||
|
||||
String storeName = storeEncoder.getName();
|
||||
// String description = storeEncoder.getDescription();
|
||||
|
||||
boolean created = storeManager.create(DEFAULT_WS, storeEncoder);
|
||||
|
||||
assertTrue("*** store " + storeName + " has not been created.", created);
|
||||
|
||||
RESTWmsStore wmsStore = reader.getWmsStore(DEFAULT_WS, storeName);
|
||||
assertNotNull(wmsStore);
|
||||
|
||||
// check if the wmsstore is properly configured in GS for publishing layers
|
||||
String layername = "wmsStoreLayer";
|
||||
|
||||
if (storeEncoder instanceof GSWmsStoreEncoder)
|
||||
layername = layername.toUpperCase();
|
||||
|
||||
GSWMSLayerEncoder fte = new GSWMSLayerEncoder();
|
||||
fte.setName(layername);
|
||||
fte.setNativeName(layername);
|
||||
fte.setTitle(layername);
|
||||
fte.setNativeCRS("EPSG:4326");
|
||||
fte.setEnabled(true);
|
||||
|
||||
GSLayerEncoder layerEncoder = new GSLayerEncoder();
|
||||
layerEncoder.setEnabled(true);
|
||||
layerEncoder.setQueryable(true);
|
||||
layerEncoder.setDefaultStyle("polygon");
|
||||
|
||||
boolean published = publisher.publishWMSLayer(DEFAULT_WS, storeName, fte, layerEncoder);
|
||||
|
||||
assertTrue("*** Test layer " + layername
|
||||
+ " has not been published. Problem in wms store configuration", published);
|
||||
|
||||
boolean unpublished = publisher.unpublishWmsLayer(DEFAULT_WS, storeName, layername);
|
||||
|
||||
assertTrue("*** Test layer " + layername
|
||||
+ " has not been unpublished. Problem in wms store configuration", unpublished);
|
||||
|
||||
|
||||
// removing test
|
||||
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
|
||||
assertTrue("*** Wmsstore " + storeName + " has not been removed.", removed);
|
||||
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user