Skip to content

Commit 8779687

Browse files
committed
Add acceptance test
1 parent f4c126c commit 8779687

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

docker-compose.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,20 @@ services:
1818
JASPER_LOG_LEVEL: DEBUG
1919
JAVA_OPTS: '-Dmapfish.image.plugins=true'
2020

21+
print-context-path:
22+
image: mapfish_print_tester
23+
user: ${USER_ID}
24+
volumes:
25+
- ./examples/src/test/resources/examples:/usr/local/tomcat/webapps/ROOT/print-apps:ro
26+
ports:
27+
- 8081:8080
28+
environment:
29+
PRINT_YAML_MAX_ALIASES: '200'
30+
LOG_LEVEL: DEBUG
31+
JASPER_LOG_LEVEL: DEBUG
32+
JAVA_OPTS: '-Dmapfish.image.plugins=true'
33+
CONTEXT_PATH: /print
34+
2135
tests:
2236
image: mapfish_print_builder
2337
user: ${USER_ID}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package org.mapfish.print;
2+
3+
import static org.junit.jupiter.api.Assertions.*;
4+
5+
import java.io.IOException;
6+
import java.net.URI;
7+
import java.net.URISyntaxException;
8+
import java.util.stream.Collectors;
9+
import java.util.stream.Stream;
10+
import org.json.JSONArray;
11+
import org.junit.jupiter.api.Test;
12+
import org.junit.jupiter.api.extension.ExtendWith;
13+
import org.mapfish.print.servlet.MapPrinterServlet;
14+
import org.springframework.http.HttpMethod;
15+
import org.springframework.http.HttpStatus;
16+
import org.springframework.http.client.ClientHttpRequest;
17+
import org.springframework.http.client.ClientHttpResponse;
18+
import org.springframework.test.context.junit.jupiter.SpringExtension;
19+
20+
/**
21+
* Test the servlet print API.
22+
*
23+
* <p>To run this test make sure that the test servers are running:
24+
*
25+
* <p>./gradlew examples:farmRun
26+
*
27+
* <p>Or run the tests with the following task (which automatically starts the servers):
28+
*
29+
* <p>./gradlew examples:geoserver
30+
*/
31+
@ExtendWith(SpringExtension.class)
32+
public class ContextPathTest extends AbstractApiTest {
33+
34+
protected static final String PRINT_SERVER = "http://print-context-path:8080/";
35+
36+
protected ClientHttpRequest getRequest(String path, HttpMethod method)
37+
throws IOException, URISyntaxException {
38+
var actualUrl =
39+
Stream.of(path.split("/")).filter(s -> !s.isEmpty()).collect(Collectors.joining("/"));
40+
return httpRequestFactory.createRequest(new URI(PRINT_SERVER + actualUrl), method);
41+
}
42+
43+
@Test
44+
public void testIndexRedirect() throws Exception {
45+
ClientHttpRequest request = getRequest("print", HttpMethod.GET);
46+
try (ClientHttpResponse response = request.execute()) {
47+
assertEquals(HttpStatus.FOUND, response.getStatusCode());
48+
assertEquals("/print/", response.getHeaders().getLocation().toString());
49+
}
50+
}
51+
52+
@Test
53+
public void testIndex() throws Exception {
54+
ClientHttpRequest request = getRequest("print/", HttpMethod.GET);
55+
try (ClientHttpResponse response = request.execute()) {
56+
assertEquals(HttpStatus.OK, response.getStatusCode());
57+
assertEquals("text/html", response.getHeaders().getContentType().toString());
58+
}
59+
}
60+
61+
@Test
62+
public void testListApps() throws Exception {
63+
ClientHttpRequest request =
64+
getRequest("print" + MapPrinterServlet.LIST_APPS_URL, HttpMethod.GET);
65+
try (ClientHttpResponse response = request.execute()) {
66+
assertEquals(HttpStatus.OK, response.getStatusCode());
67+
assertEquals(getJsonMediaType(), response.getHeaders().getContentType());
68+
final JSONArray appIdsJson = new JSONArray(getBodyAsText(response));
69+
assertFalse(appIdsJson.isEmpty());
70+
}
71+
}
72+
}

0 commit comments

Comments
 (0)