1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.fail;
|
---|
5 |
|
---|
6 | import java.net.URL;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.Test;
|
---|
9 | import org.junit.jupiter.api.Timeout;
|
---|
10 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
11 | import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
|
---|
12 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * Automatic test of imagery synchronization between JOSM and ELI.
|
---|
16 | * See <a href="https://josm.openstreetmap.de/wiki/ImageryCompare">JOSM wiki</a>
|
---|
17 | */
|
---|
18 | @BasicPreferences
|
---|
19 | @Timeout(60)
|
---|
20 | class ImageryCompareTestIT {
|
---|
21 |
|
---|
22 | private static final String BLACK_PREFIX = "<pre style=\"margin:3px;color:black\">";
|
---|
23 | private static final String RED_PREFIX = "<pre style=\"margin:3px;color:red\">";
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * Test of imagery entries.
|
---|
27 | * @throws Exception if an error occurs
|
---|
28 | */
|
---|
29 | @Test
|
---|
30 | void testImageryEntries() throws Exception {
|
---|
31 | // Increase traditional timeouts to avoid random problems
|
---|
32 | Config.getPref().putInt("socket.timeout.connect", 60);
|
---|
33 | Config.getPref().putInt("socket.timeout.read", 90);
|
---|
34 | System.out.println("Displaying only red entries. The test fails if at least one is found");
|
---|
35 | boolean rubricDisplayed = false;
|
---|
36 | boolean redFound = false;
|
---|
37 | String comparison = HttpClient.create(new URL("https://josm.openstreetmap.de/wiki/ImageryCompare")).connect().fetchContent();
|
---|
38 | String rubricLine = null;
|
---|
39 | for (String line : comparison.split("\n", -1)) {
|
---|
40 | boolean black = line.startsWith(BLACK_PREFIX);
|
---|
41 | if (black) {
|
---|
42 | rubricLine = line;
|
---|
43 | rubricDisplayed = false;
|
---|
44 | } else {
|
---|
45 | boolean red = line.startsWith(RED_PREFIX);
|
---|
46 | if (red) {
|
---|
47 | if (!rubricDisplayed && rubricLine != null) {
|
---|
48 | System.out.println(rubricLine.replace(BLACK_PREFIX, "").replace("</pre>", ""));
|
---|
49 | rubricDisplayed = true;
|
---|
50 | }
|
---|
51 | System.out.println(line.replace(RED_PREFIX, "").replace("</pre>", ""));
|
---|
52 | if (!redFound && red) {
|
---|
53 | redFound = true;
|
---|
54 | }
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|
58 | if (redFound) {
|
---|
59 | fail("Error: at least a red line has been found, see https://josm.openstreetmap.de/wiki/ImageryCompare for details");
|
---|
60 | } else {
|
---|
61 | System.out.println("No error :)");
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|