1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.io.IOException;
|
---|
8 | import java.nio.file.Files;
|
---|
9 | import java.nio.file.Path;
|
---|
10 | import java.nio.file.Paths;
|
---|
11 | import java.util.List;
|
---|
12 |
|
---|
13 | import org.junit.Rule;
|
---|
14 | import org.junit.Test;
|
---|
15 | import org.openstreetmap.josm.TestUtils;
|
---|
16 | import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import com.github.tomakehurst.wiremock.WireMockServer;
|
---|
20 | import com.github.tomakehurst.wiremock.client.WireMock;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Unit tests of {@link WMSImagery} class.
|
---|
26 | */
|
---|
27 | public class WMSImageryTest {
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Setup test
|
---|
31 | */
|
---|
32 | @Rule
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public JOSMTestRules test = new JOSMTestRules().platform().projection();
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
|
---|
38 | */
|
---|
39 | @Test
|
---|
40 | public void testWMSGetCapabilitiesException() {
|
---|
41 | Exception cause = new Exception("test");
|
---|
42 | WMSGetCapabilitiesException exc = new WMSGetCapabilitiesException(cause, "bar");
|
---|
43 | assertEquals(cause, exc.getCause());
|
---|
44 | assertEquals("bar", exc.getIncomingData());
|
---|
45 | exc = new WMSGetCapabilitiesException("foo", "bar");
|
---|
46 | assertEquals("foo", exc.getMessage());
|
---|
47 | assertEquals("bar", exc.getIncomingData());
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Non-regression test for bug #15730.
|
---|
52 | * @throws IOException if any I/O error occurs
|
---|
53 | * @throws WMSGetCapabilitiesException never
|
---|
54 | */
|
---|
55 | @Test
|
---|
56 | public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
|
---|
57 | WireMockServer wm = TestUtils.getWireMockServer(15730);
|
---|
58 | wm.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBodyFile("capabilities.xml")));
|
---|
59 | wm.start();
|
---|
60 | WMSImagery wms = new WMSImagery(wm.url("capabilities.xml"));
|
---|
61 | assertEquals(1, wms.getLayers().size());
|
---|
62 | assertTrue(wms.getLayers().get(0).getAbstract().startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM "));
|
---|
63 | wm.shutdown();
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Test
|
---|
67 | public void testNestedLayers() throws Exception {
|
---|
68 | WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
|
---|
69 | String getCapabilitiesBody = new String(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml")), "UTF-8");
|
---|
70 | getCapabilitiesMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(getCapabilitiesBody)));
|
---|
71 | getCapabilitiesMock.start();
|
---|
72 | WMSImagery wmsi = new WMSImagery(getCapabilitiesMock.url("/serwis"));
|
---|
73 | assertEquals(1, wmsi.getLayers().size());
|
---|
74 | assertEquals("Server WMS m.st. Warszawy", wmsi.getLayers().get(0).toString());
|
---|
75 | assertEquals(202, wmsi.getLayers().get(0).getChildren().size());
|
---|
76 | }
|
---|
77 |
|
---|
78 | /**
|
---|
79 | * Non-regression test for bug #16248.
|
---|
80 | * @throws IOException if any I/O error occurs
|
---|
81 | * @throws WMSGetCapabilitiesException never
|
---|
82 | */
|
---|
83 | @Test
|
---|
84 | public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
|
---|
85 | Path capabilitiesPath = Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"));
|
---|
86 | WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
|
---|
87 | getCapabilitiesMock.stubFor(
|
---|
88 | WireMock.get(WireMock.anyUrl())
|
---|
89 | .willReturn(WireMock.aResponse().withBody(Files.readAllBytes(capabilitiesPath))));
|
---|
90 | getCapabilitiesMock.start();
|
---|
91 | WMSImagery wms = new WMSImagery(getCapabilitiesMock.url("any"));
|
---|
92 | assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k", wms.buildRootUrl());
|
---|
93 | assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName());
|
---|
94 | assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25kFORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&"
|
---|
95 | + "LAYERS=wms.hgis.cartomatic.pl&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
|
---|
96 | wms.buildGetMapUrl(wms.getLayers(), (List<String>)null, true));
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|