Remove specific datastore methods from manager implementing a generic StoreManager. Improving Store encoders and integration tests.

This commit is contained in:
ccancellieri 2012-10-18 12:00:47 +02:00
parent f500243712
commit b99c9c356a
17 changed files with 685 additions and 444 deletions

View File

@ -25,7 +25,7 @@
package it.geosolutions.geoserver.rest;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTAbstractManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTDatastoreManager;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException;
import java.net.URL;
@ -39,48 +39,49 @@ import java.net.URL;
* <li>getPublisher() simple, high-level pubhish methods.
* <li>get<i>Foo</i>Manager, full-fledged management of catalog objects.
* </ul>
*
* @author Oscar Fonts
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GeoServerRESTManager extends GeoServerRESTAbstractManager {
private final GeoServerRESTPublisher publisher;
private final GeoServerRESTReader reader;
private final GeoServerRESTDatastoreManager datastoreManager;
/**
* Default constructor.
*
* Indicates connection parameters to remote GeoServer instance.
*
* @param restURL GeoServer REST API endpoint
* @param username GeoServer REST API authorized username
* @param password GeoServer REST API password for the former username
* @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
* @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
*/
public GeoServerRESTManager(URL restURL, String username, String password) throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
// Internal publisher and reader, provide simple access methods.
publisher = new GeoServerRESTPublisher(restURL.toString(), username, password);
reader = new GeoServerRESTReader(restURL, username, password);
// Classes for fine-grained management of catalog components.
datastoreManager = new GeoServerRESTDatastoreManager(restURL, username, password);
}
public GeoServerRESTPublisher getPublisher() {
return publisher;
}
public GeoServerRESTReader getReader() {
return reader;
}
public GeoServerRESTDatastoreManager getDatastoreManager() {
return datastoreManager;
}
private final GeoServerRESTPublisher publisher;
private final GeoServerRESTReader reader;
private final GeoServerRESTStoreManager store;
/**
* Default constructor.
*
* Indicates connection parameters to remote GeoServer instance.
*
* @param restURL GeoServer REST API endpoint
* @param username GeoServer REST API authorized username
* @param password GeoServer REST API password for the former username
* @throws MalformedURLException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
* @throws IllegalArgumentException {@link GeoServerRESTAbstractManager#GeoServerRESTAbstractManager(URL, String, String)}
*/
public GeoServerRESTManager(URL restURL, String username, String password)
throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
// Internal publisher and reader, provide simple access methods.
publisher = new GeoServerRESTPublisher(restURL.toString(), username, password);
reader = new GeoServerRESTReader(restURL, username, password);
store = new GeoServerRESTStoreManager(restURL, gsuser, gspass);
}
public GeoServerRESTPublisher getPublisher() {
return publisher;
}
public GeoServerRESTReader getReader() {
return reader;
}
public GeoServerRESTStoreManager getStoreManager() {
return store;
}
}

View File

@ -36,7 +36,6 @@ 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.GeoServerRESTDatastoreManager;
import java.io.File;
import java.io.FileNotFoundException;
@ -371,7 +370,7 @@ public class GeoServerRESTPublisher {
}
LOGGER.debug("POSTing new style " + name + " to " + sUrl);
String result = HTTPUtils
.post(sUrl, sldFile, "application/vnd.ogc.sld+xml", gsuser, gspass);
.post(sUrl, sldFile, Format.SLD.getContentType(), gsuser, gspass);
return result != null;
}
@ -583,14 +582,40 @@ public class GeoServerRESTPublisher {
}
/**
* Get the type name of a DataStoreType.
* Get the type name of a StoreType.
*
* @param type the DataStoreType.
* @return "featuretypes.xml" for DATASTORES, "coverages.xml" otherwise.
* @param type the StoreType.
* @return "dataStore" for DATASTORES, "coverageStore" otherwise.
*/
public static String getType(StoreType type) {
switch (type) {
case COVERAGESTORES:
return "coverageStore"; // Format
case DATASTORES:
return "dataStore";
default:
return "coverageStore";
}
}
/**
* Get the type name of a StoreType.
*
* @return "featuretypes" for DATASTORES, "coverages" otherwise.
*/
public String getTypeName() {
return getTypeName(this);
}
/**
* Get the type of a StoreType.
*
* @param type the StoreType.
* @return "dataStore" for DATASTORES, "coverageStore" otherwise.
*/
public String getType() {
return getType(this);
}
/**
* Returns a lowercase representation of the parameter value, suitable to construct the rest call.
@ -1342,6 +1367,16 @@ public class GeoServerRESTPublisher {
}
}
/**
* Gets the mime type from a format.
*
* @param f the format key.
* @return The content-type (mime), or {@code null} if not in the enum.
*/
public String getContentType() {
return getContentType(this);
}
/**
* Returns a lowercase representation of the parameter. Useful when constructing the REST request.
*/

View File

@ -0,0 +1,121 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 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.encoder;
import org.jdom.Element;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
/**
* Generic Store encoder.
*
* Provides getters and setters for parameters common to all CoverageStore.
*
* @author Carlo Cancellieri - GeoSolutions
*/
public abstract class GSAbstractStoreEncoder extends PropertyXMLEncoder {
private final GeoServerRESTPublisher.StoreType type;
protected GSAbstractStoreEncoder(GeoServerRESTPublisher.StoreType type, String storeName) {
super(type.getType());
this.type=type;
}
public StoreType getStoreType() {
return this.type;
}
public void setType(String type) {
set("type", type);
}
public String getType() {
return ElementUtils.contains(getRoot(), "name").getTextTrim();
}
public void setName(String name) {
ensureValidName(name);
set("name", name);
}
public String getName() {
Element e = ElementUtils.contains(getRoot(), "name");
return e!=null?e.getTextTrim():null;
}
public void setDescription(String description) {
set("description", description);
}
public String getDescription() {
Element e = ElementUtils.contains(getRoot(), "description");
return e!=null?e.getTextTrim():null;
}
public void setEnabled(boolean enabled) {
set("enabled", Boolean.toString(enabled));
}
public boolean getEnabled() {
Element e = ElementUtils.contains(getRoot(), "name");
if (e!=null)
return Boolean.parseBoolean(e.getTextTrim());
else
return false;
}
/**
* Check name validity.
*
* @param name the name
* @throws IllegalArgumentException if name is null or empty
*/
protected void ensureValidName(String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException("Store name cannot be null or empty");
}
}
/**
* Check type validity.
*
* @param type the type.
* @throws IllegalArgumentException if type is not {@value #TYPE}
*/
protected void ensureValidType(String type) {
if (!type.equals(getValidType())) {
throw new IllegalArgumentException("The store type '" + type + "' is not valid");
}
}
/**
* The type of the implementing store.
*/
protected abstract String getValidType();
}

View File

@ -0,0 +1,49 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 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.encoder.coverage;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.StoreType;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
/**
* Generic CoverageStore encoder.
*
* Provides getters and setters for parameters common to all CoverageStore.
*
* @author Carlo Cancellieri - GeoSolutions
*
* @deprecated TODO complete specialization
*/
public abstract class GSAbstractCoveragestoreEncoder extends GSAbstractStoreEncoder {
protected GSAbstractCoveragestoreEncoder(String storeName) {
super(StoreType.COVERAGESTORES,storeName);
// Add mandatory parameter
ensureValidName(storeName);
setName(storeName);
}
}

View File

@ -24,38 +24,37 @@
*/
package it.geosolutions.geoserver.rest.encoder.datastore;
import java.util.Map;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.utils.ElementUtils;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.NestedElementEncoder;
import it.geosolutions.geoserver.rest.encoder.utils.PropertyXMLEncoder;
import java.util.Map;
/**
* Generic Datastore encoder.
*
* Provides getters and setters for parameters common to all Datastores,
* an internal placeholder for specific connection parameters, and
* a constructor to read parameters from a {@link RESTDataStore}.
* Provides getters and setters for parameters common to all Datastores, an internal placeholder for specific connection parameters, and a constructor
* to read parameters from a {@link RESTDataStore}.
*
* @author Oscar Fonts
*/
public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
public abstract class GSAbstractDatastoreEncoder extends GSAbstractStoreEncoder {
final static String ROOT = "dataStore";
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
GSAbstractDatastoreEncoder(String storeName) {
super(ROOT);
final static String ROOT = "dataStore";
NestedElementEncoder connectionParameters = new NestedElementEncoder("connectionParameters");
GSAbstractDatastoreEncoder(String storeName) {
super(GeoServerRESTPublisher.StoreType.DATASTORES, ROOT);
// Add mandatory parameter
ensureValidName(storeName);
setName(storeName);
ensureValidName(storeName);
setName(storeName);
// Add connection parameters
addContent(connectionParameters.getRoot());
}
addContent(connectionParameters.getRoot());
}
/**
* Create a {@value #TYPE} datastore encoder from a store read from server.
*
@ -63,84 +62,25 @@ public abstract class GSAbstractDatastoreEncoder extends PropertyXMLEncoder {
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
*/
GSAbstractDatastoreEncoder(RESTDataStore store) {
this(store.getName());
// Match datastore type
ensureValidType(store.getStoreType());
setType(store.getStoreType());
// Copy store parameters
setDescription(store.getDescription());
setEnabled(store.isEnabled());
// Copy connection parameters - bulk
Map<String, String> params = store.getConnectionParameters();
for(String key : params.keySet()) {
connectionParameters.set(key, params.get(key));
}
}
void setType(String type) {
set("type", type);
}
public String getType() {
return ElementUtils.contains(getRoot(), "type").getTextTrim();
}
public void setName(String name) {
ensureValidName(name);
set("name", name);
}
public String getName() {
return ElementUtils.contains(getRoot(), "name").getTextTrim();
this(store.getName());
// Match datastore type
ensureValidType(store.getStoreType());
// Copy store parameters
setDescription(store.getDescription());
setEnabled(store.isEnabled());
// Copy connection parameters - bulk
Map<String, String> params = store.getConnectionParameters();
for (String key : params.keySet()) {
connectionParameters.set(key, params.get(key));
}
}
public void setDescription(String description) {
set("description", description);
}
public String getDescription() {
return ElementUtils.contains(getRoot(), "description").getTextTrim();
}
public void setEnabled(boolean enabled) {
set("enabled", Boolean.toString(enabled));
}
public boolean getEnabled() {
return Boolean.parseBoolean(ElementUtils.contains(getRoot(), "enabled").getTextTrim());
}
/**
* Check name validity.
*
* @param name the name
* @throws IllegalArgumentException if name is null or empty
*/
void ensureValidName(String name) {
if (name == null || name.isEmpty()) {
throw new IllegalArgumentException(
"Store name cannot be null or empty");
}
}
/**
* Check type validity.
*
* @param type the type.
* @throws IllegalArgumentException if type is not {@value #TYPE}
*/
void ensureValidType(String type) {
if (!type.equals(getValidType())) {
throw new IllegalArgumentException(
"The store type '"+ type +"' is not valid");
}
}
/**
* The type of the implementing datastore.
*/
abstract String getValidType();
protected abstract String getValidType();
}

View File

@ -66,7 +66,6 @@ public class GSArcSDEDatastoreEncoder extends GSAbstractDatastoreEncoder {
super(name);
// Set mandatory parameters
setType(TYPE);
setServer(server);
setUser(user);
@ -212,7 +211,7 @@ public class GSArcSDEDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

@ -35,19 +35,18 @@ import java.net.URL;
*/
public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastoreEncoder {
static final String TYPE = "Directory of spatial files (shapefiles)";
static final String TYPE = "Directory of spatial files (shapefiles)";
/**
* Create a {@value #TYPE} datastore with default connection parameters,
* given a store name and a url (the store location).
* Create a {@value #TYPE} datastore with default connection parameters, given a store name and a url (the store location).
*
* @param name New datastore name
* @param url The shapefile location in the server, relative to $GEOSERVER_DATA_DIR.
*/
public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) {
super(name, url);
setType(TYPE);
}
public GSDirectoryOfShapefilesDatastoreEncoder(String name, URL url) {
super(name, url);
setType(TYPE);
}
/**
* Create a {@value #TYPE} datastore encoder from an existing store read from server.
@ -55,14 +54,14 @@ public class GSDirectoryOfShapefilesDatastoreEncoder extends GSShapefileDatastor
* @param store The existing store.
* @throws IllegalArgumentException if store type or mandatory parameters are not valid
*/
public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) {
super(store);
}
public GSDirectoryOfShapefilesDatastoreEncoder(RESTDataStore store) {
super(store);
}
/**
* @return {@value #TYPE}
*/
String getValidType() {
return TYPE;
protected String getValidType() {
return TYPE;
}
}

View File

@ -181,7 +181,7 @@ public class GSOracleNGDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

@ -44,6 +44,10 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
static final boolean DEFAULT_PREPARED_STATEMENTS = false;
static final int DEFAULT_MAX_OPEN_PREPARED_STATEMENTS = 50;
/**
*
* @param name DataStore name
*/
public GSPostGISDatastoreEncoder(String name) {
super(name);
@ -141,7 +145,7 @@ public class GSPostGISDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

@ -157,7 +157,7 @@ public class GSShapefileDatastoreEncoder extends GSAbstractDatastoreEncoder {
/**
* @return {@value #TYPE}
*/
String getValidType() {
protected String getValidType() {
return TYPE;
}
}

View File

@ -24,22 +24,23 @@
*/
package it.geosolutions.geoserver.rest.manager;
import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.Format;
import it.geosolutions.geoserver.rest.HTTPUtils;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import java.net.MalformedURLException;
import java.net.URL;
/**
* Manage datastores.
* Manage stores.
*
* To pass connection parameters, use the encoders derived from
* {@link GSAbstractDatastoreEncoder}.
*
* @author Oscar Fonts
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/
public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager {
public class GeoServerRESTStoreManager extends GeoServerRESTAbstractManager {
/**
* Default constructor.
@ -50,44 +51,73 @@ public class GeoServerRESTDatastoreManager extends GeoServerRESTAbstractManager
* @throws MalformedURLException
* @throws IllegalArgumentException
*/
public GeoServerRESTDatastoreManager(URL restURL, String username, String password)
public GeoServerRESTStoreManager(URL restURL, String username, String password)
throws IllegalArgumentException, MalformedURLException {
super(restURL, username, password);
}
/**
* Create a datastore.
* Create a store.
*
* @param workspace Name of the workspace to contain the datastore. This
* @param workspace Name of the workspace to contain the store. This
* will also be the prefix of any layer names contained in the
* datastore.
* @param datastore the set of parameters to be set to the datastore
* store.
* @param datastore the set of parameters to be set to the store
* (including connection parameters).
* @return <TT>true</TT> if the datastore has been successfully created,
* @return <TT>true</TT> if the store has been successfully created,
* <TT>false</TT> otherwise
*/
public boolean create(String workspace, GSAbstractDatastoreEncoder datastore) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/datastores/").toString();
String xml = datastore.toString();
public boolean create(String workspace, GSAbstractStoreEncoder store) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/", store.getStoreType().toString(),".",Format.XML.toString()).toString();
String xml = store.toString();
String result = HTTPUtils.postXml(sUrl, xml, gsuser, gspass);
return result != null;
}
/**
* Update a datastore.
* Update a store.
*
* @param workspace Name of the workspace that contains the datastore.
* @param datastore the set of parameters to be set to the datastore
* @param workspace Name of the workspace that contains the store.
* @param datastore the set of parameters to be set to the store
* (including connection parameters).
* @return <TT>true</TT> if the datastore has been successfully updated,
* @return <TT>true</TT> if the store has been successfully updated,
* <TT>false</TT> otherwise
*/
public boolean update(String workspace, GSAbstractDatastoreEncoder datastore) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace, "/datastores/",
datastore.getName()).toString();
String xml = datastore.toString();
public boolean update(String workspace, GSAbstractStoreEncoder store) {
String sUrl = HTTPUtils.append(restURL, "/rest/workspaces/", workspace,"/", store.getStoreType().toString(),"/",
store.getName(),".",Format.XML.toString()).toString();
String xml = store.toString();
String result = HTTPUtils.putXml(sUrl, xml, gsuser, gspass);
return result != null;
}
/**
* Remove a given CoverageStore in a given Workspace.
*
* @param workspace The name of the workspace
* @param storename The name of the CoverageStore to remove.
* @param recurse if remove should be performed recursively
* @return <TT>true</TT> if the CoverageStore was successfully removed.
* @throws MalformedURLException
*/
public boolean remove(final String workspace, final GSAbstractStoreEncoder store,
final boolean recurse) throws IllegalArgumentException, MalformedURLException {
// if (workspace == null || storename == null)
// throw new IllegalArgumentException("Arguments may not be null!");
// if (workspace.isEmpty() || storename.isEmpty())
// throw new IllegalArgumentException("Arguments may not be empty!");
final StringBuffer url=HTTPUtils.append(restURL,"/rest/workspaces/",workspace,"/", store.getStoreType().toString(), "/",store.getName());
if (recurse)
url.append("?recurse=true");
final URL deleteStore = new URL(url.toString());
boolean deleted = HTTPUtils.delete(deleteStore.toExternalForm(), gsuser, gspass);
// if (!deleted) {
// LOGGER.warn("Could not delete CoverageStore " + workspace + ":" + storename);
// } else {
// LOGGER.info("CoverageStore successfully deleted " + workspace + ":" + storename);
// }
return deleted;
}
}

View File

@ -24,25 +24,24 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import java.net.MalformedURLException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
/**
* Testcase for creating arcsde-based resources on geoserver.
* <P>
* Since these tests require a running arcsde instance, this is more like integration tests.<br/>
* You may skip them by defining<tt> <pre>
* -DpgIgnore=true </pre></tt>
* When <tt>pgIgnore</tt> is defined that way, failing tests will not break
* the build: they will be logged as errors instead.
*
* -DpgIgnore=true </pre></tt> When <tt>pgIgnore</tt> is defined that way, failing tests will not break the build: they will be logged as
* errors instead.
*
* <P>
* The target arcsde instance can be customized by defining the following env vars: <ul>
* The target arcsde instance can be customized by defining the following env vars:
* <ul>
* <LI><TT>pgHost</TT> (default <TT>localhost</TT>)</LI>
* <LI><TT>pgPort</TT> (default: <TT>5432</TT>)</LI>
* <LI><TT>pgDatabase</TT> (default: <TT>test</TT>)</LI>
@ -50,76 +49,30 @@ import org.slf4j.LoggerFactory;
* <LI><TT>pgUser</TT> (default: <TT>utest</TT>)</LI>
* <LI><TT>pgPassword</TT> (default: <TT>ptest</TT>)</LI>
* </ul>
*
*
* @author etj
* @author Eric Grosso
* @author Gianni Barrotta
*
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest {
public class GSArcSDEDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSArcSDEDatastoreEncoderTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
public GSArcSDEDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
private final boolean pgIgnore;
private final String pgServer;
private final int pgPort;
private final String pgInstance;
private final String pgUser;
private final String pgPassword;
public GSArcSDEDatastoreEncoderTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgServer = System.getProperty("pgServer", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5151"));
pgInstance = System.getProperty("pgInstance", "test");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
super(System.getProperty("Ignore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeleteArcSDEDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestarcsde";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
GSArcSDEDatastoreEncoder datastoreEncoder = new GSArcSDEDatastoreEncoder(
System.getProperty("arcsdeHost", "localhost"),
System.getProperty("arcsdeSchema", "public"), System.getProperty("arcsdePassword", "ptest"));
datastoreEncoder.setNamespace(DEFAULT_WS);
datastoreEncoder.setPort(Integer.parseInt(System.getProperty("arcsdePort", "5432")));
GSArcSDEDatastoreEncoder datastoreEncoder = new GSArcSDEDatastoreEncoder(datastoreName, pgServer, pgUser);
datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace);
datastoreEncoder.setPort(pgPort);
datastoreEncoder.setInstance(pgInstance);
datastoreEncoder.setPassword(pgPassword);
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = manager.getDatastoreManager().create(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("arcsde datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName, true);
if( ! pgIgnore )
assertTrue("arcsde datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName, false));
return datastoreEncoder;
}
}

View File

@ -24,8 +24,11 @@
*/
package it.geosolutions.geoserver.rest.datastore;
import java.net.MalformedURLException;
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.datastore.GSOracleNGDatastoreEncoder;
import org.junit.Test;
@ -54,82 +57,37 @@ import org.slf4j.LoggerFactory;
* @author etj
* @author Eric Grosso
* @author Gianni Barrotta
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest {
public class GSOracleNGDatastoreEncoderTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
private final boolean pgIgnore;
private final String pgHost;
private final int pgPort;
private final String pgDatabase;
private final String pgSchema;
private final String pgUser;
private final String pgPassword;
public GSOracleNGDatastoreEncoderTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
pgDatabase = System.getProperty("pgDatabase", "test");
pgSchema = System.getProperty("pgSchema", "public");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
// private final static Logger LOGGER = LoggerFactory.getLogger(GSOracleNGDatastoreEncoderTest.class);
public GSOracleNGDatastoreEncoderTest() throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeleteOracleNGDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestOracleNG";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
GSOracleNGDatastoreEncoder datastoreEncoder = new GSOracleNGDatastoreEncoder(System.getProperty("oDataStoreName", "test"), System.getProperty("pgDatabase", "test"));
datastoreEncoder.setNamespace(DEFAULT_WS);
datastoreEncoder.setHost(System.getProperty("pgHost", "localhost"));
datastoreEncoder.setPort(Integer.parseInt(System.getProperty("pgPort", "5432")));
datastoreEncoder.setSchema(System.getProperty("pgUser", "postgres"));
datastoreEncoder.setUser(System.getProperty("pgSchema", "public"));
datastoreEncoder.setPassword(System.getProperty("pgPassword", "postgres"));
boolean exposePrimaryKeys = true;
boolean validateConnections = false;
String primaryKeyMetadataTable = "test";
GSOracleNGDatastoreEncoder datastoreEncoder = new GSOracleNGDatastoreEncoder(datastoreName, pgDatabase);
datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace);
datastoreEncoder.setHost(pgHost);
datastoreEncoder.setPort(pgPort);
datastoreEncoder.setSchema(pgSchema);
datastoreEncoder.setUser(pgUser);
datastoreEncoder.setPassword(pgPassword);
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
datastoreEncoder.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = manager.getDatastoreManager().create(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("OracleNG datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName, true);
if( ! pgIgnore )
assertTrue("OracleNG datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName, false));
return datastoreEncoder;
}
}

View File

@ -0,0 +1,114 @@
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 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.datastore;
import java.net.MalformedURLException;
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.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* <P>
* Since these tests require a running Store instance, this is more like integration tests.<br/>
*
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public abstract class StoreIntegrationTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(StoreIntegrationTest.class);
private final GeoServerRESTStoreManager storeManager;
/**
* ignore integration tests
*/
private final boolean ignore;
public boolean isIgnore() {
return ignore;
}
/**
*
* @param ignore false if this test shoudl be disabled
* @throws IllegalArgumentException
* @throws MalformedURLException
*/
public StoreIntegrationTest(boolean ignore) throws IllegalArgumentException, MalformedURLException {
super();
this.storeManager = new GeoServerRESTStoreManager(URL, RESTUSER, RESTPW);
this.ignore=ignore;
}
public abstract GSAbstractStoreEncoder getStoreEncoderTest();
@Test
public void testCreateDeleteDatastore() throws IllegalArgumentException, MalformedURLException {
if (!enabled()) {
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);
if( ! ignore )
assertTrue("Datastore not created", created);
else if( ! created)
LOGGER.error("*** store " + storeName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(DEFAULT_WS, storeName);
assertNotNull(datastore);
LOGGER.info("The type of the created datastore is: " + datastore.getStoreType());
// removing test
boolean removed = storeManager.remove(DEFAULT_WS, storeEncoder, true);
if( ! ignore )
assertTrue("Datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + storeName + " has not been removed.");
assertTrue(publisher.removeWorkspace(DEFAULT_WS, false));
}
}

View File

@ -24,8 +24,9 @@
*/
package it.geosolutions.geoserver.rest.manager;
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder;
@ -62,70 +63,135 @@ import org.junit.Test;
*
* @author Oscar Fonts
*/
public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest {
private static final String WS_NAME = DEFAULT_WS;
private static final String DS_NAME = "testCreateDatastore";
private static final String DS_DESCRIPTION = "A description";
private static URL LOCATION_1;
private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest() throws Exception {
LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2");
}
/*
* GeoServer-Manager - Simple Manager Library for GeoServer
*
* Copyright (C) 2007,2012 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.
*/
@Test
public void test() throws Exception {
/**
* Test datastore handling (create, read and update):
*
* <ul>
* <li>Tests all the constructors and setters from {@link GSDirectoryOfShapefilesDatastoreEncoder} and parent classes (
* {@link GSShapefileDatastoreEncoder}, {@link GSAbstractDatastoreEncoder}).
*
* <li>Tests constructors and getters from {@link RESTDataStore} (reader).
*
* <li>Tests {@link GeoServerRESTDatastoreManager} create and update methods.
* </ul>
*
* <p>
* The sequence is:
* <ol>
* <li>Create a DirectoryOfShapefilesDatastoreEncoder, with default parameters.
* <li>Publish via GeoServerRESTDatastoreManager.create.
* <li>Read the datastore from server.
* <li>Test all parameter values.
* <li>Create a new Encoder from it.
* <li>Change all datastore parameter to non-default ones.
* <li>Update via GeoServerRESTDatastoreManager.update.
* <li>Read again.
* <li>Test all new values.
* </ol>
*
* @author Oscar Fonts
*/
public class GeoserverRESTDatastoreManagerTest extends StoreIntegrationTest {
private static final String WS_NAME = DEFAULT_WS;
private static final String DS_NAME = "testCreateDatastore";
private static final String DS_DESCRIPTION = "A description";
private static URL LOCATION_1;
private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest() throws Exception {
super(true);
LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2");
}
@Override
public GSAbstractStoreEncoder getStoreEncoderTest() {
return new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
}
@Test
public void test() throws Exception {
if (!enabled()) {
return;
}
// Delete all resources except styles
deleteAllWorkspacesRecursively();
// Delete all resources except styles
deleteAllWorkspacesRecursively();
// Create workspace
assertTrue(publisher.createWorkspace(WS_NAME));
// Create a directory of spatial files with default parameters
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(DS_NAME, LOCATION_1);
assertTrue(manager.getDatastoreManager().create(WS_NAME, create));
// Read the store from server; check all parameter values
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getName(), DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), true);
Map<String,String> connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_1.toString());
assertEquals(connParams.get("charset"), "ISO-8859-1");
assertEquals(connParams.get("create spatial index"), "true");
assertEquals(connParams.get("memory mapped buffer"), "false");
assertEquals(connParams.get("cache and reuse memory maps"), "true");
// Change all parameter to non-default values
GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(read);
update.setDescription(DS_DESCRIPTION);
update.setEnabled(false);
update.setUrl(LOCATION_2);
update.setCharset(Charset.forName("UTF-8"));
update.setCreateSpatialIndex(false);
update.setMemoryMappedBuffer(true);
update.setCacheAndReuseMemoryMaps(false);
//update the store
assertTrue(manager.getDatastoreManager().update(WS_NAME, update));
// Read again, check that all parameters have changed
read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), false);
connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_2.toString());
assertEquals(connParams.get("charset"), "UTF-8");
assertEquals(connParams.get("create spatial index"), "false");
assertEquals(connParams.get("memory mapped buffer"), "true");
assertEquals(connParams.get("cache and reuse memory maps"), "false");
}
// Create a directory of spatial files with default parameters
GSDirectoryOfShapefilesDatastoreEncoder create = new GSDirectoryOfShapefilesDatastoreEncoder(
DS_NAME, LOCATION_1);
assertTrue(manager.getStoreManager().create(WS_NAME, create));
// Read the store from server; check all parameter values
RESTDataStore read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getName(), DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), true);
Map<String, String> connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_1.toString());
assertEquals(connParams.get("charset"), "ISO-8859-1");
assertEquals(connParams.get("create spatial index"), "true");
assertEquals(connParams.get("memory mapped buffer"), "false");
assertEquals(connParams.get("cache and reuse memory maps"), "true");
// Change all parameter to non-default values
GSDirectoryOfShapefilesDatastoreEncoder update = new GSDirectoryOfShapefilesDatastoreEncoder(
read);
update.setDescription(DS_DESCRIPTION);
update.setEnabled(false);
update.setUrl(LOCATION_2);
update.setCharset(Charset.forName("UTF-8"));
update.setCreateSpatialIndex(false);
update.setMemoryMappedBuffer(true);
update.setCacheAndReuseMemoryMaps(false);
// update the store
assertTrue(manager.getStoreManager().update(WS_NAME, update));
// Read again, check that all parameters have changed
read = reader.getDatastore(WS_NAME, DS_NAME);
assertEquals(read.getWorkspaceName(), WS_NAME);
assertEquals(read.isEnabled(), false);
connParams = read.getConnectionParameters();
assertEquals(connParams.get("url"), LOCATION_2.toString());
assertEquals(connParams.get("charset"), "UTF-8");
assertEquals(connParams.get("create spatial index"), "false");
assertEquals(connParams.get("memory mapped buffer"), "true");
assertEquals(connParams.get("cache and reuse memory maps"), "false");
}
}

View File

@ -27,10 +27,13 @@ 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.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.datastore.StoreIntegrationTest;
import it.geosolutions.geoserver.rest.encoder.GSAbstractStoreEncoder;
import it.geosolutions.geoserver.rest.encoder.datastore.GSPostGISDatastoreEncoder;
import it.geosolutions.geoserver.rest.manager.GeoServerRESTStoreManager;
import java.net.MalformedURLException;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -55,53 +58,39 @@ import org.slf4j.LoggerFactory;
*
* @author etj
* @author Eric Grosso
* @author carlo cancellieri - GeoSolutions
*
* @see GeoserverRESTTest
*/
public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
public class GeoserverRESTPostgisDatastoreTest extends StoreIntegrationTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPostgisDatastoreTest.class);
private static final String DEFAULT_WS = "it.geosolutions";
private final boolean pgIgnore;
private final String pgHost;
private final int pgPort;
private final String pgDatabase;
private final String pgSchema;
private final String pgUser;
private final String pgPassword;
public GeoserverRESTPostgisDatastoreTest() {
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost");
pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
pgDatabase = System.getProperty("pgDatabase", "test");
pgSchema = System.getProperty("pgSchema", "public");
pgUser = System.getProperty("pgUser", "utest");
pgPassword = System.getProperty("pgPassword", "ptest");
public GeoserverRESTPostgisDatastoreTest()
throws IllegalArgumentException, MalformedURLException {
super(System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"));
}
@Test
public void testCreateDeletePostGISDatastore() {
if (!enabled()) {
return;
}
deleteAll();
String wsName = DEFAULT_WS;
String datastoreName = "resttestpostgis";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
@Override
public GSAbstractStoreEncoder getStoreEncoderTest(){
boolean exposePrimaryKeys = true;
boolean validateConnections = false;
String primaryKeyMetadataTable = "test";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder();
datastoreEncoder.defaultInit();
datastoreEncoder.setName(datastoreName);
String datastoreName = "resttestpostgis";
String description = "description";
String dsNamespace = "http://www.geo-solutions.it";
GSPostGISDatastoreEncoder datastoreEncoder = new GSPostGISDatastoreEncoder(datastoreName);
datastoreEncoder.setDescription(description);
datastoreEncoder.setNamespace(dsNamespace);
String pgHost = System.getProperty("pgHost", "localhost");
int pgPort = Integer.parseInt(System.getProperty("pgPort", "5432"));
String pgDatabase = System.getProperty("pgDatabase", "test");
String pgSchema = System.getProperty("pgSchema", "public");
String pgUser = System.getProperty("pgUser", "utest");
String pgPassword = System.getProperty("pgPassword", "ptest");
datastoreEncoder.setHost(pgHost);
datastoreEncoder.setPort(pgPort);
datastoreEncoder.setDatabase(pgDatabase);
@ -111,29 +100,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
datastoreEncoder.setExposePrimaryKeys(exposePrimaryKeys);
datastoreEncoder.setValidateConnections(validateConnections);
datastoreEncoder.setPrimaryKeyMetadataTable(primaryKeyMetadataTable);
assertTrue(publisher.createWorkspace(wsName));
// creation test
boolean created = publisher.createPostGISDatastore(wsName, datastoreEncoder);
if( ! pgIgnore )
assertTrue("PostGIS datastore not created", created);
else if( ! created)
LOGGER.error("*** Datastore " + datastoreName + " has not been created.");
RESTDataStore datastore = reader.getDatastore(wsName, datastoreName);
LOGGER.info("The type of the created datastore is: " + datastore.getType());
// removing test
boolean removed = publisher.removeDatastore(wsName, datastoreName);
if( ! pgIgnore )
assertTrue("PostGIS datastore not removed", removed);
else if( ! removed )
LOGGER.error("*** Datastore " + datastoreName + " has not been removed.");
assertTrue(publisher.removeWorkspace(wsName));
return datastoreEncoder;
}
}

View File

@ -60,16 +60,14 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
@After
public void cleanUp(){
if(enabled()){
deleteAllWorkspaces();
}
}
@Test
public void testReloadDataStore() throws FileNotFoundException, IOException {
if (!enabled())
return;
deleteAllWorkspacesRecursively();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp";
@ -91,7 +89,8 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) {
return;
}
deleteAllWorkspacesRecursively();
assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp";
@ -126,6 +125,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) {
return;
}
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -159,6 +159,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) {
return;
}
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -192,6 +193,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) {
return;
}
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -236,6 +238,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
if (!enabled()) {
return;
}
deleteAllWorkspacesRecursively();
// Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS));
@ -278,7 +281,8 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
public void testPublishShpUsingDeclaredNativeCRS() throws Exception {
if (!enabled())
return;
deleteAllWorkspacesRecursively();
// layer publication params
String workspace = DEFAULT_WS;
String storename = "resttestshp";
@ -315,7 +319,8 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
public void testPublishShpUsingWKTNativeCRS() throws Exception {
if (!enabled())
return;
deleteAllWorkspacesRecursively();
// layer publication params
String workspace = DEFAULT_WS;
String storename = "resttestshp";