source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/vectortile/mapbox/MapboxVectorTileSourceTest.java@ 18766

Last change on this file since 18766 was 18766, checked in by taylor.smock, 11 months ago

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

File size: 3.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery.vectortile.mapbox;
3
4import static org.junit.jupiter.api.Assertions.assertEquals;
5import static org.junit.jupiter.api.Assertions.assertNotNull;
6import static org.junit.jupiter.api.Assertions.assertNull;
7
8import java.util.stream.Stream;
9
10import org.junit.jupiter.api.Test;
11import org.junit.jupiter.params.ParameterizedTest;
12import org.junit.jupiter.params.provider.Arguments;
13import 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;
22
23/**
24 * Test class for {@link MapboxVectorTileSource}
25 * @author Taylor Smock
26 * @since 17862
27 */
28class MapboxVectorTileSourceTest implements TileSourceTest {
29 private static class SelectLayerDialogMocker extends ExtendedDialogMocker {
30 int index;
31 @Override
32 protected void act(final ExtendedDialog instance) {
33 ((JosmComboBox<?>) this.getContent(instance)).setSelectedIndex(index);
34 }
35
36 @Override
37 protected String getString(final ExtendedDialog instance) {
38 return String.join(";", ((Source) ((JosmComboBox<?>) this.getContent(instance)).getSelectedItem()).getUrls());
39 }
40 }
41
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
52 @Test
53 void testNoStyle() {
54 MapboxVectorTileSource tileSource = getTileSource(getInfo());
55 assertNull(tileSource.getStyleSource());
56 }
57
58 private static Stream<Arguments> testMapillaryStyle() {
59 return Stream.of(Arguments.of(0, "Test Mapillary: mapillary-source", "https://tiles3.mapillary.com/v0.1/{z}/{x}/{y}.mvt"),
60 Arguments.of(1, "Test Mapillary: mapillary-features-source",
61 "https://a.mapillary.com/v3/map_features?tile={z}/{x}/{y}&client_id=_apiKey_"
62 + "&layers=points&per_page=1000"),
63 Arguments.of(2, "Test Mapillary: mapillary-traffic-signs-source",
64 "https://a.mapillary.com/v3/map_features?tile={z}/{x}/{y}&client_id=_apiKey_"
65 + "&layers=trafficsigns&per_page=1000"));
66 }
67
68 @ParameterizedTest
69 @MethodSource("testMapillaryStyle")
70 void testMapillaryStyle(Integer index, String expected, String dialogMockerText) {
71 TestUtils.assumeWorkingJMockit();
72 SelectLayerDialogMocker extendedDialogMocker = new SelectLayerDialogMocker();
73 extendedDialogMocker.index = index;
74 extendedDialogMocker.getMockResultMap().put(dialogMockerText, "Add layers");
75 MapboxVectorTileSource tileSource = getTileSource(
76 new ImageryInfo("Test Mapillary", "file:/" + TestUtils.getTestDataRoot() + "mapillary.json"));
77 MapboxVectorStyle styleSource = tileSource.getStyleSource();
78 assertNotNull(styleSource);
79 assertEquals(expected, tileSource.toString());
80 }
81}
Note: See TracBrowser for help on using the repository browser.