From db5313461016cb322166b5267abddf9e9fede7c2 Mon Sep 17 00:00:00 2001 From: Simone Giannecchini Date: Thu, 9 Aug 2012 17:12:56 +0200 Subject: [PATCH] #34,#35,#33 --- .../rest/GeoServerRESTPublisher.java | 176 ++++++++++++++---- .../geoserver/rest/GeoServerRESTReader.java | 7 +- .../rest/encoder/GSResourceEncoder.java | 18 +- .../geoserver/rest/ConfigTest.java | 32 ++-- .../rest/GeoserverRESTReaderTest.java | 20 +- .../geoserver/rest/GeoserverRESTTest.java | 18 +- .../GSArcSDEDatastoreEncoderTest.java | 5 +- .../GSOracleNGDatastoreEncoderTest.java | 5 +- .../rest/encoder/GSBackupEncoderTest.java | 3 - .../rest/encoder/GSWorkspaceEncoderTest.java | 3 - .../coverage/GSCoverageEncoderTest.java | 24 ++- .../encoder/feature/GSFeatureEncoderTest.java | 3 - .../utils/EntryKeyListEncoderTest.java | 3 +- .../GeoserverRESTDatastoreManagerTest.java | 16 +- .../publisher/GeoserverRESTGeoTiffTest.java | 9 +- .../GeoserverRESTImageMosaicTest.java | 8 +- .../publisher/GeoserverRESTNamespaceTest.java | 6 +- .../GeoserverRESTPostgisDatastoreTest.java | 5 +- ...GeoserverRESTPublishShpCollectionTest.java | 11 +- .../publisher/GeoserverRESTPublisherTest.java | 8 +- .../publisher/GeoserverRESTShapeTest.java | 80 ++++++-- .../publisher/GeoserverRESTStyleTest.java | 9 +- .../publisher/GeoserverRESTWorkspaceTest.java | 7 +- .../GeoserverRESTWorldImageTest.java | 6 +- src/test/resources/testdata/test_noepsg.zip | Bin 0 -> 6037 bytes 25 files changed, 334 insertions(+), 148 deletions(-) create mode 100644 src/test/resources/testdata/test_noepsg.zip diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java index 613b75c..3635208 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTPublisher.java @@ -61,7 +61,9 @@ import org.slf4j.LoggerFactory; */ public class GeoServerRESTPublisher { - /** The logger for this class */ + public static final String DEFAULT_CRS = "EPSG:4326"; + + /** The logger for this class */ private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class); /** @@ -1069,7 +1071,7 @@ public class GeoServerRESTPublisher { /** * Upload an publish a local shapefile. *

- * The defaultCRS will be set to EPSG:4326. + * The SRS will be set to EPSG:4326. * * @see {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)} * @@ -1088,7 +1090,7 @@ public class GeoServerRESTPublisher { */ public boolean publishShp(String workspace, String storename, String datasetname, File zipFile) throws FileNotFoundException, IllegalArgumentException { - return publishShp(workspace, storename, new NameValuePair[0], datasetname,UploadMethod.FILE, zipFile.toURI(), "EPSG:4326", ProjectionPolicy.NONE,null); + return publishShp(workspace, storename, new NameValuePair[0], datasetname,UploadMethod.FILE, zipFile.toURI(), DEFAULT_CRS,null); } /** @@ -1116,7 +1118,9 @@ public class GeoServerRESTPublisher { *

  • A zip file if 'method' is uri (UNTESTED)
  • * * @param srs - * the native CRS + * the SRS for this shapefile. It must be an ESPG code or GeoServer will choke. + * @param nativeCRS + * the nativeCRS for this shapefile. It can be an EPSG code (for {@link ProjectionPolicy#NONE} or a WKT for {@link ProjectionPolicy#REPROJECT_TO_DECLARED}. * @param policy * {@link ProjectionPolicy} * @param defaultStyle @@ -1130,11 +1134,33 @@ public class GeoServerRESTPublisher { */ public boolean publishShp(String workspace, String storeName, NameValuePair[] storeParams, String datasetName, UploadMethod method, URI shapefile, - String srs, ProjectionPolicy policy, String defaultStyle) + String srs, String nativeCRS, ProjectionPolicy policy, String defaultStyle) throws FileNotFoundException, IllegalArgumentException { if (workspace == null || storeName == null || shapefile == null - || datasetName == null || srs == null || policy == null) + || datasetName == null || policy == null){ throw new IllegalArgumentException("Unable to run: null parameter"); + } + + // + // SRS Policy Management + // + boolean srsNull=!(srs!=null&&srs.length()!=0); + boolean nativeSrsNull=!(nativeCRS!=null&&nativeCRS.length()!=0); + // if we are asking to use the reproject policy we must have the native crs + if(policy==ProjectionPolicy.REPROJECT_TO_DECLARED && (nativeSrsNull||srsNull)){ + throw new IllegalArgumentException("Unable to run: you can't ask GeoServer to reproject while not specifying a native CRS"); + } + + // if we are asking to use the NONE policy we must have the native crs. + if(policy==ProjectionPolicy.NONE && nativeSrsNull){ + throw new IllegalArgumentException("Unable to run: you can't ask GeoServer to use a native srs which is null"); + } + + // if we are asking to use the reproject policy we must have the native crs + if(policy==ProjectionPolicy.FORCE_DECLARED && srsNull){ + throw new IllegalArgumentException("Unable to run: you can't force GeoServer to use an srs which is null"); + } + // final String mimeType; switch (method){ @@ -1164,7 +1190,17 @@ public class GeoServerRESTPublisher { final GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder(); featureTypeEncoder.setName(datasetName); featureTypeEncoder.setTitle(datasetName); - featureTypeEncoder.setSRS(srs); + // set destination srs + if(!srsNull){ + featureTypeEncoder.setSRS(srs); + } else { + // this under the assumption that when the destination srs is null the nativeCRS has an EPSG one so we force them to be the same + featureTypeEncoder.setSRS(nativeCRS); + } + // set native srs + if(!nativeSrsNull){ + featureTypeEncoder.setNativeCRS(nativeCRS); + } featureTypeEncoder.setProjectionPolicy(policy); if (!createResource(workspace, DataStoreType.DATASTORES, storeName, @@ -1181,6 +1217,95 @@ public class GeoServerRESTPublisher { return configureLayer(workspace, datasetName, layerEncoder); } + + /** + * Publish a shapefile. + * + * @param workspace + * the name of the workspace to use + * @param storename + * the name of the store to create + * @param storeParams + * parameters to append to the url (can be null).
    + * Accepted parameters are:
    + * + * @param layername + * the name of the layer to configure + * @param method + * {@link UploadMethod} + * @param fileUri + * the uri of the file containing the shapefile.It should be: + * + * @param srs + * the SRS for this shapefile. It must be an ESPG code or GeoServer will choke. + * Notice that we can only use {@link ProjectionPolicy#FORCE_DECLARED}. + * @param policy + * {@link ProjectionPolicy} + * @param defaultStyle + * the default style to set (can be null). + * @return true if success false otherwise + * + * @throws FileNotFoundException + * if file to upload is not found + * @throws IllegalArgumentException + * if any of the mandatory arguments are {@code null}. + * @deprecated use {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, String)} instead as the behaviour + * of this method is misleading as it allows you to use wrong ProjectionPolicy values. + */ + public boolean publishShp(String workspace, String storeName, + NameValuePair[] storeParams, String datasetName, UploadMethod method, URI shapefile, + String srs, ProjectionPolicy policy, String defaultStyle) + throws FileNotFoundException, IllegalArgumentException { + return publishShp(workspace, storeName, storeParams, datasetName, method, shapefile, srs, null, policy, defaultStyle); + } + + /** + * Publish a shapefile. + * + * @param workspace + * the name of the workspace to use + * @param storename + * the name of the store to create + * @param storeParams + * parameters to append to the url (can be null).
    + * Accepted parameters are:
    + * + * @param layername + * the name of the layer to configure + * @param method + * {@link UploadMethod} + * @param fileUri + * the uri of the file containing the shapefile.It should be: + * + * @param srs + * the SRS for this shapefile. It must be an ESPG code or GeoServer will choke. + * @param defaultStyle + * the default style to set (can be null). + * @return true if success false otherwise + * + * @throws FileNotFoundException + * if file to upload is not found + * @throws IllegalArgumentException + * if any of the mandatory arguments are {@code null}. + */ + public boolean publishShp(String workspace, String storeName, + NameValuePair[] storeParams, String datasetName, UploadMethod method, URI shapefile, + String srs, String defaultStyle) + throws FileNotFoundException, IllegalArgumentException { + return publishShp(workspace, storeName, storeParams, datasetName, method, shapefile, srs, null, ProjectionPolicy.FORCE_DECLARED, defaultStyle); + } /** * Publish a zipped shapefile. @@ -1195,8 +1320,8 @@ public class GeoServerRESTPublisher { * the name of the layer to configure * @param zipFile * The zipped file to publish - * @param nativeCrs - * the native CRS + * @param srs + * the srs for this shapefile. It will be forced to use this one in GeoServer using {@link ProjectionPolicy#FORCE_DECLARED}. * @param defaultStyle * the default style to set (can be null). * @@ -1207,16 +1332,15 @@ public class GeoServerRESTPublisher { * if any of the mandatory arguments are {@code null}. */ public boolean publishShp(String workspace, String storename, - String layerName, File zipFile, String nativeCrs, + String layerName, File zipFile, String srs, String defaultStyle) throws FileNotFoundException, IllegalArgumentException { return publishShp(workspace, storename, (NameValuePair[]) null, - layerName, UploadMethod.FILE, zipFile.toURI(), nativeCrs, - ProjectionPolicy.FORCE_DECLARED, defaultStyle); + layerName, UploadMethod.FILE, zipFile.toURI(), srs, defaultStyle); } - /** - * Publish a zipped shapefile. + /** + * Publish a zipped shapefile forcing the srs to the one provided. * * @see {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)} * @@ -1229,7 +1353,7 @@ public class GeoServerRESTPublisher { * @param zipFile * The zipped file to publish * @param srs - * the native CRS + * the CRS for this shapefile. It must be an EPSG CODE ! * * @return {@code true} if the operation completed successfully. * @throws FileNotFoundException @@ -1240,21 +1364,7 @@ public class GeoServerRESTPublisher { public boolean publishShp(String workspace, String storename, String layername, File zipFile, String srs) throws FileNotFoundException { - /* - * These are the equivalent calls with cUrl: - * - * {@code curl -u admin:geoserver -XPUT -H 'Content-type: - * application/zip' \ --data-binary @$ZIPFILE \ - * http://$GSIP:$GSPORT/$SERVLET - * /rest/workspaces/$WORKSPACE/datastores/$STORENAME/file.shp - * - * curl -u admin:geoserver -XPOST -H 'Content-type: text/xml' \ -d - * "$BAREEPSG:4326true" - * \ - * http://$GSIP:$GSPORT/$SERVLET/rest/workspaces/$WORKSPACE/datastores/ - * $STORENAME/featuretypes/$LAYERNAME } - */ - return publishShp(workspace, storename, (NameValuePair[])null, layername, UploadMethod.FILE, zipFile.toURI(), srs, ProjectionPolicy.NONE,null); + return publishShp(workspace, storename, (NameValuePair[])null, layername, UploadMethod.FILE, zipFile.toURI(), srs,null); } /** @@ -1271,7 +1381,7 @@ public class GeoServerRESTPublisher { * @param zipFile * the zip file containing the shapefile * @param srs - * the native CRS + * the shapefile srs. This must be an EPSG Codefor this code to work! * @param params * parameters to append to the url (can be null).
    * Accepted parameters are:
    @@ -1288,7 +1398,7 @@ public class GeoServerRESTPublisher { String layername, File zipFile, String srs, NameValuePair... params) throws FileNotFoundException, IllegalArgumentException { - return publishShp(workspace, storename, params, layername, UploadMethod.FILE, zipFile.toURI(), srs, ProjectionPolicy.NONE,null); + return publishShp(workspace, storename, params, layername, UploadMethod.FILE, zipFile.toURI(), srs,null); } @@ -1645,7 +1755,7 @@ public class GeoServerRESTPublisher { coverageEncoder.setSRS(srs); coverageEncoder.setProjectionPolicy(policy); if(bbox != null && bbox.length == 4) { - coverageEncoder.setLatLonBoundingBox(bbox[0], bbox[1], bbox[2], bbox[3], "EPSG:4326"); + coverageEncoder.setLatLonBoundingBox(bbox[0], bbox[1], bbox[2], bbox[3], DEFAULT_CRS); } if (!createCoverage(workspace, storeName, coverageEncoder)) { diff --git a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java index d594e3b..4265f24 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java +++ b/src/main/java/it/geosolutions/geoserver/rest/GeoServerRESTReader.java @@ -45,6 +45,8 @@ import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import org.slf4j.Logger; @@ -524,10 +526,13 @@ public class GeoServerRESTReader { * Get the names of all the Workspaces. *
    * This is a shortcut call: These info could be retrieved using {@link #getWorkspaces getWorkspaces} - * @return the list of the names of all Workspaces. + * @return the list of the names of all Workspaces or an empty list. */ public List getWorkspaceNames() { RESTWorkspaceList list = getWorkspaces(); + if(list==null){ + return Collections.emptyList(); + } List names = new ArrayList(list.size()); for (RESTWorkspaceList.RESTShortWorkspace item : list) { names.add(item.getName()); diff --git a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java index df84b31..dffc20c 100644 --- a/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java +++ b/src/main/java/it/geosolutions/geoserver/rest/encoder/GSResourceEncoder.java @@ -148,7 +148,7 @@ public abstract class GSResourceEncoder REPROJECT_TO_DECLARED, /** Use the declared CRS (ignore native) */ FORCE_DECLARED, - /** No reprojection */ + /** Keep native */ NONE } @@ -227,6 +227,22 @@ public abstract class GSResourceEncoder public void setSRS(final String srs) { set(SRS, srs); } + + private final static String NATIVECRS = "nativeCRS"; + + /** + * Add the 'nativeCRS' node with a text value from 'nativeCRS' + */ + protected void addNativeCRS(final String nativeCRS) { + add(NATIVECRS, nativeCRS); + } + + /** + * Set or modify the 'nativeCRS' node with a text value from 'nativeCRS' + */ + public void setNativeCRS(final String nativeCRS) { + set(NATIVECRS, nativeCRS); + } private final static String LATLONBBMINX = "latLonBoundingBox/minx"; private final static String LATLONBBMAXX = "latLonBoundingBox/maxx"; diff --git a/src/test/java/it/geosolutions/geoserver/rest/ConfigTest.java b/src/test/java/it/geosolutions/geoserver/rest/ConfigTest.java index a1c96a1..855d300 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/ConfigTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/ConfigTest.java @@ -35,6 +35,7 @@ import java.io.IOException; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.filefilter.SuffixFileFilter; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -53,13 +54,12 @@ public class ConfigTest extends GeoserverRESTTest { private static final String DEFAULT_WS = "geosolutions"; - - public ConfigTest(String testName) { - super(testName); - } - + @Test public void testEtj() throws FileNotFoundException, IOException { - if (!enabled()) return; + if(!enabled()){ + LOGGER.info("Skipping test "+"testEtj"+"for class:"+this.getClass().getSimpleName()); + return; + } deleteAll(); assertTrue(reader.getWorkspaces().isEmpty()); @@ -73,8 +73,12 @@ public class ConfigTest extends GeoserverRESTTest { // assertTrue(ok); } + @Test public void insertStyles() throws FileNotFoundException, IOException { - + if(!enabled()){ + LOGGER.info("Skipping test "+"insertStyles"+"for class:"+this.getClass().getSimpleName()); + return; + } File sldDir = new ClassPathResource("testdata").getFile(); for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) { LOGGER.info("Existing styles: " + reader.getStyles().getNames()); @@ -84,9 +88,12 @@ public class ConfigTest extends GeoserverRESTTest { } } - + @Test public void insertExternalGeotiff() throws FileNotFoundException, IOException { - + if(!enabled()){ + LOGGER.info("Skipping test "+"insertExternalGeotiff"+"for class:"+this.getClass().getSimpleName()); + return; + } String storeName = "testRESTStoreGeotiff"; String layerName = "resttestdem"; @@ -95,9 +102,12 @@ public class ConfigTest extends GeoserverRESTTest { assertTrue(pc); } - + @Test public void insertExternalShape() throws FileNotFoundException, IOException { - + if(!enabled()){ + LOGGER.info("Skipping test "+"insertExternalShape"+"for class:"+this.getClass().getSimpleName()); + return; + } File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); boolean published = publisher.publishShp(DEFAULT_WS, "anyname", "cities", zipFile, "EPSG:41001", "default_point"); diff --git a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java index 773066c..b3d2717 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTReaderTest.java @@ -25,14 +25,17 @@ package it.geosolutions.geoserver.rest; -import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; -import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList; import it.geosolutions.geoserver.rest.decoder.RESTDataStore; +import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList; import it.geosolutions.geoserver.rest.decoder.RESTLayerList; import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList; import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList; +import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem; + import java.util.List; +import org.junit.Test; + /** * @@ -40,13 +43,10 @@ import java.util.List; */ public class GeoserverRESTReaderTest extends GeoserverRESTTest { - public GeoserverRESTReaderTest(String testName) { - super(testName); - } - /** * Test of getLayers method, of class GeoServerRESTReader. */ + @Test public void testGetLayers() { if(!enabled()) return; @@ -70,6 +70,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getDatastores method, of class GeoServerRESTReader. */ + @Test public void testGetDatastores() { if(!enabled()) return; @@ -100,6 +101,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { } + @Test public void testGetWSDSNames() { if(!enabled()) return; @@ -129,6 +131,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getDatastore method, of class GeoServerRESTReader. */ + @Test public void testGetDatastore() { //tested in testGetDatastores() } @@ -136,12 +139,14 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getLayer method, of class GeoServerRESTReader. */ + @Test public void testGetLayer() { } /** * Test of getNamespaceNames method, of class GeoServerRESTReader. */ + @Test public void testGetNamespaces() { if(!enabled()) return; @@ -165,6 +170,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getWorkspaceNames method, of class GeoServerRESTReader. */ + @Test public void testGetNamespaceNames() { if(!enabled()) return; @@ -183,6 +189,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getWorkspaceNames method, of class GeoServerRESTReader. */ + @Test public void testGetWorkspaces() { if(!enabled()) return; @@ -202,6 +209,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest { /** * Test of getWorkspaceNames method, of class GeoServerRESTReader. */ + @Test public void testGetWorkspaceNames() { if(!enabled()) return; diff --git a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTTest.java b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTTest.java index 4db9e7c..12e6243 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/GeoserverRESTTest.java @@ -39,6 +39,8 @@ import java.util.List; import junit.framework.TestCase; +import org.junit.Assert; +import org.junit.BeforeClass; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +58,7 @@ import org.slf4j.LoggerFactory; * * @author etj */ -public abstract class GeoserverRESTTest extends TestCase { +public abstract class GeoserverRESTTest extends Assert { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTTest.class); protected static final String DEFAULT_WS = "geosolutions"; @@ -100,15 +102,10 @@ public abstract class GeoserverRESTTest extends TestCase { return ret != null? ret : envDefault; } - public GeoserverRESTTest(String testName) { - super(testName); - } + @BeforeClass + public static void setUp() throws Exception { - @Override - protected void setUp() throws Exception { - super.setUp(); - if(enabled) { if(existgs == null) { existgs = reader.existGeoserver(); @@ -120,12 +117,11 @@ public abstract class GeoserverRESTTest extends TestCase { } if ( ! existgs ) { - System.out.println("Failing test " + this.getClass().getSimpleName() + "::" + this.getName() + " : geoserver not found"); + System.out.println("Failing tests : geoserver not found"); fail("GeoServer not found"); } - System.out.println("\n-------------------> RUNNING TEST " + this.getName()); } else { - System.out.println("Skipping test " + this.getClass().getSimpleName() + "::" + this.getName()); + System.out.println("Skipping tests "); } } diff --git a/src/test/java/it/geosolutions/geoserver/rest/datastore/GSArcSDEDatastoreEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/datastore/GSArcSDEDatastoreEncoderTest.java index dbeaf99..12e343f 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/datastore/GSArcSDEDatastoreEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/datastore/GSArcSDEDatastoreEncoderTest.java @@ -28,6 +28,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -68,8 +69,7 @@ public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest { private final String pgUser; private final String pgPassword; - public GSArcSDEDatastoreEncoderTest(String testName) { - super(testName); + public GSArcSDEDatastoreEncoderTest() { pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgServer = System.getProperty("pgServer", "localhost"); @@ -79,6 +79,7 @@ public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest { pgPassword = System.getProperty("pgPassword", "ptest"); } + @Test public void testCreateDeleteArcSDEDatastore() { if (!enabled()) { return; 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 e8d7e86..b470860 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/datastore/GSOracleNGDatastoreEncoderTest.java @@ -28,6 +28,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,8 +70,7 @@ public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest { private final String pgUser; private final String pgPassword; - public GSOracleNGDatastoreEncoderTest(String testName) { - super(testName); + public GSOracleNGDatastoreEncoderTest() { pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgHost = System.getProperty("pgHost", "localhost"); @@ -81,6 +81,7 @@ public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest { pgPassword = System.getProperty("pgPassword", "ptest"); } + @Test public void testCreateDeleteOracleNGDatastore() { if (!enabled()) { return; diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSBackupEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSBackupEncoderTest.java index 3471450..47a5dd2 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSBackupEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSBackupEncoderTest.java @@ -37,9 +37,6 @@ public class GSBackupEncoderTest extends TestCase */ protected static final Logger LOGGER = Logger.getLogger(GSBackupEncoderTest.class); - public GSBackupEncoderTest() - { - } @Test public void testAll() diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoderTest.java index 3fbb068..d81e12d 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/GSWorkspaceEncoderTest.java @@ -31,9 +31,6 @@ import org.slf4j.LoggerFactory; */ public class GSWorkspaceEncoderTest extends TestCase { - public GSWorkspaceEncoderTest() { - } - /** * Default logger */ diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java index d25fbe9..2803ca4 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/coverage/GSCoverageEncoderTest.java @@ -37,6 +37,13 @@ import org.slf4j.LoggerFactory; * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it */ public class GSCoverageEncoderTest extends TestCase { + public static final String WGS84="GEOGCS[\"WGS84(DD)," + + "DATUM[\"WGS84\"," + + "SPHEROID[\"WGS84\", 6378137.0, 298.257223563]]," + + "PRIMEM[\"Greenwich\", 0.0]," + + "UNIT[\"degree\", 0.017453292519943295]," + + "AXIS[\"Geodetic longitude\", EAST]," + + "AXIS[\"Geodetic latitude\", NORTH]]"; public GSCoverageEncoderTest() { } @@ -54,11 +61,22 @@ public class GSCoverageEncoderTest extends TestCase { GSResourceEncoder/**/ re=new GSCoverageEncoder(); re.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); + re.setSRS("EPSG:4326"); Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString())); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"srs","EPSG:4326")); re.setProjectionPolicy(ProjectionPolicy.NONE); + re.setNativeCRS("EPSG:4326"); Assert.assertNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString())); Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.NONE.toString())); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"nativeCRS","EPSG:4326")); + + re.setProjectionPolicy(ProjectionPolicy.REPROJECT_TO_DECLARED); + re.setNativeCRS(WGS84); + re.setSRS("EPSG:4326"); + Assert.assertNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString())); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"nativeCRS",WGS84)); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"srs","EPSG:4326")); } /** @@ -68,13 +86,15 @@ public class GSCoverageEncoderTest extends TestCase { public void testBB(){ GSResourceEncoder/**/ re=new GSCoverageEncoder(); - re.setLatLonBoundingBox(-180d, 90d, 180d, -90d, null); + re.setLatLonBoundingBox(-180d, 90d, 180d, -90d, WGS84); Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-180.0")); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"crs",WGS84)); - re.setLatLonBoundingBox(-90d, 45d, 180d, -90d, null); + re.setLatLonBoundingBox(-90d, 45d, 180d, -90d, WGS84); Assert.assertNull(ElementUtils.contains(re.getRoot(),"minx","-180.0")); Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-90.0")); + Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"crs",WGS84)); } @Test diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java index 29ce77e..9e71009 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/feature/GSFeatureEncoderTest.java @@ -43,9 +43,6 @@ import org.slf4j.LoggerFactory; */ public class GSFeatureEncoderTest extends TestCase { protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class); - - public GSFeatureEncoderTest() { - } @Test public void testAll() { diff --git a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java index 994fabb..ef38e74 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/encoder/utils/EntryKeyListEncoderTest.java @@ -19,11 +19,10 @@ */ package it.geosolutions.geoserver.rest.encoder.utils; -import java.util.List; import junit.framework.TestCase; + import org.jdom.Element; import org.junit.Test; -import static org.junit.Assert.*; /** * 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 5d296cd..82273a6 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/manager/GeoserverRESTDatastoreManagerTest.java @@ -24,17 +24,17 @@ */ package it.geosolutions.geoserver.rest.manager; -import org.junit.Test; +import it.geosolutions.geoserver.rest.GeoserverRESTTest; +import it.geosolutions.geoserver.rest.decoder.RESTDataStore; +import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder; +import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder; +import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder; import java.net.URL; import java.nio.charset.Charset; import java.util.Map; -import it.geosolutions.geoserver.rest.GeoserverRESTTest; -import it.geosolutions.geoserver.rest.decoder.RESTDataStore; -import it.geosolutions.geoserver.rest.encoder.datastore.GSAbstractDatastoreEncoder; -import it.geosolutions.geoserver.rest.encoder.datastore.GSShapefileDatastoreEncoder; -import it.geosolutions.geoserver.rest.encoder.datastore.GSDirectoryOfShapefilesDatastoreEncoder; +import org.junit.Test; /** * Test datastore handling (create, read and update): @@ -70,9 +70,7 @@ public class GeoserverRESTDatastoreManagerTest extends GeoserverRESTTest { private static URL LOCATION_1; private static URL LOCATION_2; - public GeoserverRESTDatastoreManagerTest(String testName) throws Exception { - super(testName); - + public GeoserverRESTDatastoreManagerTest() throws Exception { LOCATION_1 = new URL("file:data/1"); LOCATION_2 = new URL("file:data/2"); } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java index d518e56..6541b76 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTGeoTiffTest.java @@ -33,6 +33,7 @@ import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -48,10 +49,7 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTGeoTiffTest.class); - public GeoserverRESTGeoTiffTest(String testName) { - super(testName); - } - + @Test public void testExternalGeotiff() throws FileNotFoundException, IOException { if (!enabled()) return; deleteAll(); @@ -83,7 +81,8 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest { assertFalse("Bad unpublish()", publisher.unpublishCoverage(DEFAULT_WS, storeName, layerName)); assertFalse(existsLayer(layerName)); } - + + @Test public void testGeotiff() throws FileNotFoundException, IOException { if (!enabled()) return; deleteAll(); diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java index d2137e3..9b655aa 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTImageMosaicTest.java @@ -40,6 +40,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.httpclient.NameValuePair; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -71,11 +72,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImageMosaicTest.class); - - public GeoserverRESTImageMosaicTest(String testName) { - super(testName); - } - + @Test public void testCreateDeleteImageMosaicDatastore() { if (!enabled()) { return; @@ -170,6 +167,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest { assertTrue(publisher.removeWorkspace(wsName)); } + @Test public void testPublishImageMosaic() throws IOException { if (!enabled()) { diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java index 7a9f60a..29995a4 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTNamespaceTest.java @@ -40,11 +40,7 @@ import java.net.URI; * @author Oscar Fonts */ public class GeoserverRESTNamespaceTest extends GeoserverRESTTest { - - public GeoserverRESTNamespaceTest(String testName) { - super(testName); - } - + /** * Test Namespace create */ 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 2d76af5..c809d42 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPostgisDatastoreTest.java @@ -30,6 +30,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -70,8 +71,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest { private final String pgUser; private final String pgPassword; - public GeoserverRESTPostgisDatastoreTest(String testName) { - super(testName); + public GeoserverRESTPostgisDatastoreTest() { pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgHost = System.getProperty("pgHost", "localhost"); @@ -82,6 +82,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest { pgPassword = System.getProperty("pgPassword", "ptest"); } + @Test public void testCreateDeletePostGISDatastore() { if (!enabled()) { return; diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublishShpCollectionTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublishShpCollectionTest.java index 8463bbe..f6a1037 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublishShpCollectionTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublishShpCollectionTest.java @@ -24,12 +24,13 @@ */ package it.geosolutions.geoserver.rest.publisher; -import org.junit.Test; +import it.geosolutions.geoserver.rest.GeoserverRESTTest; + import java.net.URI; import java.util.List; -import org.springframework.core.io.ClassPathResource; -import it.geosolutions.geoserver.rest.GeoserverRESTTest; +import org.junit.Test; +import org.springframework.core.io.ClassPathResource; /** * @author Oscar Fonts @@ -39,10 +40,6 @@ public class GeoserverRESTPublishShpCollectionTest extends GeoserverRESTTest { final String workspace = DEFAULT_WS; final String storeName = "testshpcollection"; - public GeoserverRESTPublishShpCollectionTest(String testName) { - super(testName); - } - @Test public void testLocalZip() throws Exception { if (!enabled()) { diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublisherTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublisherTest.java index 4ca9a21..0c31f2d 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublisherTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTPublisherTest.java @@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTLayer; import java.io.FileNotFoundException; import java.io.IOException; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -47,10 +48,6 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPublisherTest.class); - public GeoserverRESTPublisherTest(String testName) { - super(testName); - } - protected void cleanupTestFT(String layerName, String ns, String storeName) { // dry run delete to work in a known state RESTLayer testLayer = reader.getLayer(layerName); @@ -68,6 +65,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest { assertFalse("Cleanup failed", existsLayer(layerName)); } + @Test public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException { if (!enabled()) { return; @@ -82,6 +80,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest { assertFalse("unpublished not existing layer", ok); } + @Test public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException { if (!enabled()) { return; @@ -96,6 +95,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest { assertFalse("unpublished not existing layer", ok); } + @Test public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException { if (!enabled()) { return; 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 960b001..4f5816b 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTShapeTest.java @@ -29,12 +29,17 @@ import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod; import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.decoder.RESTLayer; import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; +import it.geosolutions.geoserver.rest.encoder.coverage.GSCoverageEncoderTest; +import it.geosolutions.geoserver.rest.encoder.feature.GSFeatureEncoderTest; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import org.apache.commons.httpclient.NameValuePair; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -50,18 +55,20 @@ import org.springframework.core.io.ClassPathResource; public class GeoserverRESTShapeTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTShapeTest.class); - - public GeoserverRESTShapeTest(String testName) { - super(testName); - } + @After + public void cleanUp(){ + if(enabled()){ + deleteAllWorkspaces(); + } + } + @Test public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException { if (!enabled()) { return; } // Assume.assumeTrue(enabled); - deleteAllWorkspaces(); assertTrue(publisher.createWorkspace(DEFAULT_WS)); String storeName = "resttestshp"; @@ -91,12 +98,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { } + @Test public void testPublishDeleteExternalComplexShapeZip() throws FileNotFoundException, IOException { if (!enabled()) { return; } // Assume.assumeTrue(enabled); - deleteAllWorkspaces(); assertTrue(publisher.createWorkspace(DEFAULT_WS)); String storeName = "resttestshp_complex"; @@ -105,7 +112,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile(); // test insert - boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.EXTERNAL, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); + boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.EXTERNAL, zipFile.toURI(), "EPSG:4326",GSCoverageEncoderTest.WGS84,ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); assertTrue("publish() failed", published); assertTrue(existsLayer(datasetName)); @@ -124,12 +131,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { assertTrue("removeDatastore() failed", dsRemoved); } + @Test public void testPublishDeleteComplexShapeZip() throws FileNotFoundException, IOException { if (!enabled()) { return; } // Assume.assumeTrue(enabled); - deleteAllWorkspaces(); assertTrue(publisher.createWorkspace(DEFAULT_WS)); String storeName = "resttestshp_complex"; @@ -138,7 +145,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); // test insert - boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.FILE, zipFile.toURI(), "EPSG:4326",ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); + boolean published = publisher.publishShp(DEFAULT_WS, storeName, new NameValuePair[]{new NameValuePair("charset", "UTF-8")},datasetName, UploadMethod.FILE, zipFile.toURI(), "EPSG:4326",GSCoverageEncoderTest.WGS84,ProjectionPolicy.REPROJECT_TO_DECLARED,"polygon"); assertTrue("publish() failed", published); assertTrue(existsLayer(datasetName)); @@ -157,11 +164,13 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { assertTrue("removeDatastore() failed", dsRemoved); } + @Test public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException { if (!enabled()) { return; } // Assume.assumeTrue(enabled); + assertTrue(publisher.createWorkspace(DEFAULT_WS)); String ns = "geosolutions"; String storeName = "resttestshp"; @@ -199,12 +208,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { assertFalse(reader.existsStyle(styleName)); } + @Test public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException { if (!enabled()) { return; } // Assume.assumeTrue(enabled); - deleteAllWorkspaces(); assertTrue(publisher.createWorkspace(DEFAULT_WS)); String storeName = "resttestshp"; @@ -242,6 +251,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { * @throws IllegalArgumentException * @throws FileNotFoundException */ + @Test public void testPublishShpUsingDeclaredNativeCRS() throws Exception { if (!enabled()) return; @@ -265,16 +275,48 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest { // Read CRS. Should be using the one indicated at publication time. assertNotNull(reader.getLayer(layerName)); + + // remove also datastore + boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storename,true); + assertTrue("removeDatastore() failed", dsRemoved); + } + + /** + * Test case to solve error described in: + * https://github.com/geosolutions-it/geoserver-manager/issues/11 + * + * @throws IllegalArgumentException + * @throws FileNotFoundException + */ + @Test + public void testPublishShpUsingWKTNativeCRS() throws Exception { + if (!enabled()) + return; + + // layer publication params + String workspace = DEFAULT_WS; + String storename = "resttestshp"; + String layerName = "10m_populated_places"; + File zipFile = new ClassPathResource("testdata/test_noepsg.zip") + .getFile(); + String nativeCrs = "EPSG:4326"; + String defaultStyle = null; + + // Cleanup + deleteAllWorkspacesRecursively(); + assertTrue(publisher.createWorkspace(workspace)); + + // Publish layer + assertTrue(publisher.publishShp(workspace, storename, layerName, + zipFile, nativeCrs, defaultStyle)); + + // Read CRS. Should be using the one indicated at publication time. + assertNotNull(reader.getLayer(layerName)); + + // remove also datastore + boolean dsRemoved = publisher.removeDatastore(DEFAULT_WS, storename,true); + assertTrue("removeDatastore() failed", dsRemoved); } - - // public void testDeleteUnexistingFT() throws FileNotFoundException, IOException { -// String wsName = "this_ws_does_not_exist"; -// String storeName = "this_store_does_not_exist"; -// String layerName = "this_layer_does_not_exist"; -// -// boolean ok = publisher.unpublishFT(wsName, storeName, layerName); -// assertFalse("unpublished not existing layer", ok); -// } } diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTStyleTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTStyleTest.java index 11eea6f..b29abca 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTStyleTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTStyleTest.java @@ -38,6 +38,7 @@ import java.io.IOException; import org.apache.commons.io.IOUtils; import org.jdom.Element; import org.jdom.Namespace; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -55,10 +56,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory .getLogger(GeoserverRESTStyleTest.class); - public GeoserverRESTStyleTest(String testName) { - super(testName); - } - + @Test public void testStyles() throws IOException { if (!enabled()) return; @@ -116,6 +114,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest { assertFalse("Cleanup failed", reader.existsStyle(styleName)); } + @Test public void testPublishDeleteStyleFile() throws FileNotFoundException, IOException { if (!enabled()) { @@ -147,6 +146,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest { assertFalse(reader.existsStyle(styleName)); } + @Test public void testPublishDeleteStyleString() throws FileNotFoundException, IOException { if (!enabled()) { @@ -193,6 +193,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest { } + @Test public void testUpdateDefaultStyle() throws FileNotFoundException, IOException { if (!enabled()) { diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java index 6730ea4..244c93d 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorkspaceTest.java @@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy import java.io.File; import java.io.IOException; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -47,10 +48,7 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorkspaceTest.class); - public GeoserverRESTWorkspaceTest(String testName) { - super(testName); - } - + @Test public void testWorkspaces() { if (!enabled()) return; deleteAll(); @@ -69,6 +67,7 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest { * remove workspace and all of its contents * @throws IOException */ + @Test public void testWorkspaceRemoval() throws IOException { if (!enabled()) return; deleteAll(); diff --git a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java index f67aaee..9491362 100644 --- a/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java +++ b/src/test/java/it/geosolutions/geoserver/rest/publisher/GeoserverRESTWorldImageTest.java @@ -32,6 +32,7 @@ import java.io.File; import java.io.IOException; import org.apache.commons.httpclient.NameValuePair; +import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.ClassPathResource; @@ -47,10 +48,7 @@ public class GeoserverRESTWorldImageTest extends GeoserverRESTTest { private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorldImageTest.class); - public GeoserverRESTWorldImageTest(String testName) { - super(testName); - } - + @Test public void testPublishWorldImage() throws IOException { if (!enabled()) { diff --git a/src/test/resources/testdata/test_noepsg.zip b/src/test/resources/testdata/test_noepsg.zip new file mode 100644 index 0000000000000000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