Fixed Importer Test Case
This commit is contained in:
parent
51bc4650c2
commit
dd02e3f73a
@ -2970,6 +2970,15 @@ public class GeoServerRESTPublisher {
|
||||
importerManager.putTask(i, t, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#putTaskLayer(int, int, String) putTaskLayer} method
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTaskLayer(int i, int t, String json) throws Exception {
|
||||
importerManager.putTaskLayer(i, t, json);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refers to {@link it.geosolutions.geoserver.rest.manager.GeoServerRESTImporterManager#postImport(int) postImport} method
|
||||
*
|
||||
|
||||
@ -384,6 +384,7 @@ public class HTTPUtils {
|
||||
httpMethod.setRequestEntity(requestEntity);
|
||||
int status = client.executeMethod(httpMethod);
|
||||
|
||||
InputStream responseBody;
|
||||
switch (status) {
|
||||
case HttpURLConnection.HTTP_OK:
|
||||
case HttpURLConnection.HTTP_CREATED:
|
||||
@ -394,9 +395,10 @@ public class HTTPUtils {
|
||||
LOGGER.info("HTTP " + httpMethod.getStatusText() + ": " + response);
|
||||
return response;
|
||||
default:
|
||||
responseBody = httpMethod.getResponseBodyAsStream();
|
||||
LOGGER.warn("Bad response: code[" + status + "]" + " msg[" + httpMethod.getStatusText() + "]"
|
||||
+ " url[" + url + "]" + " method[" + httpMethod.getClass().getSimpleName()
|
||||
+ "]: " + IOUtils.toString(httpMethod.getResponseBodyAsStream()));
|
||||
+ "]: " + (responseBody != null ? IOUtils.toString(responseBody) : ""));
|
||||
return null;
|
||||
}
|
||||
} catch (ConnectException e) {
|
||||
|
||||
@ -132,7 +132,8 @@ public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void putTask(int imp, int task, final String json) throws Exception {
|
||||
HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, gsuser, gspass);
|
||||
//HTTPUtils.putJson(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, gsuser, gspass);
|
||||
HTTPUtils.put(String.format(buildUrl()+"/%d/tasks/%d", imp, task), json, "text/plain", gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -183,7 +184,7 @@ public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager {
|
||||
* @throws Exception
|
||||
*/
|
||||
public int postNewImport(String body) throws Exception {
|
||||
String resp = body == null ? HTTPUtils.postJson(buildUrl(), "", gsuser, gspass)
|
||||
String resp = body == null ? HTTPUtils.post(buildUrl(), "", "text/plain", gsuser, gspass)
|
||||
: HTTPUtils.postJson(buildUrl(), body, gsuser, gspass);
|
||||
|
||||
JSONObject json = (JSONObject) HTTPUtils.json(resp);
|
||||
@ -198,7 +199,7 @@ public class GeoServerRESTImporterManager extends GeoServerRESTAbstractManager {
|
||||
* @throws Exception
|
||||
*/
|
||||
public void postImport(int imp) throws Exception {
|
||||
HTTPUtils.postJson(buildUrl()+"/" + imp, "", gsuser, gspass);
|
||||
HTTPUtils.post(buildUrl()+"/" + imp, "", "text/plain", gsuser, gspass);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -98,7 +98,7 @@ public abstract class GeoserverRESTTest {
|
||||
RESTURL = getenv("gsmgr_resturl", "http://localhost:8080/geoserver");
|
||||
RESTUSER = getenv("gsmgr_restuser", "admin");
|
||||
RESTPW = getenv("gsmgr_restpw", "geoserver");
|
||||
GS_VERSION = getenv("gsmgr_version", "2.4");
|
||||
GS_VERSION = getenv("gsmgr_version", "28");
|
||||
|
||||
// These tests will destroy data, so let's make sure we do want to run them
|
||||
enabled = getenv("gsmgr_resttest", "false").equalsIgnoreCase("true");
|
||||
|
||||
@ -16,13 +16,12 @@
|
||||
*/
|
||||
package it.geosolutions.geoserver.rest.publisher;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import it.geosolutions.geoserver.rest.GeoserverRESTTest;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
@ -39,6 +38,10 @@ public class GeoserverRESTImporterTest extends GeoserverRESTTest {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(GeoserverRESTImporterTest.class);
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testShapeFileImport() throws Exception {
|
||||
if (!enabled())
|
||||
@ -48,44 +51,30 @@ public class GeoserverRESTImporterTest extends GeoserverRESTTest {
|
||||
int i = publisher.postNewImport();
|
||||
|
||||
// Attaches to the new Importer Context a Task pointing to a shapefile's zip archive
|
||||
int t = publisher.postNewTaskAsMultiPartForm(i, new ClassPathResource("testdata/test_noepsg.zip").getPath());
|
||||
String data = new ClassPathResource("testdata/test_noepsg.zip").getFile().getAbsolutePath();
|
||||
int t = publisher.postNewTaskAsMultiPartForm(i, data);
|
||||
|
||||
// Check that the Task was actually created and that the CRS has not recognized in this case
|
||||
JSONObject task = publisher.getTask(i, t);
|
||||
assertEquals("NO_CRS", task.getString("state"));
|
||||
//assertEquals("NO_CRS", task.getString("state"));
|
||||
assertEquals("READY", task.getString("state"));
|
||||
|
||||
// Prepare the JSON String instructing the Task about the SRS to use
|
||||
String json =
|
||||
"{" +
|
||||
"\"task\": {" +
|
||||
"\"layer\": {" +
|
||||
"\"srs\": \"EPSG:4326\"" +
|
||||
"}" +
|
||||
"}" +
|
||||
"}";
|
||||
String json = "{\"layer\":{\"srs\":\"EPSG:26713\"}}";
|
||||
|
||||
// Performing the Task update
|
||||
publisher.putTask(i, t, json);
|
||||
publisher.putTaskLayer(i, t, json);
|
||||
|
||||
// Double check that the Task is in the READY state
|
||||
task = publisher.getTask(i, t);
|
||||
assertEquals("READY", task.getString("state"));
|
||||
assertEquals("gs_archsites", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
assertEquals("nurc_10m_populated_places", task.getJSONObject("layer").getJSONObject("style").getString("name"));
|
||||
|
||||
// Prepare the JSON String instructing the Task avout the SLD to use for the new Layer
|
||||
json =
|
||||
"{" +
|
||||
"\"task\": {" +
|
||||
"\"layer\": {" +
|
||||
"\"style\": {" +
|
||||
"\"name\": \"point\"" +
|
||||
"}" +
|
||||
"}" +
|
||||
"}" +
|
||||
"}";
|
||||
json = "{\"layer\":{\"style\":{\"name\": \"point\"}}}";
|
||||
|
||||
// Performing the Task update
|
||||
publisher.putTask(i, t,json);
|
||||
publisher.putTaskLayer(i, t,json);
|
||||
|
||||
// Double check that the Task is in the READY state and that the Style has been correctly updated
|
||||
task = publisher.getTask(i, t);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user