#34,#35,#33

This commit is contained in:
Simone Giannecchini 2012-08-09 17:12:56 +02:00
parent d317ff5ab9
commit db53134610
25 changed files with 334 additions and 148 deletions

View File

@ -61,6 +61,8 @@ import org.slf4j.LoggerFactory;
*/ */
public class GeoServerRESTPublisher { public class GeoServerRESTPublisher {
public static final String DEFAULT_CRS = "EPSG:4326";
/** The logger for this class */ /** The logger for this class */
private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class); private static final Logger LOGGER = LoggerFactory.getLogger(GeoServerRESTPublisher.class);
@ -1069,7 +1071,7 @@ public class GeoServerRESTPublisher {
/** /**
* Upload an publish a local shapefile. * Upload an publish a local shapefile.
* <P> * <P>
* 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)} * @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, public boolean publishShp(String workspace, String storename,
String datasetname, File zipFile) throws FileNotFoundException, IllegalArgumentException { 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 {
* <li>A zip file if 'method' is uri (UNTESTED)</li> * <li>A zip file if 'method' is uri (UNTESTED)</li>
* </ul> * </ul>
* @param srs * @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 * @param policy
* {@link ProjectionPolicy} * {@link ProjectionPolicy}
* @param defaultStyle * @param defaultStyle
@ -1130,11 +1134,33 @@ public class GeoServerRESTPublisher {
*/ */
public boolean publishShp(String workspace, String storeName, public boolean publishShp(String workspace, String storeName,
NameValuePair[] storeParams, String datasetName, UploadMethod method, URI shapefile, 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 { throws FileNotFoundException, IllegalArgumentException {
if (workspace == null || storeName == null || shapefile == null 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"); 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; final String mimeType;
switch (method){ switch (method){
@ -1164,7 +1190,17 @@ public class GeoServerRESTPublisher {
final GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder(); final GSFeatureTypeEncoder featureTypeEncoder = new GSFeatureTypeEncoder();
featureTypeEncoder.setName(datasetName); featureTypeEncoder.setName(datasetName);
featureTypeEncoder.setTitle(datasetName); featureTypeEncoder.setTitle(datasetName);
// set destination srs
if(!srsNull){
featureTypeEncoder.setSRS(srs); 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); featureTypeEncoder.setProjectionPolicy(policy);
if (!createResource(workspace, DataStoreType.DATASTORES, storeName, if (!createResource(workspace, DataStoreType.DATASTORES, storeName,
@ -1182,6 +1218,95 @@ public class GeoServerRESTPublisher {
return configureLayer(workspace, datasetName, layerEncoder); 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).<br>
* Accepted parameters are:<br>
* <ul>
* <li><b>charset</b> used to set the charset</li>
* </ul>
* @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:
* <ul>
* <li>A zip file if 'method' is file</li>
* <li>A shp file if 'method' is external</li>
* <li>A zip file if 'method' is uri (UNTESTED)</li>
* </ul>
* @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).<br>
* Accepted parameters are:<br>
* <ul>
* <li><b>charset</b> used to set the charset</li>
* </ul>
* @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:
* <ul>
* <li>A zip file if 'method' is file</li>
* <li>A shp file if 'method' is external</li>
* <li>A zip file if 'method' is uri (UNTESTED)</li>
* </ul>
* @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. * Publish a zipped shapefile.
* *
@ -1195,8 +1320,8 @@ public class GeoServerRESTPublisher {
* the name of the layer to configure * the name of the layer to configure
* @param zipFile * @param zipFile
* The zipped file to publish * The zipped file to publish
* @param nativeCrs * @param srs
* the native CRS * the srs for this shapefile. It will be forced to use this one in GeoServer using {@link ProjectionPolicy#FORCE_DECLARED}.
* @param defaultStyle * @param defaultStyle
* the default style to set (can be null). * the default style to set (can be null).
* *
@ -1207,16 +1332,15 @@ public class GeoServerRESTPublisher {
* if any of the mandatory arguments are {@code null}. * if any of the mandatory arguments are {@code null}.
*/ */
public boolean publishShp(String workspace, String storename, public boolean publishShp(String workspace, String storename,
String layerName, File zipFile, String nativeCrs, String layerName, File zipFile, String srs,
String defaultStyle) throws FileNotFoundException, IllegalArgumentException { String defaultStyle) throws FileNotFoundException, IllegalArgumentException {
return publishShp(workspace, storename, (NameValuePair[]) null, return publishShp(workspace, storename, (NameValuePair[]) null,
layerName, UploadMethod.FILE, zipFile.toURI(), nativeCrs, layerName, UploadMethod.FILE, zipFile.toURI(), srs, defaultStyle);
ProjectionPolicy.FORCE_DECLARED, 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)} * @see {@link #publishShp(String, String, NameValuePair[], String, UploadMethod, URI, String, ProjectionPolicy, String)}
* *
@ -1229,7 +1353,7 @@ public class GeoServerRESTPublisher {
* @param zipFile * @param zipFile
* The zipped file to publish * The zipped file to publish
* @param srs * @param srs
* the native CRS * the CRS for this shapefile. It must be an EPSG CODE !
* *
* @return {@code true} if the operation completed successfully. * @return {@code true} if the operation completed successfully.
* @throws FileNotFoundException * @throws FileNotFoundException
@ -1240,21 +1364,7 @@ public class GeoServerRESTPublisher {
public boolean publishShp(String workspace, String storename, public boolean publishShp(String workspace, String storename,
String layername, File zipFile, String srs) String layername, File zipFile, String srs)
throws FileNotFoundException { throws FileNotFoundException {
/* return publishShp(workspace, storename, (NameValuePair[])null, layername, UploadMethod.FILE, zipFile.toURI(), srs,null);
* 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
* "<featureType><name>$BARE</name><nativeCRS>EPSG:4326</nativeCRS><enabled>true</enabled></featureType>"
* \
* 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);
} }
/** /**
@ -1271,7 +1381,7 @@ public class GeoServerRESTPublisher {
* @param zipFile * @param zipFile
* the zip file containing the shapefile * the zip file containing the shapefile
* @param srs * @param srs
* the native CRS * the shapefile srs. This must be an EPSG Codefor this code to work!
* @param params * @param params
* parameters to append to the url (can be null).<br> * parameters to append to the url (can be null).<br>
* Accepted parameters are:<br> * Accepted parameters are:<br>
@ -1288,7 +1398,7 @@ public class GeoServerRESTPublisher {
String layername, File zipFile, String srs, NameValuePair... params) String layername, File zipFile, String srs, NameValuePair... params)
throws FileNotFoundException, IllegalArgumentException { 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.setSRS(srs);
coverageEncoder.setProjectionPolicy(policy); coverageEncoder.setProjectionPolicy(policy);
if(bbox != null && bbox.length == 4) { 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)) { if (!createCoverage(workspace, storeName, coverageEncoder)) {

View File

@ -45,6 +45,8 @@ import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -524,10 +526,13 @@ public class GeoServerRESTReader {
* Get the names of all the Workspaces. * Get the names of all the Workspaces.
* <BR> * <BR>
* This is a shortcut call: These info could be retrieved using {@link #getWorkspaces getWorkspaces} * 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<String> getWorkspaceNames() { public List<String> getWorkspaceNames() {
RESTWorkspaceList list = getWorkspaces(); RESTWorkspaceList list = getWorkspaces();
if(list==null){
return Collections.emptyList();
}
List<String> names = new ArrayList<String>(list.size()); List<String> names = new ArrayList<String>(list.size());
for (RESTWorkspaceList.RESTShortWorkspace item : list) { for (RESTWorkspaceList.RESTShortWorkspace item : list) {
names.add(item.getName()); names.add(item.getName());

View File

@ -148,7 +148,7 @@ public abstract class GSResourceEncoder
REPROJECT_TO_DECLARED, REPROJECT_TO_DECLARED,
/** Use the declared CRS (ignore native) */ /** Use the declared CRS (ignore native) */
FORCE_DECLARED, FORCE_DECLARED,
/** No reprojection */ /** Keep native */
NONE NONE
} }
@ -228,6 +228,22 @@ public abstract class GSResourceEncoder
set(SRS, 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 LATLONBBMINX = "latLonBoundingBox/minx";
private final static String LATLONBBMAXX = "latLonBoundingBox/maxx"; private final static String LATLONBBMAXX = "latLonBoundingBox/maxx";
private final static String LATLONBBMINY = "latLonBoundingBox/miny"; private final static String LATLONBBMINY = "latLonBoundingBox/miny";

View File

@ -35,6 +35,7 @@ import java.io.IOException;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import org.apache.commons.io.filefilter.SuffixFileFilter; import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -53,13 +54,12 @@ public class ConfigTest extends GeoserverRESTTest {
private static final String DEFAULT_WS = "geosolutions"; private static final String DEFAULT_WS = "geosolutions";
@Test
public ConfigTest(String testName) {
super(testName);
}
public void testEtj() throws FileNotFoundException, IOException { public void testEtj() throws FileNotFoundException, IOException {
if (!enabled()) return; if(!enabled()){
LOGGER.info("Skipping test "+"testEtj"+"for class:"+this.getClass().getSimpleName());
return;
}
deleteAll(); deleteAll();
assertTrue(reader.getWorkspaces().isEmpty()); assertTrue(reader.getWorkspaces().isEmpty());
@ -73,8 +73,12 @@ public class ConfigTest extends GeoserverRESTTest {
// assertTrue(ok); // assertTrue(ok);
} }
@Test
public void insertStyles() throws FileNotFoundException, IOException { 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(); File sldDir = new ClassPathResource("testdata").getFile();
for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) { for(File sldFile : sldDir.listFiles((FilenameFilter)new SuffixFileFilter(".sld"))) {
LOGGER.info("Existing styles: " + reader.getStyles().getNames()); LOGGER.info("Existing styles: " + reader.getStyles().getNames());
@ -84,9 +88,12 @@ public class ConfigTest extends GeoserverRESTTest {
} }
} }
@Test
public void insertExternalGeotiff() throws FileNotFoundException, IOException { public void insertExternalGeotiff() throws FileNotFoundException, IOException {
if(!enabled()){
LOGGER.info("Skipping test "+"insertExternalGeotiff"+"for class:"+this.getClass().getSimpleName());
return;
}
String storeName = "testRESTStoreGeotiff"; String storeName = "testRESTStoreGeotiff";
String layerName = "resttestdem"; String layerName = "resttestdem";
@ -95,9 +102,12 @@ public class ConfigTest extends GeoserverRESTTest {
assertTrue(pc); assertTrue(pc);
} }
@Test
public void insertExternalShape() throws FileNotFoundException, IOException { 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(); File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
boolean published = publisher.publishShp(DEFAULT_WS, "anyname", "cities", zipFile, "EPSG:41001", "default_point"); boolean published = publisher.publishShp(DEFAULT_WS, "anyname", "cities", zipFile, "EPSG:41001", "default_point");

View File

@ -25,14 +25,17 @@
package it.geosolutions.geoserver.rest; 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.RESTDataStore;
import it.geosolutions.geoserver.rest.decoder.RESTDataStoreList;
import it.geosolutions.geoserver.rest.decoder.RESTLayerList; import it.geosolutions.geoserver.rest.decoder.RESTLayerList;
import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList; import it.geosolutions.geoserver.rest.decoder.RESTNamespaceList;
import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList; import it.geosolutions.geoserver.rest.decoder.RESTWorkspaceList;
import it.geosolutions.geoserver.rest.decoder.utils.NameLinkElem;
import java.util.List; import java.util.List;
import org.junit.Test;
/** /**
* *
@ -40,13 +43,10 @@ import java.util.List;
*/ */
public class GeoserverRESTReaderTest extends GeoserverRESTTest { public class GeoserverRESTReaderTest extends GeoserverRESTTest {
public GeoserverRESTReaderTest(String testName) {
super(testName);
}
/** /**
* Test of getLayers method, of class GeoServerRESTReader. * Test of getLayers method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetLayers() { public void testGetLayers() {
if(!enabled()) return; if(!enabled()) return;
@ -70,6 +70,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getDatastores method, of class GeoServerRESTReader. * Test of getDatastores method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetDatastores() { public void testGetDatastores() {
if(!enabled()) return; if(!enabled()) return;
@ -100,6 +101,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
} }
@Test
public void testGetWSDSNames() { public void testGetWSDSNames() {
if(!enabled()) if(!enabled())
return; return;
@ -129,6 +131,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getDatastore method, of class GeoServerRESTReader. * Test of getDatastore method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetDatastore() { public void testGetDatastore() {
//tested in testGetDatastores() //tested in testGetDatastores()
} }
@ -136,12 +139,14 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getLayer method, of class GeoServerRESTReader. * Test of getLayer method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetLayer() { public void testGetLayer() {
} }
/** /**
* Test of getNamespaceNames method, of class GeoServerRESTReader. * Test of getNamespaceNames method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetNamespaces() { public void testGetNamespaces() {
if(!enabled()) return; if(!enabled()) return;
@ -165,6 +170,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getWorkspaceNames method, of class GeoServerRESTReader. * Test of getWorkspaceNames method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetNamespaceNames() { public void testGetNamespaceNames() {
if(!enabled()) return; if(!enabled()) return;
@ -183,6 +189,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getWorkspaceNames method, of class GeoServerRESTReader. * Test of getWorkspaceNames method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetWorkspaces() { public void testGetWorkspaces() {
if(!enabled()) return; if(!enabled()) return;
@ -202,6 +209,7 @@ public class GeoserverRESTReaderTest extends GeoserverRESTTest {
/** /**
* Test of getWorkspaceNames method, of class GeoServerRESTReader. * Test of getWorkspaceNames method, of class GeoServerRESTReader.
*/ */
@Test
public void testGetWorkspaceNames() { public void testGetWorkspaceNames() {
if(!enabled()) return; if(!enabled()) return;

View File

@ -39,6 +39,8 @@ import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -56,7 +58,7 @@ import org.slf4j.LoggerFactory;
* *
* @author etj * @author etj
*/ */
public abstract class GeoserverRESTTest extends TestCase { public abstract class GeoserverRESTTest extends Assert {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTTest.class);
protected static final String DEFAULT_WS = "geosolutions"; protected static final String DEFAULT_WS = "geosolutions";
@ -100,15 +102,10 @@ public abstract class GeoserverRESTTest extends TestCase {
return ret != null? ret : envDefault; return ret != null? ret : envDefault;
} }
public GeoserverRESTTest(String testName) { @BeforeClass
super(testName); public static void setUp() throws Exception {
}
@Override
protected void setUp() throws Exception {
super.setUp();
if(enabled) { if(enabled) {
if(existgs == null) { if(existgs == null) {
existgs = reader.existGeoserver(); existgs = reader.existGeoserver();
@ -120,12 +117,11 @@ public abstract class GeoserverRESTTest extends TestCase {
} }
if ( ! existgs ) { 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"); fail("GeoServer not found");
} }
System.out.println("\n-------------------> RUNNING TEST " + this.getName());
} else { } else {
System.out.println("Skipping test " + this.getClass().getSimpleName() + "::" + this.getName()); System.out.println("Skipping tests ");
} }
} }

View File

@ -28,6 +28,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSArcSDEDatastoreEncoder;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -68,8 +69,7 @@ public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest {
private final String pgUser; private final String pgUser;
private final String pgPassword; private final String pgPassword;
public GSArcSDEDatastoreEncoderTest(String testName) { public GSArcSDEDatastoreEncoderTest() {
super(testName);
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgServer = System.getProperty("pgServer", "localhost"); pgServer = System.getProperty("pgServer", "localhost");
@ -79,6 +79,7 @@ public class GSArcSDEDatastoreEncoderTest extends GeoserverRESTTest {
pgPassword = System.getProperty("pgPassword", "ptest"); pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test
public void testCreateDeleteArcSDEDatastore() { public void testCreateDeleteArcSDEDatastore() {
if (!enabled()) { if (!enabled()) {
return; return;

View File

@ -28,6 +28,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.datastore.GSOracleNGDatastoreEncoder;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -69,8 +70,7 @@ public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest {
private final String pgUser; private final String pgUser;
private final String pgPassword; private final String pgPassword;
public GSOracleNGDatastoreEncoderTest(String testName) { public GSOracleNGDatastoreEncoderTest() {
super(testName);
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost"); pgHost = System.getProperty("pgHost", "localhost");
@ -81,6 +81,7 @@ public class GSOracleNGDatastoreEncoderTest extends GeoserverRESTTest {
pgPassword = System.getProperty("pgPassword", "ptest"); pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test
public void testCreateDeleteOracleNGDatastore() { public void testCreateDeleteOracleNGDatastore() {
if (!enabled()) { if (!enabled()) {
return; return;

View File

@ -37,9 +37,6 @@ public class GSBackupEncoderTest extends TestCase
*/ */
protected static final Logger LOGGER = Logger.getLogger(GSBackupEncoderTest.class); protected static final Logger LOGGER = Logger.getLogger(GSBackupEncoderTest.class);
public GSBackupEncoderTest()
{
}
@Test @Test
public void testAll() public void testAll()

View File

@ -31,9 +31,6 @@ import org.slf4j.LoggerFactory;
*/ */
public class GSWorkspaceEncoderTest extends TestCase { public class GSWorkspaceEncoderTest extends TestCase {
public GSWorkspaceEncoderTest() {
}
/** /**
* Default logger * Default logger
*/ */

View File

@ -37,6 +37,13 @@ import org.slf4j.LoggerFactory;
* @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it * @author Carlo Cancellieri - carlo.cancellieri@geo-solutions.it
*/ */
public class GSCoverageEncoderTest extends TestCase { 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() { public GSCoverageEncoderTest() {
} }
@ -54,11 +61,22 @@ public class GSCoverageEncoderTest extends TestCase {
GSResourceEncoder/*<GSDimensionInfoEncoder>*/ re=new GSCoverageEncoder(); GSResourceEncoder/*<GSDimensionInfoEncoder>*/ re=new GSCoverageEncoder();
re.setProjectionPolicy(ProjectionPolicy.FORCE_DECLARED); 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(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString()));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"srs","EPSG:4326"));
re.setProjectionPolicy(ProjectionPolicy.NONE); re.setProjectionPolicy(ProjectionPolicy.NONE);
re.setNativeCRS("EPSG:4326");
Assert.assertNull(ElementUtils.contains(re.getRoot(),"projectionPolicy",ProjectionPolicy.FORCE_DECLARED.toString())); 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(),"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(){ public void testBB(){
GSResourceEncoder/*<GSDimensionInfoEncoder>*/ re=new GSCoverageEncoder(); GSResourceEncoder/*<GSDimensionInfoEncoder>*/ 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(),"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.assertNull(ElementUtils.contains(re.getRoot(),"minx","-180.0"));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-90.0")); Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"minx","-90.0"));
Assert.assertNotNull(ElementUtils.contains(re.getRoot(),"crs",WGS84));
} }
@Test @Test

View File

@ -44,9 +44,6 @@ import org.slf4j.LoggerFactory;
public class GSFeatureEncoderTest extends TestCase { public class GSFeatureEncoderTest extends TestCase {
protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class); protected final static Logger LOGGER = LoggerFactory.getLogger(GSFeatureEncoderTest.class);
public GSFeatureEncoderTest() {
}
@Test @Test
public void testAll() { public void testAll() {

View File

@ -19,11 +19,10 @@
*/ */
package it.geosolutions.geoserver.rest.encoder.utils; package it.geosolutions.geoserver.rest.encoder.utils;
import java.util.List;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.jdom.Element; import org.jdom.Element;
import org.junit.Test; import org.junit.Test;
import static org.junit.Assert.*;
/** /**
* *

View File

@ -24,17 +24,17 @@
*/ */
package it.geosolutions.geoserver.rest.manager; 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.net.URL;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.util.Map; import java.util.Map;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import org.junit.Test;
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;
/** /**
* Test datastore handling (create, read and update): * 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_1;
private static URL LOCATION_2; private static URL LOCATION_2;
public GeoserverRESTDatastoreManagerTest(String testName) throws Exception { public GeoserverRESTDatastoreManagerTest() throws Exception {
super(testName);
LOCATION_1 = new URL("file:data/1"); LOCATION_1 = new URL("file:data/1");
LOCATION_2 = new URL("file:data/2"); LOCATION_2 = new URL("file:data/2");
} }

View File

@ -33,6 +33,7 @@ import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -48,10 +49,7 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTGeoTiffTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTGeoTiffTest.class);
public GeoserverRESTGeoTiffTest(String testName) { @Test
super(testName);
}
public void testExternalGeotiff() throws FileNotFoundException, IOException { public void testExternalGeotiff() throws FileNotFoundException, IOException {
if (!enabled()) return; if (!enabled()) return;
deleteAll(); deleteAll();
@ -84,6 +82,7 @@ public class GeoserverRESTGeoTiffTest extends GeoserverRESTTest {
assertFalse(existsLayer(layerName)); assertFalse(existsLayer(layerName));
} }
@Test
public void testGeotiff() throws FileNotFoundException, IOException { public void testGeotiff() throws FileNotFoundException, IOException {
if (!enabled()) return; if (!enabled()) return;
deleteAll(); deleteAll();

View File

@ -40,6 +40,7 @@ import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.NameValuePair;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -71,11 +72,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImageMosaicTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImageMosaicTest.class);
@Test
public GeoserverRESTImageMosaicTest(String testName) {
super(testName);
}
public void testCreateDeleteImageMosaicDatastore() { public void testCreateDeleteImageMosaicDatastore() {
if (!enabled()) { if (!enabled()) {
return; return;
@ -170,6 +167,7 @@ public class GeoserverRESTImageMosaicTest extends GeoserverRESTTest {
assertTrue(publisher.removeWorkspace(wsName)); assertTrue(publisher.removeWorkspace(wsName));
} }
@Test
public void testPublishImageMosaic() throws IOException { public void testPublishImageMosaic() throws IOException {
if (!enabled()) { if (!enabled()) {

View File

@ -41,10 +41,6 @@ import java.net.URI;
*/ */
public class GeoserverRESTNamespaceTest extends GeoserverRESTTest { public class GeoserverRESTNamespaceTest extends GeoserverRESTTest {
public GeoserverRESTNamespaceTest(String testName) {
super(testName);
}
/** /**
* Test Namespace create * Test Namespace create
*/ */

View File

@ -30,6 +30,7 @@ import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTDataStore; import it.geosolutions.geoserver.rest.decoder.RESTDataStore;
import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder; import it.geosolutions.geoserver.rest.encoder.GSPostGISDatastoreEncoder;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -70,8 +71,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
private final String pgUser; private final String pgUser;
private final String pgPassword; private final String pgPassword;
public GeoserverRESTPostgisDatastoreTest(String testName) { public GeoserverRESTPostgisDatastoreTest() {
super(testName);
pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true"); pgIgnore = System.getProperty("pgIgnore", "false").equalsIgnoreCase("true");
pgHost = System.getProperty("pgHost", "localhost"); pgHost = System.getProperty("pgHost", "localhost");
@ -82,6 +82,7 @@ public class GeoserverRESTPostgisDatastoreTest extends GeoserverRESTTest {
pgPassword = System.getProperty("pgPassword", "ptest"); pgPassword = System.getProperty("pgPassword", "ptest");
} }
@Test
public void testCreateDeletePostGISDatastore() { public void testCreateDeletePostGISDatastore() {
if (!enabled()) { if (!enabled()) {
return; return;

View File

@ -24,12 +24,13 @@
*/ */
package it.geosolutions.geoserver.rest.publisher; package it.geosolutions.geoserver.rest.publisher;
import org.junit.Test; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import java.net.URI; import java.net.URI;
import java.util.List; 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 * @author Oscar Fonts
@ -39,10 +40,6 @@ public class GeoserverRESTPublishShpCollectionTest extends GeoserverRESTTest {
final String workspace = DEFAULT_WS; final String workspace = DEFAULT_WS;
final String storeName = "testshpcollection"; final String storeName = "testshpcollection";
public GeoserverRESTPublishShpCollectionTest(String testName) {
super(testName);
}
@Test @Test
public void testLocalZip() throws Exception { public void testLocalZip() throws Exception {
if (!enabled()) { if (!enabled()) {

View File

@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -47,10 +48,6 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPublisherTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTPublisherTest.class);
public GeoserverRESTPublisherTest(String testName) {
super(testName);
}
protected void cleanupTestFT(String layerName, String ns, String storeName) { protected void cleanupTestFT(String layerName, String ns, String storeName) {
// dry run delete to work in a known state // dry run delete to work in a known state
RESTLayer testLayer = reader.getLayer(layerName); RESTLayer testLayer = reader.getLayer(layerName);
@ -68,6 +65,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse("Cleanup failed", existsLayer(layerName)); assertFalse("Cleanup failed", existsLayer(layerName));
} }
@Test
public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException { public void testDeleteUnexistingCoverage() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
@ -82,6 +80,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse("unpublished not existing layer", ok); assertFalse("unpublished not existing layer", ok);
} }
@Test
public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException { public void testDeleteUnexistingFeatureType() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
@ -96,6 +95,7 @@ public class GeoserverRESTPublisherTest extends GeoserverRESTTest {
assertFalse("unpublished not existing layer", ok); assertFalse("unpublished not existing layer", ok);
} }
@Test
public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException { public void testDeleteUnexistingDatastore() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;

View File

@ -29,12 +29,17 @@ import it.geosolutions.geoserver.rest.GeoServerRESTPublisher.UploadMethod;
import it.geosolutions.geoserver.rest.GeoserverRESTTest; import it.geosolutions.geoserver.rest.GeoserverRESTTest;
import it.geosolutions.geoserver.rest.decoder.RESTLayer; import it.geosolutions.geoserver.rest.decoder.RESTLayer;
import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy; 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.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.httpclient.NameValuePair; 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.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -51,17 +56,19 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTShapeTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTShapeTest.class);
public GeoserverRESTShapeTest(String testName) { @After
super(testName); public void cleanUp(){
if(enabled()){
deleteAllWorkspaces();
}
} }
@Test
public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException { public void testPublishDeleteShapeZip() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
} }
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp"; String storeName = "resttestshp";
@ -91,12 +98,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
} }
@Test
public void testPublishDeleteExternalComplexShapeZip() throws FileNotFoundException, IOException { public void testPublishDeleteExternalComplexShapeZip() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
} }
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp_complex"; String storeName = "resttestshp_complex";
@ -105,7 +112,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile(); File zipFile = new ClassPathResource("testdata/shapefile/cities.shp").getFile();
// test insert // 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("publish() failed", published);
assertTrue(existsLayer(datasetName)); assertTrue(existsLayer(datasetName));
@ -124,12 +131,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
assertTrue("removeDatastore() failed", dsRemoved); assertTrue("removeDatastore() failed", dsRemoved);
} }
@Test
public void testPublishDeleteComplexShapeZip() throws FileNotFoundException, IOException { public void testPublishDeleteComplexShapeZip() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
} }
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp_complex"; String storeName = "resttestshp_complex";
@ -138,7 +145,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile(); File zipFile = new ClassPathResource("testdata/resttestshp.zip").getFile();
// test insert // 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("publish() failed", published);
assertTrue(existsLayer(datasetName)); assertTrue(existsLayer(datasetName));
@ -157,11 +164,13 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
assertTrue("removeDatastore() failed", dsRemoved); assertTrue("removeDatastore() failed", dsRemoved);
} }
@Test
public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException { public void testPublishDeleteStyledShapeZip() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
} }
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
assertTrue(publisher.createWorkspace(DEFAULT_WS));
String ns = "geosolutions"; String ns = "geosolutions";
String storeName = "resttestshp"; String storeName = "resttestshp";
@ -199,12 +208,12 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
assertFalse(reader.existsStyle(styleName)); assertFalse(reader.existsStyle(styleName));
} }
@Test
public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException { public void testPublishDeleteShapeZipWithParams() throws FileNotFoundException, IOException {
if (!enabled()) { if (!enabled()) {
return; return;
} }
// Assume.assumeTrue(enabled); // Assume.assumeTrue(enabled);
deleteAllWorkspaces();
assertTrue(publisher.createWorkspace(DEFAULT_WS)); assertTrue(publisher.createWorkspace(DEFAULT_WS));
String storeName = "resttestshp"; String storeName = "resttestshp";
@ -242,6 +251,7 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
* @throws IllegalArgumentException * @throws IllegalArgumentException
* @throws FileNotFoundException * @throws FileNotFoundException
*/ */
@Test
public void testPublishShpUsingDeclaredNativeCRS() throws Exception { public void testPublishShpUsingDeclaredNativeCRS() throws Exception {
if (!enabled()) if (!enabled())
return; return;
@ -265,16 +275,48 @@ public class GeoserverRESTShapeTest extends GeoserverRESTTest {
// Read CRS. Should be using the one indicated at publication time. // Read CRS. Should be using the one indicated at publication time.
assertNotNull(reader.getLayer(layerName)); 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);
// }
} }

View File

@ -38,6 +38,7 @@ import java.io.IOException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.jdom.Element; import org.jdom.Element;
import org.jdom.Namespace; import org.jdom.Namespace;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -55,10 +56,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory private final static Logger LOGGER = LoggerFactory
.getLogger(GeoserverRESTStyleTest.class); .getLogger(GeoserverRESTStyleTest.class);
public GeoserverRESTStyleTest(String testName) { @Test
super(testName);
}
public void testStyles() throws IOException { public void testStyles() throws IOException {
if (!enabled()) if (!enabled())
return; return;
@ -116,6 +114,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest {
assertFalse("Cleanup failed", reader.existsStyle(styleName)); assertFalse("Cleanup failed", reader.existsStyle(styleName));
} }
@Test
public void testPublishDeleteStyleFile() throws FileNotFoundException, public void testPublishDeleteStyleFile() throws FileNotFoundException,
IOException { IOException {
if (!enabled()) { if (!enabled()) {
@ -147,6 +146,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest {
assertFalse(reader.existsStyle(styleName)); assertFalse(reader.existsStyle(styleName));
} }
@Test
public void testPublishDeleteStyleString() throws FileNotFoundException, public void testPublishDeleteStyleString() throws FileNotFoundException,
IOException { IOException {
if (!enabled()) { if (!enabled()) {
@ -193,6 +193,7 @@ public class GeoserverRESTStyleTest extends GeoserverRESTTest {
} }
@Test
public void testUpdateDefaultStyle() throws FileNotFoundException, public void testUpdateDefaultStyle() throws FileNotFoundException,
IOException { IOException {
if (!enabled()) { if (!enabled()) {

View File

@ -31,6 +31,7 @@ import it.geosolutions.geoserver.rest.encoder.GSResourceEncoder.ProjectionPolicy
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -47,10 +48,7 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorkspaceTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorkspaceTest.class);
public GeoserverRESTWorkspaceTest(String testName) { @Test
super(testName);
}
public void testWorkspaces() { public void testWorkspaces() {
if (!enabled()) return; if (!enabled()) return;
deleteAll(); deleteAll();
@ -69,6 +67,7 @@ public class GeoserverRESTWorkspaceTest extends GeoserverRESTTest {
* remove workspace and all of its contents * remove workspace and all of its contents
* @throws IOException * @throws IOException
*/ */
@Test
public void testWorkspaceRemoval() throws IOException { public void testWorkspaceRemoval() throws IOException {
if (!enabled()) return; if (!enabled()) return;
deleteAll(); deleteAll();

View File

@ -32,6 +32,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.NameValuePair;
import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
@ -47,10 +48,7 @@ public class GeoserverRESTWorldImageTest extends GeoserverRESTTest {
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorldImageTest.class); private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTWorldImageTest.class);
public GeoserverRESTWorldImageTest(String testName) { @Test
super(testName);
}
public void testPublishWorldImage() throws IOException { public void testPublishWorldImage() throws IOException {
if (!enabled()) { if (!enabled()) {

Binary file not shown.