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

Last change on this file was 19155, checked in by taylor.smock, 22 months ago

Fix tests broken by r19152

  • Property svn:eol-style set to native
File size: 6.9 KB
RevLine 
[11974]1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.imagery;
3
[18106]4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNull;
6import static org.junit.jupiter.api.Assertions.assertTrue;
[11974]7
[13274]8import java.io.IOException;
[13733]9import java.nio.file.Files;
10import java.nio.file.Paths;
11import java.util.List;
[13274]12
[19155]13import com.github.tomakehurst.wiremock.junit5.WireMockRuntimeInfo;
14import org.junit.jupiter.api.BeforeEach;
[18106]15import org.junit.jupiter.api.Test;
[13274]16import org.openstreetmap.josm.TestUtils;
[11974]17import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
[18870]18import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
[18106]19import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
[18870]20import org.openstreetmap.josm.testutils.annotations.Projection;
[11974]21
[13733]22import com.github.tomakehurst.wiremock.client.WireMock;
23
[11974]24/**
25 * Unit tests of {@link WMSImagery} class.
26 */
[18870]27@BasicPreferences(true)
[18106]28@BasicWiremock
[18870]29@Projection
[18106]30class WMSImageryTest {
31
[19155]32 private WireMockRuntimeInfo tileServer;
33
34 @BeforeEach
35 void setup(WireMockRuntimeInfo wireMockRuntimeRule) {
36 this.tileServer = wireMockRuntimeRule;
37 }
38
[11974]39 /**
40 * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
41 */
42 @Test
[18106]43 void testWMSGetCapabilitiesException() {
[11974]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 }
[13274]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
[18106]59 void testTicket15730() throws IOException, WMSGetCapabilitiesException {
[19155]60 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
[13735]61 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml"))
62 )));
63
[19155]64 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/capabilities.xml");
[13735]65 assertEquals(1, wms.getLayers().size());
66 assertTrue(wms.getLayers().get(0).getAbstract().startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM "));
[13274]67 }
[13699]68
[13733]69 @Test
[18106]70 void testNestedLayers() throws Exception {
[19155]71 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
[13735]72 Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml")))));
[19155]73 WMSImagery wmsi = new WMSImagery(tileServer.getHttpBaseUrl() + "/serwis");
[13733]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
[13699]79 /**
80 * Non-regression test for bug #16248.
81 * @throws IOException if any I/O error occurs
82 * @throws WMSGetCapabilitiesException never
83 */
84 @Test
[18106]85 void testTicket16248() throws IOException, WMSGetCapabilitiesException {
[16412]86 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml")));
[19155]87 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
88 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any");
[13878]89 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k?", wms.buildRootUrl());
[13733]90 assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName());
[16412]91 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.3.0&SERVICE=WMS&REQUEST=GetMap&"
92 + "LAYERS=wms.hgis.cartomatic.pl&STYLES=&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
[13742]93 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true));
[13699]94 }
[13870]95
96 /**
[16412]97 * Non-regression test for bug #19193.
98 * @throws IOException if any I/O error occurs
99 * @throws WMSGetCapabilitiesException never
100 */
101 @Test
[18106]102 void testTicket19193() throws IOException, WMSGetCapabilitiesException {
[16412]103 byte[] capabilities = Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(19193, "capabilities.xml")));
[19155]104 tileServer.getWireMock().register(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(capabilities)));
105 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any");
[16412]106 assertEquals("https://inspire.brandenburg.de/services/gn_alkis_wms?", wms.buildRootUrl());
107 assertEquals(1, wms.getLayers().size());
108 assertNull(wms.getLayers().get(0).getName());
109 assertEquals("INSPIRE GN ALKIS BB", wms.getLayers().get(0).getTitle());
110 assertEquals("https://inspire.brandenburg.de/services/gn_alkis_wms?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.3.0&"
111 + "SERVICE=WMS&REQUEST=GetMap&LAYERS=null&STYLES=&CRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
112 wms.buildGetMapUrl(wms.getLayers(), (List<String>) null, true));
113 }
114
115 /**
[13870]116 * Regression test for bug #16333 (null style name)
117 * @throws IOException if any I/O error occurs
118 * @throws WMSGetCapabilitiesException never
119 */
120 @Test
[18106]121 void testTicket16333() throws IOException, WMSGetCapabilitiesException {
[19155]122 tileServer.getWireMock().register(
[13870]123 WireMock.get(WireMock.anyUrl())
124 .willReturn(WireMock.aResponse().withBody(
125 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16333, "capabilities.xml")))
126 ))
127 );
[19155]128 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any");
[13870]129 assertEquals("https://duinoord.xs4all.nl/geoserver/ows?SERVICE=WMS&", wms.buildRootUrl());
[18106]130 assertNull(wms.getLayers().get(0).getName());
[13870]131 assertEquals("", wms.getLayers().get(0).getTitle());
132
133 assertEquals("bag:Matching Street", wms.getLayers().get(0).getChildren().get(0).getName());
134 assertEquals("Dichtstbijzijnde straat", wms.getLayers().get(0).getChildren().get(0).getTitle());
[14411]135 }
[13870]136
[14411]137 @Test
[18106]138 void testForTitleWithinAttribution_ticket16940() throws IOException, WMSGetCapabilitiesException {
[19155]139 tileServer.getWireMock().register(
[14411]140 WireMock.get(WireMock.anyUrl())
141 .willReturn(WireMock.aResponse().withBody(
142 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16940, "capabilities.xml")))
143 ))
144 );
[19155]145 WMSImagery wms = new WMSImagery(tileServer.getHttpBaseUrl() + "/any");
[14411]146 assertEquals("Hipsográfico", wms.getLayers().stream().findFirst().get().getTitle());
[13870]147 }
[11974]148}
Note: See TracBrowser for help on using the repository browser.