source: josm/trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java@ 16412

Last change on this file since 16412 was 16412, checked in by simon04, 5 years ago

fix #19193 - WMSImagery: fix parsing of version 1.3.0 capabilities

For the constant CAPABILITIES_ROOT_130, the namespaceURI and localPart were interchanged.

  • Property svn:eol-style set to native
File size: 6.7 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.imagery;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNull;
6import static org.junit.Assert.assertTrue;
7
8import java.io.IOException;
9import java.nio.file.Files;
10import java.nio.file.Paths;
11import java.util.List;
12
13import org.junit.Rule;
14import org.junit.Test;
15import org.openstreetmap.josm.TestUtils;
16import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
17import org.openstreetmap.josm.testutils.JOSMTestRules;
18
19import com.github.tomakehurst.wiremock.client.WireMock;
20import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
21import com.github.tomakehurst.wiremock.junit.WireMockRule;
22
23import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
24
25/**
26 * Unit tests of {@link WMSImagery} class.
27 */
28public class WMSImageryTest {
29
30 /**
31 * Setup test
32 */
33 @Rule
34 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
35 public JOSMTestRules test = new JOSMTestRules().projection();
36
37 @Rule
38 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
39 .dynamicPort());
40 /**
41 * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
42 */
43 @Test
44 public void testWMSGetCapabilitiesException() {
45 Exception cause = new Exception("test");
46 WMSGetCapabilitiesException exc = new WMSGetCapabilitiesException(cause, "bar");
47 assertEquals(cause, exc.getCause());
48 assertEquals("bar", exc.getIncomingData());
49 exc = new WMSGetCapabilitiesException("foo", "bar");
50 assertEquals("foo", exc.getMessage());
51 assertEquals("bar", exc.getIncomingData());
52 }
53
54 /**
55 * Non-regression test for bug #15730.
56 * @throws IOException if any I/O error occurs
57 * @throws WMSGetCapabilitiesException never
58 */
59 @Test
60 public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
61 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
62 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml"))
63 )));
64
65 WMSImagery wms = new WMSImagery(tileServer.url("capabilities.xml"));
66 assertEquals(1, wms.getLayers().size());
67 assertTrue(wms.getLayers().get(0).getAbstract().startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM "));
68 }
69
70 @Test
71 public void testNestedLayers() throws Exception {
72 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
73 Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml")))));
74 WMSImagery wmsi = new WMSImagery(tileServer.url("/serwis"));
75 assertEquals(1, wmsi.getLayers().size());
76 assertEquals("Server WMS m.st. Warszawy", wmsi.getLayers().get(0).toString());
77 assertEquals(202, wmsi.getLayers().get(0).getChildren().size());
78 }
79
80 /**
81 * Non-regression test for bug #16248.
82 * @throws IOException if any I/O error occurs
83 * @throws WMSGetCapabilitiesException never
84 */
85 @Test
86 public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
87 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml")));
88 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
89 WMSImagery wms = new WMSImagery(tileServer.url("any"));
90 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k?", wms.buildRootUrl());
91 assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName());
92 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap&"
93 + "LAYERS=wms.hgis.cartomatic.pl&STYLES=&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
94 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true));
95 }
96
97 /**
98 * Non-regression test for bug #19193.
99 * @throws IOException if any I/O error occurs
100 * @throws WMSGetCapabilitiesException never
101 */
102 @Test
103 public void testTicket19193() throws IOException, WMSGetCapabilitiesException {
104 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(19193, "capabilities.xml")));
105 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
106 WMSImagery wms = new WMSImagery(tileServer.url("any"));
107 assertEquals("https://inspire.brandenburg.de/services/gn_alkis_wms?", wms.buildRootUrl());
108 assertEquals(1, wms.getLayers().size());
109 assertNull(wms.getLayers().get(0).getName());
110 assertEquals("INSPIRE GN ALKIS BB", wms.getLayers().get(0).getTitle());
111 assertEquals("https://inspire.brandenburg.de/services/gn_alkis_wms?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.3.0&"
112 + "SERVICE=WMS&REQUEST=GetMap&LAYERS=null&STYLES=&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
113 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true));
114 }
115
116 /**
117 * Regression test for bug #16333 (null style name)
118 * @throws IOException if any I/O error occurs
119 * @throws WMSGetCapabilitiesException never
120 */
121 @Test
122 public void testTicket16333() throws IOException, WMSGetCapabilitiesException {
123 tileServer.stubFor(
124 WireMock.get(WireMock.anyUrl())
125 .willReturn(WireMock.aResponse().withBody(
126 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16333, "capabilities.xml")))
127 ))
128 );
129 WMSImagery wms = new WMSImagery(tileServer.url("any"));
130 assertEquals("https://duinoord.xs4all.nl/geoserver/ows?SERVICE=WMS&", wms.buildRootUrl());
131 assertEquals(null, wms.getLayers().get(0).getName());
132 assertEquals("", wms.getLayers().get(0).getTitle());
133
134 assertEquals("bag:Matching Street", wms.getLayers().get(0).getChildren().get(0).getName());
135 assertEquals("Dichtstbijzijnde straat", wms.getLayers().get(0).getChildren().get(0).getTitle());
136 }
137
138 @Test
139 public void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException {
140 tileServer.stubFor(
141 WireMock.get(WireMock.anyUrl())
142 .willReturn(WireMock.aResponse().withBody(
143 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16940, "capabilities.xml")))
144 ))
145 );
146 WMSImagery wms = new WMSImagery(tileServer.url("any"));
147 assertEquals("Hipsográfico", wms.getLayers().stream().findFirst().get().getTitle());
148 }
149}
150
Note: See TracBrowser for help on using the repository browser.