Changeset 18630 in josm for trunk/test/unit/org


Ignore:
Timestamp:
2023-01-11T14:31:19+01:00 (22 months ago)
Author:
taylor.smock
Message:

see r18628: {apikey} fails for Swedish historic orthophoto endpoint imagery

This fixes and adapts a test for WMS endpoints

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java

    r18106 r18630  
    1212import org.junit.jupiter.api.Test;
    1313import org.junit.jupiter.api.extension.RegisterExtension;
     14import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    1415import org.openstreetmap.josm.data.imagery.ImageryInfo;
    1516import org.openstreetmap.josm.gui.MainApplication;
     
    3536    @RegisterExtension
    3637    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    37     public JOSMTestRules test = new JOSMTestRules().fakeAPI();
     38    public JOSMTestRules test = new JOSMTestRules().fakeAPI().projection();
    3839
    3940    /**
     
    7273    @Test
    7374    void testActionPerformedEnabledWms() {
    74         wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
     75        wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.1.1"))
    7576                .willReturn(aResponse()
    7677                        .withStatus(200)
    7778                        .withHeader("Content-Type", "text/xml")
    7879                        .withBodyFile("imagery/wms-capabilities.xml")));
    79         wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities"))
     80        wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities"))
    8081                .willReturn(aResponse()
    8182                        .withStatus(404)));
    82         wireMockServer.stubFor(get(urlEqualTo("/wms?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
     83        wireMockServer.stubFor(get(urlEqualTo("/wms?apikey=random_key&SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0"))
    8384                .willReturn(aResponse()
    8485                        .withStatus(404)));
    8586
    86         new AddImageryLayerAction(new ImageryInfo("localhost", wireMockServer.url("/wms?"),
    87                 "wms_endpoint", null, null)).actionPerformed(null);
    88         List<WMSLayer> wmsLayers = MainApplication.getLayerManager().getLayersOfType(WMSLayer.class);
    89         assertEquals(1, wmsLayers.size());
     87        try {
     88            FeatureAdapter.registerApiKeyAdapter(id -> "random_key");
     89            final ImageryInfo imageryInfo = new ImageryInfo("localhost", wireMockServer.url("/wms?apikey={apikey}"),
     90                    "wms_endpoint", null, null);
     91            imageryInfo.setId("testActionPerformedEnabledWms");
     92            new AddImageryLayerAction(imageryInfo).actionPerformed(null);
     93            List<WMSLayer> wmsLayers = MainApplication.getLayerManager().getLayersOfType(WMSLayer.class);
     94            assertEquals(1, wmsLayers.size());
    9095
    91         MainApplication.getLayerManager().removeLayer(wmsLayers.get(0));
     96            MainApplication.getLayerManager().removeLayer(wmsLayers.get(0));
     97        } finally {
     98            FeatureAdapter.registerApiKeyAdapter(new FeatureAdapter.DefaultApiKeyAdapter());
     99        }
    92100    }
    93101
Note: See TracChangeset for help on using the changeset viewer.