|
5 | 5 | package org.geoserver.cloud.restconfig;
|
6 | 6 |
|
7 | 7 | import static org.assertj.core.api.Assertions.assertThat;
|
| 8 | +import static org.junit.Assert.assertTrue; |
8 | 9 | import static org.springframework.http.MediaType.APPLICATION_JSON;
|
9 | 10 | import static org.springframework.http.MediaType.APPLICATION_XML;
|
10 | 11 | import static org.springframework.http.MediaType.TEXT_HTML;
|
11 | 12 |
|
| 13 | +import java.io.IOException; |
| 14 | +import java.nio.file.Files; |
| 15 | +import java.nio.file.Path; |
12 | 16 | import org.geoserver.catalog.SLDHandler;
|
13 | 17 | import org.junit.jupiter.api.BeforeEach;
|
| 18 | +import org.junit.jupiter.api.MethodOrderer; |
| 19 | +import org.junit.jupiter.api.Order; |
14 | 20 | import org.junit.jupiter.api.Test;
|
| 21 | +import org.junit.jupiter.api.TestMethodOrder; |
| 22 | +import org.junit.jupiter.api.io.TempDir; |
15 | 23 | import org.springframework.beans.factory.annotation.Autowired;
|
16 | 24 | import org.springframework.boot.test.context.SpringBootTest;
|
17 | 25 | import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
18 | 26 | import org.springframework.boot.test.web.client.TestRestTemplate;
|
19 | 27 | import org.springframework.http.HttpStatus;
|
20 | 28 | import org.springframework.http.MediaType;
|
21 | 29 | import org.springframework.http.ResponseEntity;
|
| 30 | +import org.springframework.test.annotation.DirtiesContext; |
22 | 31 | import org.springframework.test.context.ActiveProfiles;
|
| 32 | +import org.springframework.test.context.DynamicPropertyRegistry; |
| 33 | +import org.springframework.test.context.DynamicPropertySource; |
23 | 34 |
|
24 | 35 | @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
| 36 | +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
25 | 37 | @ActiveProfiles("test")
|
26 | 38 | class RestConfigApplicationTest {
|
27 | 39 |
|
28 | 40 | @Autowired
|
29 | 41 | private TestRestTemplate restTemplate;
|
30 | 42 |
|
| 43 | + static @TempDir Path datadir; |
| 44 | + |
| 45 | + @DynamicPropertySource |
| 46 | + static void setUpDataDir(DynamicPropertyRegistry registry) throws IOException { |
| 47 | + var gwcdir = datadir.resolve("gwc"); |
| 48 | + if (!Files.exists(gwcdir)) { |
| 49 | + Files.createDirectory(gwcdir); |
| 50 | + } |
| 51 | + registry.add("geoserver.backend.data-directory.location", datadir::toAbsolutePath); |
| 52 | + registry.add("gwc.cache-directory", gwcdir::toAbsolutePath); |
| 53 | + } |
| 54 | + |
31 | 55 | @BeforeEach
|
32 |
| - void before() { |
| 56 | + void before() throws Exception { |
33 | 57 | restTemplate = restTemplate.withBasicAuth("admin", "geoserver");
|
34 | 58 | }
|
35 | 59 |
|
| 60 | + /** |
| 61 | + * REVISIT: for some reason, running the REST API tests right after starting off |
| 62 | + * an empty data directory produce a 403 forbidden response. We're hence forcing |
| 63 | + * the order of the tests and the reload of the context for the time being |
| 64 | + */ |
36 | 65 | @Test
|
37 |
| - void testDefaultContentType() { |
| 66 | + @Order(1) |
| 67 | + @DirtiesContext |
| 68 | + void smokeTest() { |
| 69 | + assertTrue(true); |
| 70 | + } |
38 | 71 |
|
| 72 | + @Test |
| 73 | + @Order(2) |
| 74 | + @DirtiesContext |
| 75 | + void testDefaultContentType() { |
39 | 76 | testPathExtensionContentType("/rest/workspaces", APPLICATION_JSON);
|
40 | 77 | testPathExtensionContentType("/rest/layers", APPLICATION_JSON);
|
41 | 78 | }
|
42 | 79 |
|
43 | 80 | @Test
|
| 81 | + @Order(3) |
| 82 | + @DirtiesContext |
44 | 83 | void testPathExtensionContentNegotiation() {
|
45 |
| - |
46 | 84 | testPathExtensionContentType("/rest/styles/line.json", APPLICATION_JSON);
|
47 | 85 | testPathExtensionContentType("/rest/styles/line.xml", APPLICATION_XML);
|
48 | 86 | testPathExtensionContentType("/rest/styles/line.html", TEXT_HTML);
|
|
0 commit comments