1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery.vectortile.mapbox;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertNull;
|
---|
7 |
|
---|
8 | import java.util.stream.Stream;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.junit.jupiter.params.ParameterizedTest;
|
---|
12 | import org.junit.jupiter.params.provider.Arguments;
|
---|
13 | import org.junit.jupiter.params.provider.MethodSource;
|
---|
14 | import org.openstreetmap.josm.TestUtils;
|
---|
15 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
16 | import org.openstreetmap.josm.data.imagery.TileSourceTest;
|
---|
17 | import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.MapboxVectorStyle;
|
---|
18 | import org.openstreetmap.josm.data.imagery.vectortile.mapbox.style.Source;
|
---|
19 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
20 | import org.openstreetmap.josm.gui.widgets.JosmComboBox;
|
---|
21 | import org.openstreetmap.josm.testutils.mockers.ExtendedDialogMocker;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Test class for {@link MapboxVectorTileSource}
|
---|
25 | * @author Taylor Smock
|
---|
26 | * @since 17862
|
---|
27 | */
|
---|
28 | class 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 | }
|
---|