1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.data.imagery;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 |
|
---|
6 | import java.nio.file.Files;
|
---|
7 | import java.nio.file.Paths;
|
---|
8 | import java.util.Arrays;
|
---|
9 |
|
---|
10 | import org.junit.Rule;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.TestUtils;
|
---|
14 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
15 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | import com.github.tomakehurst.wiremock.client.WireMock;
|
---|
19 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
---|
20 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
---|
21 |
|
---|
22 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
23 |
|
---|
24 | public class WMSEndpointTileSourceTest {
|
---|
25 | /**
|
---|
26 | * Setup test
|
---|
27 | */
|
---|
28 | @Rule
|
---|
29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
30 | public JOSMTestRules test = new JOSMTestRules().platform().projection();
|
---|
31 |
|
---|
32 | @Rule
|
---|
33 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
34 | public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
|
---|
35 |
|
---|
36 | @Test
|
---|
37 | public void testDefaultLayerSetInMaps() throws Exception {
|
---|
38 |
|
---|
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(
|
---|
48 | "<?xml version='1.0' encoding='UTF-8'?>\n" +
|
---|
49 | "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
|
---|
50 | "<entry>\n" +
|
---|
51 | "<name>OSM Inspector: Geometry</name>\n" +
|
---|
52 | "<id>OSM_Inspector-Geometry</id>\n" +
|
---|
53 | "<type>wms_endpoint</type>\n" +
|
---|
54 | "<url><![CDATA[" + tileServer.url("/capabilities") + "]]></url>\n" +
|
---|
55 | "<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" +
|
---|
56 | "<attribution-text mandatory=\"true\">© Geofabrik GmbH, OpenStreetMap contributors, CC-BY-SA</attribution-text>\n" +
|
---|
57 | "<attribution-url>http://tools.geofabrik.de/osmi/</attribution-url>\n" +
|
---|
58 | "<max-zoom>18</max-zoom>\n" +
|
---|
59 | "<valid-georeference>true</valid-georeference>\n" +
|
---|
60 | "<defaultLayers>" +
|
---|
61 | "<layer name=\"single_node_in_way\" style=\"default\" />" +
|
---|
62 | "</defaultLayers>" +
|
---|
63 | "</entry>\n" +
|
---|
64 | "</imagery>"
|
---|
65 | )));
|
---|
66 |
|
---|
67 | Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
|
---|
68 | ImageryLayerInfo.instance.loadDefaults(true, null, false);
|
---|
69 | assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
|
---|
70 | ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
|
---|
71 | assertEquals("single_node_in_way", wmsImageryInfo.getDefaultLayers().get(0).getLayerName());
|
---|
72 | WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
|
---|
73 | tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
74 | assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&"
|
---|
75 | + "LAYERS=single_node_in_way&STYLES=default&"
|
---|
76 | + "SRS=EPSG:3857&WIDTH=512&HEIGHT=512&"
|
---|
77 | + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
|
---|
78 | }
|
---|
79 | }
|
---|