Skip to content

Commit b136bba

Browse files
committed
Add acceptence test
1 parent 8269a67 commit b136bba

File tree

2 files changed

+74
-0
lines changed

2 files changed

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

0 commit comments

Comments
 (0)