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

Last change on this file since 18870 was 18870, checked in by taylor.smock, 11 months ago

See #16567: Update to JUnit 5

This converts most tests to use @Annotations. There are also some performance
improvements as it relates to tests.

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