159 changes: 32 additions & 127 deletions core/src/test/java/org/mapfish/print/servlet/MapPrinterServletTest.java

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions examples/src/test/java/org/mapfish/print/AbstractApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,4 @@ protected MediaType getJsonMediaType() {
params.put("charset", "utf-8");
return new MediaType("application", "json", params);
}

protected MediaType getJavaScriptMediaType() {
Map<String, String> params = new HashMap<>();
params.put("charset", "utf-8");
return new MediaType("application", "javascript", params);
}
}
84 changes: 2 additions & 82 deletions examples/src/test/java/org/mapfish/print/PrintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,6 @@ public void testListApps() throws Exception {
}
}

@Test
public void testListAppsJsonp() throws Exception {
ClientHttpRequest request =
getPrintRequest(MapPrinterServlet.LIST_APPS_URL + "?jsonp=listApps", HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());

String responseAsText = getBodyAsText(response);
assertTrue(responseAsText.startsWith("listApps("));

responseAsText = responseAsText.replace("listApps(", "").replace(");", "");
final JSONArray appIdsJson = new JSONArray(responseAsText);
assertTrue(appIdsJson.length() > 0);
}
}

@Test
public void testGetCapabilities_NoApp() throws Exception {
ClientHttpRequest request = getPrintRequest(MapPrinterServlet.CAPABILITIES_URL, HttpMethod.GET);
Expand Down Expand Up @@ -107,31 +90,6 @@ public void testGetCapabilitiesPretty_NoApp() throws Exception {
}
}

@Test
public void testGetCapabilitiesJsonp_NoApp() throws Exception {
ClientHttpRequest request =
getPrintRequest(MapPrinterServlet.CAPABILITIES_URL + "?jsonp=printCapabilities",
HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());
assertTrue(getBodyAsText(response).startsWith("printCapabilities("));
}
}

@Test
public void testGetCapabilitiesJsonpPretty_NoApp() throws Exception {
ClientHttpRequest request = getPrintRequest(
MapPrinterServlet.CAPABILITIES_URL + "?pretty=true&jsonp=printCapabilities", HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());
String responseAsText = getBodyAsText(response);
assertTrue(responseAsText.startsWith("printCapabilities("));
assertTrue(responseAsText.contains("\n"));
}
}

@Test
public void testExampleRequest_NoApp() throws Exception {
ClientHttpRequest request = getPrintRequest(MapPrinterServlet.EXAMPLE_REQUEST_URL, HttpMethod.GET);
Expand All @@ -142,23 +100,6 @@ public void testExampleRequest_NoApp() throws Exception {
}
}

@Test
public void testExampleRequestJsonp_NoApp() throws Exception {
ClientHttpRequest request =
getPrintRequest(MapPrinterServlet.EXAMPLE_REQUEST_URL + "?jsonp=exampleRequest",
HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());

String responseAsText = getBodyAsText(response);
assertTrue(responseAsText.startsWith("exampleRequest("));

responseAsText = responseAsText.replace("exampleRequest(", "").replace(");", "");
checkExampleRequest(responseAsText);
}
}

@Test
public void testExampleRequest_App() throws Exception {
ClientHttpRequest request =
Expand All @@ -170,23 +111,6 @@ public void testExampleRequest_App() throws Exception {
}
}

@Test
public void testExampleRequestJsonp_App() throws Exception {
ClientHttpRequest request =
getPrintRequest("geoext" + MapPrinterServlet.EXAMPLE_REQUEST_URL + "?jsonp=exampleRequest",
HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());

String responseAsText = getBodyAsText(response);
assertTrue(responseAsText.startsWith("exampleRequest("));

responseAsText = responseAsText.replace("exampleRequest(", "").replace(");", "");
checkExampleRequest(responseAsText);
}
}

private void checkExampleRequest(String responseAsText) throws JSONException {
JSONObject samplesRequest = new JSONObject(responseAsText);
final Iterator keys = samplesRequest.keys();
Expand Down Expand Up @@ -308,17 +232,13 @@ private void testCreateReport(String requestPath, String printSpec) throws Excep
}
}

// check status with JSONP
request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json?jsonp=getStatus",
request = getPrintRequest(MapPrinterServlet.STATUS_URL + "/" + ref + ".json",
HttpMethod.GET);
try (ClientHttpResponse response = request.execute()) {
assertEquals(HttpStatus.OK, response.getStatusCode());
assertEquals(getJavaScriptMediaType(), response.getHeaders().getContentType());
assertEquals(getJsonMediaType(), response.getHeaders().getContentType());

String responseAsText = getBodyAsText(response);
assertTrue(responseAsText.startsWith("getStatus("));

responseAsText = responseAsText.replace("getStatus(", "").replace(");", "");
JSONObject statusResult = new JSONObject(responseAsText);

assertTrue(statusResult.has(MapPrinterServlet.JSON_DONE));
Expand Down