Skip to content

Commit e705fc1

Browse files
committed
Add acceptance test
1 parent f4c126c commit e705fc1

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed

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: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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.condition.EnabledIfEnvironmentVariable;
13+
import org.junit.jupiter.api.extension.ExtendWith;
14+
import org.mapfish.print.servlet.MapPrinterServlet;
15+
import org.springframework.http.HttpMethod;
16+
import org.springframework.http.HttpStatus;
17+
import org.springframework.http.client.ClientHttpRequest;
18+
import org.springframework.http.client.ClientHttpResponse;
19+
import org.springframework.test.context.junit.jupiter.SpringExtension;
20+
21+
/**
22+
* Test the servlet print API.
23+
*
24+
* <p>To run this test make sure that the test servers are running:
25+
*
26+
* <p>./gradlew examples:farmRun
27+
*
28+
* <p>Or run the tests with the following task (which automatically starts the servers):
29+
*
30+
* <p>./gradlew examples:geoserver
31+
*/
32+
@ExtendWith(SpringExtension.class)
33+
public class ContextPathTest extends AbstractApiTest {
34+
35+
protected static final String PRINT_SERVER = "http://print-context-path:8080/";
36+
37+
protected ClientHttpRequest getRequest(String path, HttpMethod method)
38+
throws IOException, URISyntaxException {
39+
var actualUrl =
40+
Stream.of(path.split("/")).filter(s -> !s.isEmpty()).collect(Collectors.joining("/"));
41+
return httpRequestFactory.createRequest(new URI(PRINT_SERVER + actualUrl), method);
42+
}
43+
44+
@Test
45+
@EnabledIfEnvironmentVariable(named = "MAPFISH_PRINT_TESTS_CLUSTER_MODE", matches = "true")
46+
public void testIndexRedirect() throws Exception {
47+
ClientHttpRequest request = getRequest("print", HttpMethod.GET);
48+
try (ClientHttpResponse response = request.execute()) {
49+
assertEquals(HttpStatus.FOUND, response.getStatusCode());
50+
assertEquals("/print/", response.getHeaders().getLocation().toString());
51+
}
52+
}
53+
54+
@Test
55+
@EnabledIfEnvironmentVariable(named = "MAPFISH_PRINT_TESTS_CLUSTER_MODE", matches = "true")
56+
public void testIndex() throws Exception {
57+
ClientHttpRequest request = getRequest("print/", HttpMethod.GET);
58+
try (ClientHttpResponse response = request.execute()) {
59+
assertEquals(HttpStatus.OK, response.getStatusCode());
60+
assertEquals("text/html", response.getHeaders().getContentType().toString());
61+
}
62+
}
63+
64+
@Test
65+
@EnabledIfEnvironmentVariable(named = "MAPFISH_PRINT_TESTS_CLUSTER_MODE", matches = "true")
66+
public void testListApps() throws Exception {
67+
ClientHttpRequest request =
68+
getRequest("print" + MapPrinterServlet.LIST_APPS_URL, HttpMethod.GET);
69+
try (ClientHttpResponse response = request.execute()) {
70+
assertEquals(HttpStatus.OK, response.getStatusCode());
71+
assertEquals(getJsonMediaType(), response.getHeaders().getContentType());
72+
final JSONArray appIdsJson = new JSONArray(getBodyAsText(response));
73+
assertFalse(appIdsJson.isEmpty());
74+
}
75+
}
76+
}

0 commit comments

Comments
 (0)