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

Last change on this file since 14411 was 14411, checked in by wiktorn, 6 years ago

Skip unkown tags in WMS Getcapabilities

In Layer definition, if there is any other tag than ones that are interpreted,
move to the end of the tag, as it may be complex tag and affect further parsing.

Closes: #16940

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