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


Ignore:
Timestamp:
2023-06-21T16:50:47+02:00 (18 months ago)
Author:
taylor.smock
Message:

Fix #23011: Custom http headers aren't applied on custom TMS imagery sources

Location:
trunk/test/unit/org/openstreetmap/josm/data/imagery
Files:
2 added
4 edited

Legend:

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

    r18381 r18766  
    88
    99import org.junit.jupiter.api.Test;
    10 import org.junit.jupiter.api.extension.RegisterExtension;
    1110import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    1211import org.openstreetmap.gui.jmapviewer.TileXY;
    1312import org.openstreetmap.gui.jmapviewer.interfaces.ICoordinate;
     13import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
    1414import org.openstreetmap.gui.jmapviewer.tilesources.TemplatedTMSTileSource;
    1515import org.openstreetmap.josm.data.Bounds;
     
    2020import org.openstreetmap.josm.data.projection.ProjectionRegistry;
    2121import org.openstreetmap.josm.data.projection.Projections;
    22 import org.openstreetmap.josm.testutils.JOSMTestRules;
    23 
    24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2522
    2623/**
    2724 * Unit tests for class {@link TemplatedWMSTileSource}.
    2825 */
    29 class TemplatedWMSTileSourceTest {
     26@org.openstreetmap.josm.testutils.annotations.Projection
     27class TemplatedWMSTileSourceTest implements TileSourceTest {
    3028
    3129    private final ImageryInfo testImageryWMS = new ImageryInfo("test imagery", "http://localhost", "wms", null, null);
    3230    private final ImageryInfo testImageryTMS = new ImageryInfo("test imagery", "http://localhost", "tms", null, null);
    3331
    34     /**
    35      * Setup test.
    36      */
    37     @RegisterExtension
    38     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    39     public JOSMTestRules test = new JOSMTestRules();
     32    @Override
     33    public ImageryInfo getInfo() {
     34        return new ImageryInfo(testImageryWMS);
     35    }
     36
     37    @Override
     38    public TemplatedTileSource getTileSource(ImageryInfo info) {
     39        return new TemplatedWMSTileSource(info, ProjectionRegistry.getProjection());
     40    }
    4041
    4142    /**
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java

    r18106 r18766  
    22package org.openstreetmap.josm.data.imagery;
    33
     4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
    45import static org.junit.jupiter.api.Assertions.assertEquals;
    56import static org.junit.jupiter.api.Assertions.assertTrue;
    67
     8import java.io.IOException;
    79import java.nio.file.Files;
    810import java.nio.file.Paths;
    9 import java.util.Arrays;
     11import java.util.Collections;
    1012
    1113import org.junit.jupiter.api.Test;
    12 import org.junit.jupiter.api.extension.RegisterExtension;
     14import org.openstreetmap.gui.jmapviewer.interfaces.TemplatedTileSource;
    1315import org.openstreetmap.josm.TestUtils;
    1416import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
     
    1618import org.openstreetmap.josm.data.projection.Projections;
    1719import org.openstreetmap.josm.spi.preferences.Config;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    1920import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
    2021
     
    2223import com.github.tomakehurst.wiremock.client.WireMock;
    2324
    24 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
     25import org.openstreetmap.josm.testutils.annotations.Projection;
    2526
    2627@BasicWiremock
    27 class WMSEndpointTileSourceTest {
    28     /**
    29      * Setup test
    30      */
    31     @RegisterExtension
    32     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    33     public JOSMTestRules test = new JOSMTestRules().projection();
    34 
     28@Projection
     29class WMSEndpointTileSourceTest implements TileSourceTest {
    3530    @BasicWiremock
    3631    WireMockServer tileServer;
     32
     33    private void basicMock() {
     34        final byte[] response = assertDoesNotThrow(() -> Files.readAllBytes(
     35                Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml")));
     36        tileServer.stubFor(
     37                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
     38                        .willReturn(WireMock.aResponse().withBody(response))
     39        );
     40    }
     41
     42    @Override
     43    public ImageryInfo getInfo() {
     44        this.basicMock();
     45        final ImageryInfo info = new ImageryInfo("WMSEndpointTileSourceTest");
     46        info.setExtendedUrl(tileServer.url("/capabilities"));
     47        info.setDefaultLayers(Collections.singletonList(new DefaultLayer(ImageryType.WMS_ENDPOINT,
     48                "single_node_in_way", "default", null)));
     49        info.setImageryType(ImageryType.WMS_ENDPOINT);
     50        return info;
     51    }
     52
     53    @Override
     54    public TemplatedTileSource getTileSource(ImageryInfo info) {
     55        return new WMSEndpointTileSource(info, ProjectionRegistry.getProjection());
     56    }
    3757
    3858    @Test
     
    7393                )));
    7494
    75         Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
     95        Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer.url("//maps")));
    7696        ImageryLayerInfo.instance.loadDefaults(true, null, false);
    7797        assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
     
    87107
    88108    @Test
    89     void testCustomHeaders() throws Exception {
     109    void testCustomHeadersServerSide() throws IOException {
    90110        tileServer.stubFor(
    91111                WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
     
    118138                )));
    119139
    120         Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
     140        Config.getPref().putList("imagery.layers.sites", Collections.singletonList(tileServer.url("//maps")));
    121141        ImageryLayerInfo.instance.loadDefaults(true, null, false);
    122142        ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
    123         wmsImageryInfo.setDefaultLayers(Arrays.asList(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
     143        wmsImageryInfo.setDefaultLayers(Collections.singletonList(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
    124144        WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, ProjectionRegistry.getProjection());
    125145        tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/WMTSTileSourceTest.java

    r18568 r18766  
    2525import com.github.tomakehurst.wiremock.WireMockServer;
    2626import com.github.tomakehurst.wiremock.client.WireMock;
    27 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
    2827import org.apache.commons.io.FileUtils;
    2928import org.junit.jupiter.api.Disabled;
    3029import org.junit.jupiter.api.Test;
    31 import org.junit.jupiter.api.extension.RegisterExtension;
     30import org.junit.jupiter.api.Timeout;
    3231import org.junit.jupiter.api.io.TempDir;
    3332import org.junit.jupiter.params.ParameterizedTest;
     
    4443import org.openstreetmap.josm.data.projection.Projections;
    4544import org.openstreetmap.josm.spi.preferences.Config;
    46 import org.openstreetmap.josm.testutils.JOSMTestRules;
    4745import org.openstreetmap.josm.testutils.annotations.BasicPreferences;
    4846import org.openstreetmap.josm.testutils.annotations.BasicWiremock;
     47import org.openstreetmap.josm.testutils.annotations.Projection;
    4948import org.openstreetmap.josm.tools.ReflectionUtils;
    5049
     
    5453@BasicWiremock
    5554@BasicPreferences
     55@Projection
     56@Timeout(value = 5, unit = TimeUnit.MINUTES)
    5657class WMTSTileSourceTest {
    57 
    58     /**
    59      * Setup test.
    60      */
    61     @RegisterExtension
    62     @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
    63     public static JOSMTestRules test = new JOSMTestRules().projection().timeout((int) TimeUnit.MINUTES.toMillis(5));
    64 
    6558    @BasicWiremock
    6659    WireMockServer tileServer;
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/MapboxVectorTileSourceTest.java

    r17867 r18766  
    66import static org.junit.jupiter.api.Assertions.assertNull;
    77
    8 
    98import java.util.stream.Stream;
    10 
    11 import org.junit.jupiter.api.extension.RegisterExtension;
    12 import org.openstreetmap.josm.TestUtils;
    13 import org.openstreetmap.josm.data.imagery.ImageryInfo;
    14 import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.MapboxVectorStyle;
    15 import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.Source;
    16 import org.openstreetmap.josm.gui.ExtendedDialog;
    17 import org.openstreetmap.josm.gui.widgets.JosmComboBox;
    18 import org.openstreetmap.josm.testutils.JOSMTestRules;
    19 import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    209
    2110import org.junit.jupiter.api.Test;
     
    2312import org.junit.jupiter.params.provider.Arguments;
    2413import org.junit.jupiter.params.provider.MethodSource;
     14import org.openstreetmap.josm.TestUtils;
     15import org.openstreetmap.josm.data.imagery.ImageryInfo;
     16import org.openstreetmap.josm.data.imagery.TileSourceTest;
     17import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.MapboxVectorStyle;
     18import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.Source;
     19import org.openstreetmap.josm.gui.ExtendedDialog;
     20import org.openstreetmap.josm.gui.widgets.JosmComboBox;
     21import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
    2522
    2623/**
     
    2926 * @since 17862
    3027 */
    31 class MapboxVectorTileSourceTest {
    32     @RegisterExtension
    33     JOSMTestRules rule = new JOSMTestRules();
     28class MapboxVectorTileSourceTest implements TileSourceTest {
    3429    private static class SelectLayerDialogMocker extends ExtendedDialogMocker {
    3530        int index;
     
    4540    }
    4641
     42    @Override
     43    public ImageryInfo getInfo() {
     44        return new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot() + "pbf/mapillary/{z}/{x}/{y}.mvt");
     45    }
     46
     47    @Override
     48    public MapboxVectorTileSource getTileSource(ImageryInfo info) {
     49        return new MapboxVectorTileSource(info);
     50    }
     51
    4752    @Test
    4853    void testNoStyle() {
    49         MapboxVectorTileSource tileSource = new MapboxVectorTileSource(
    50           new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot() + "pbf/mapillary/{z}/{x}/{y}.mvt"));
     54        MapboxVectorTileSource tileSource = getTileSource(getInfo());
    5155        assertNull(tileSource.getStyleSource());
    5256    }
     
    6973        extendedDialogMocker.index = index;
    7074        extendedDialogMocker.getMockResultMap().put(dialogMockerText, "Add layers");
    71         MapboxVectorTileSource tileSource = new MapboxVectorTileSource(
     75        MapboxVectorTileSource tileSource = getTileSource(
    7276          new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot() + "mapillary.json"));
    7377        MapboxVectorStyle styleSource = tileSource.getStyleSource();
Note: See TracChangeset for help on using the changeset viewer.