* Since these tests require a running arcsde instance, this is more like integration tests.
* You may skip them by defining
- * -DpgIgnore=true
- * When pgIgnore is defined that way, failing tests will not break
- * the build: they will be logged as errors instead.
- *
+ * -DpgIgnore=true When pgIgnore is defined that way, failing tests will not break the build: they will be logged as
+ * errors instead.
+ *
*
- * The target arcsde instance can be customized by defining the following env vars:
+ * The target arcsde instance can be customized by defining the following env vars:
+ *
* - pgHost (default localhost)
* - pgPort (default: 5432)
* - pgDatabase (default: test)
@@ -50,76 +49,30 @@ import org.slf4j.LoggerFactory;
* - pgUser (default: utest)
* - pgPassword (default: ptest)
*
- *
+ *
* @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;
}
}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java
index b470860..263fcee 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java
@@ -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;
}
+
}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/datastore/StoreIntegrationTest.java b/src/test/java/it/geosolutions/geoserver/rest/datastore/StoreIntegrationTest.java
new file mode 100644
index 0000000..fab7cb7
--- /dev/null
+++ b/src/test/java/it/geosolutions/geoserver/rest/datastore/StoreIntegrationTest.java
@@ -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;
+
+/**
+ *
+ * Since these tests require a running Store instance, this is more like integration tests.
+ *
+ * @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));
+ }
+}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java b/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java
index 82273a6..8d121d3 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java
@@ -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):
+ *
+ *
+ * - Tests all the constructors and setters from {@link GSDirectoryOfShapefilesDatastoreEncoder} and parent classes (
+ * {@link GSShapefileDatastoreEncoder}, {@link GSAbstractDatastoreEncoder}).
+ *
+ *
- Tests constructors and getters from {@link RESTDataStore} (reader).
+ *
+ *
- Tests {@link GeoServerRESTDatastoreManager} create and update methods.
+ *
+ *
+ *
+ * The sequence is:
+ *
+ * - Create a DirectoryOfShapefilesDatastoreEncoder, with default parameters.
+ *
- Publish via GeoServerRESTDatastoreManager.create.
+ *
- Read the datastore from server.
+ *
- Test all parameter values.
+ *
- Create a new Encoder from it.
+ *
- Change all datastore parameter to non-default ones.
+ *
- Update via GeoServerRESTDatastoreManager.update.
+ *
- Read again.
+ *
- Test all new values.
+ *
+ *
+ * @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 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 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");
+ }
}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java
index c809d42..92fc273 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java
@@ -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;
}
-
+
}
diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java
index 3778449..2491f12 100644
--- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java
+++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java
@@ -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";