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

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

Imagery definition refactor

Extend imagery definitions by:

  • allowing setting default layers for WMS_ENDPOINT and WMTS
  • allowing setting minimum expires time for tile for this imagery
  • allowing setting custom headers that will be sent for all requests

(get map, get capabilities) for this imagery

Additional changes in code:

  • use TileJobOptions to pass miscellaneous options to loaders
  • refactor WMSImagery to use SAX parser

See: #15981, #7953, #16224, #15940, #16249

  • Property svn:eol-style set to native
File size: 4.2 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.Path;
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.WireMockServer;
20import com.github.tomakehurst.wiremock.client.WireMock;
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().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
Note: See TracBrowser for help on using the repository browser.