Ignore:
Timestamp:
2018-05-12T14:18:57+02:00 (3 years ago)
Author:
wiktorn
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java

    r13699 r13733  
    66
    77import java.io.IOException;
    8 import java.io.InputStream;
     8import java.nio.file.Files;
     9import java.nio.file.Path;
     10import java.nio.file.Paths;
     11import java.util.List;
    912
    1013import org.junit.Rule;
     
    1316import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
    1417import org.openstreetmap.josm.testutils.JOSMTestRules;
     18
     19import com.github.tomakehurst.wiremock.WireMockServer;
     20import com.github.tomakehurst.wiremock.client.WireMock;
    1521
    1622import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2632    @Rule
    2733    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    28     public JOSMTestRules test = new JOSMTestRules();
     34    public JOSMTestRules test = new JOSMTestRules().platform().projection();
    2935
    3036    /**
     
    4955    @Test
    5056    public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
    51         try (InputStream is = TestUtils.getRegressionDataStream(15730, "capabilities.xml")) {
    52             WMSImagery wms = new WMSImagery();
    53             wms.parseCapabilities(null, is);
    54             assertEquals(1, wms.getLayers().size());
    55             assertTrue(wms.getLayers().get(0).abstr.startsWith("South Carolina  NAIP Imagery 2017    Resolution: 100CM "));
    56         }
     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());
    5776    }
    5877
     
    6483    @Test
    6584    public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
    66         try (InputStream is = TestUtils.getRegressionDataStream(16248, "capabilities.xml")) {
    67             WMSImagery wms = new WMSImagery();
    68             wms.parseCapabilities(null, is);
    69             assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k", wms.getServiceUrl().toExternalForm());
    70         }
     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));
    7197    }
    7298}
     99
Note: See TracChangeset for help on using the changeset viewer.