Changeset 13735 in josm for trunk/test


Ignore:
Timestamp:
2018-05-12T22:08:00+02:00 (14 months ago)
Author:
wiktorn
Message:

Fix tests

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java

    r13733 r13735  
    66import java.nio.file.Files;
    77import java.nio.file.Paths;
     8import java.util.Arrays;
    89
    910import org.junit.Rule;
     
    1516import org.openstreetmap.josm.testutils.JOSMTestRules;
    1617
    17 import com.github.tomakehurst.wiremock.WireMockServer;
    1818import com.github.tomakehurst.wiremock.client.WireMock;
     19import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
     20import com.github.tomakehurst.wiremock.junit.WireMockRule;
    1921
    2022import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    2830    public JOSMTestRules test = new JOSMTestRules().platform().projection();
    2931
     32    @Rule
     33    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     34    public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
     35
    3036    @Test
    3137    public void testDefaultLayerSetInMaps() throws Exception {
    32         WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
    33         String getCapabilitiesBody = new String(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml")), "UTF-8");
    34         // do not use withFileBody as it needs different directory layout :(
    35         getCapabilitiesMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(getCapabilitiesBody)));
    36         getCapabilitiesMock.start();
    3738
    38         WireMockServer mapsMock = TestUtils.getWireMockServer();
    39         mapsMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
     39        tileServer.stubFor(
     40                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
     41                .willReturn(
     42                        WireMock.aResponse()
     43                        .withBody(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml")))
     44                        )
     45                );
     46
     47        tileServer.stubFor(WireMock.get(WireMock.urlEqualTo("//maps")).willReturn(WireMock.aResponse().withBody(
    4048                "<?xml version='1.0' encoding='UTF-8'?>\n" +
    4149                "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
     
    4452                "<id>OSM_Inspector-Geometry</id>\n" +
    4553                "<type>wms_endpoint</type>\n" +
    46                 "<url><![CDATA[" + getCapabilitiesMock.url("/any") + "]]></url>\n" +
     54                "<url><![CDATA[" + tileServer.url("/capabilities") + "]]></url>\n" +
    4755                "<icon>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsSAAALEgHS3X78AAAB5UlEQVQ4y4WTwWsTURDGfy8W1yYmXZOqtGJJFyGw6KF7CEigwYuS0kthrYUi4i0iORS9BU9hQdA/ILcixVBrwENKLz1FUBB0wWOwYFAqxUNYTZq6BfM8yC5d05iBObz3vfnmm3kz4sqDh/zP7szdlG5I+Of1zQ1xFA8xxI4GH2cjg4Cl+UUJcC4SJq6c7FPkKRlIoPQk0+NnuDwxHrhvuYd83+8OVuBlHouE/eDXzW8+/qO9DyHB0vyiVHoy2INSNiPdeg23XuPs3icmIoofPKXGmFJjjEUjgf4EFNi2TT6fJ5FI0Gg0ePrkMRfnbvn41QsJgEAJAQUdbYZyuQxAcvoSpmnydesFAF+cn8f2KUCw/fGt6GgzWJbF706bVCoFwGxyktnk5N8kB79QepL1zQ3xbOulCJWyGbkQHZWlbEZ6JIZhBDI1nQ5Np8P2zi4t9zAwGyNe3QALti11XSedTvsPYrEY73f3Bk+irusAnI6qrNy7z43sNUbFCQC6LYdCoYBbr/k1/2sh690HUalUaH7eIRxXA+6RFItF3HqN6+dP9REIb5lK2Yy0bdsHDMMgl8vRbTkAhOMqlmVhmibLq2ui7xsf1d+IV+0D3zVNw7KsPiXVapXnd2/Lodu4vLomTNMcSvIHY6bDkqJtEqIAAAAASUVORK5CYII=</icon>\n" +
    4856                "<attribution-text mandatory=\"true\">© Geofabrik GmbH, OpenStreetMap contributors, CC-BY-SA</attribution-text>\n" +
     
    5664                "</imagery>"
    5765                )));
    58         mapsMock.start();
    59         Config.getPref().put("josm.url", mapsMock.url("/"));
     66
     67        Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
    6068        ImageryLayerInfo.instance.loadDefaults(true, null, false);
    6169        assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
     
    6876                + "SRS=EPSG:3857&WIDTH=512&HEIGHT=512&"
    6977                + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
    70 
    7178    }
    7279}
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r13733 r13735  
    1313import java.util.Arrays;
    1414import java.util.List;
     15import java.util.concurrent.TimeUnit;
    1516
    1617import org.junit.ClassRule;
    1718import org.junit.Ignore;
     19import org.junit.Rule;
    1820import org.junit.Test;
    1921import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
     
    2830import org.openstreetmap.josm.testutils.JOSMTestRules;
    2931
    30 import com.github.tomakehurst.wiremock.WireMockServer;
    3132import com.github.tomakehurst.wiremock.client.WireMock;
     33import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
     34import com.github.tomakehurst.wiremock.junit.WireMockRule;
    3235
    3336import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    4346    @ClassRule
    4447    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    45     public static JOSMTestRules test = new JOSMTestRules().preferences().platform();
     48    public static JOSMTestRules test = new JOSMTestRules().preferences().platform().projection().timeout((int)TimeUnit.MINUTES.toMillis(5));
     49
     50    @Rule
     51    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
     52    public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
    4653
    4754    private ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
     
    339346    public void testDefaultLayer() throws Exception {
    340347        // https://gibs.earthdata.nasa.gov/wmts/epsg3857/best/1.0.0/WMTSCapabilities.xml
    341         WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
    342         String getCapabilitiesBody = new String(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml")), "UTF-8");
    343348        // do not use withFileBody as it needs different directory layout :(
    344         getCapabilitiesMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(getCapabilitiesBody)));
    345         getCapabilitiesMock.start();
    346 
    347         WireMockServer mapsMock = TestUtils.getWireMockServer();
    348         mapsMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
     349
     350        tileServer.stubFor(
     351                WireMock.get("/getcapabilities.xml")
     352                .willReturn(
     353                        WireMock.aResponse()
     354                        .withBody(Files.readAllBytes(
     355                                Paths.get(TestUtils.getTestDataRoot() + "wmts/getCapabilities-lots-of-layers.xml"))
     356                                )
     357                        )
     358                );
     359
     360        tileServer.stubFor(
     361                WireMock.get("//maps")
     362                .willReturn(
     363                        WireMock.aResponse().withBody(
    349364                "<?xml version='1.0' encoding='UTF-8'?>\n" +
    350365                "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
     
    353368                "<id>landsat</id>\n" +
    354369                "<type>wmts</type>\n" +
    355                 "<url><![CDATA[" + getCapabilitiesMock.url("/getcapabilities.xml") + "]]></url>\n" +
     370                "<url><![CDATA[" + tileServer.url("/getcapabilities.xml") + "]]></url>\n" +
    356371                "<defaultLayers>" +
    357372                "<layer name=\"GEOGRAPHICALGRIDSYSTEMS.MAPS\" />" +
     
    360375                "</imagery>"
    361376                )));
    362         mapsMock.start();
    363         Config.getPref().put("josm.url", mapsMock.url("/"));
    364 
     377
     378        Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
    365379        ImageryLayerInfo.instance.loadDefaults(true, null, false);
    366380
  • trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java

    r13733 r13735  
    77import java.io.IOException;
    88import java.nio.file.Files;
    9 import java.nio.file.Path;
    109import java.nio.file.Paths;
    1110import java.util.List;
     
    1716import org.openstreetmap.josm.testutils.JOSMTestRules;
    1817
    19 import com.github.tomakehurst.wiremock.WireMockServer;
    2018import com.github.tomakehurst.wiremock.client.WireMock;
     19import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
     20import com.github.tomakehurst.wiremock.junit.WireMockRule;
    2121
    2222import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     
    3434    public JOSMTestRules test = new JOSMTestRules().platform().projection();
    3535
     36    @Rule
     37    public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
     38            .dynamicPort());
    3639    /**
    3740     * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
     
    5558    @Test
    5659    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();
     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 "));
    6467    }
    6568
    6669    @Test
    6770    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"));
     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"));
    7374        assertEquals(1, wmsi.getLayers().size());
    7475        assertEquals("Server WMS m.st. Warszawy", wmsi.getLayers().get(0).toString());
     
    8384    @Test
    8485    public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
    85         Path capabilitiesPath = Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"));
    86         WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
    87         getCapabilitiesMock.stubFor(
     86        tileServer.stubFor(
    8887                WireMock.get(WireMock.anyUrl())
    89                 .willReturn(WireMock.aResponse().withBody(Files.readAllBytes(capabilitiesPath))));
    90         getCapabilitiesMock.start();
    91         WMSImagery wms = new WMSImagery(getCapabilitiesMock.url("any"));
     88                .willReturn(WireMock.aResponse().withBody(Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"))))));
     89        WMSImagery wms = new WMSImagery(tileServer.url("any"));
    9290        assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k", wms.buildRootUrl());
    9391        assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName());
Note: See TracChangeset for help on using the changeset viewer.