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 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.TestUtils;
|
---|
13 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
14 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
16 |
|
---|
17 | import com.github.tomakehurst.wiremock.WireMockServer;
|
---|
18 | import com.github.tomakehurst.wiremock.client.WireMock;
|
---|
19 |
|
---|
20 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
21 |
|
---|
22 | public class WMSEndpointTileSourceTest {
|
---|
23 | /**
|
---|
24 | * Setup test
|
---|
25 | */
|
---|
26 | @Rule
|
---|
27 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
28 | public JOSMTestRules test = new JOSMTestRules().platform().projection();
|
---|
29 |
|
---|
30 | @Test
|
---|
31 | public void testDefaultLayerSetInMaps() throws Exception {
|
---|
32 | WireMockServer getCapabilitiesMock = TestUtils.getWireMockServer();
|
---|
33 | String getCapabilitiesBody = new String(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml")), "UTF-8");
|
---|
34 | // do not use withFileBody as it needs different directory layout :(
|
---|
35 | getCapabilitiesMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(getCapabilitiesBody)));
|
---|
36 | getCapabilitiesMock.start();
|
---|
37 |
|
---|
38 | WireMockServer mapsMock = TestUtils.getWireMockServer();
|
---|
39 | mapsMock.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
|
---|
40 | "<?xml version='1.0' encoding='UTF-8'?>\n" +
|
---|
41 | "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
|
---|
42 | "<entry>\n" +
|
---|
43 | "<name>OSM Inspector: Geometry</name>\n" +
|
---|
44 | "<id>OSM_Inspector-Geometry</id>\n" +
|
---|
45 | "<type>wms_endpoint</type>\n" +
|
---|
46 | "<url><![CDATA[" + getCapabilitiesMock.url("/any") + "]]></url>\n" +
|
---|
47 | "<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" +
|
---|
48 | "<attribution-text mandatory=\"true\">© Geofabrik GmbH, OpenStreetMap contributors, CC-BY-SA</attribution-text>\n" +
|
---|
49 | "<attribution-url>http://tools.geofabrik.de/osmi/</attribution-url>\n" +
|
---|
50 | "<max-zoom>18</max-zoom>\n" +
|
---|
51 | "<valid-georeference>true</valid-georeference>\n" +
|
---|
52 | "<defaultLayers>" +
|
---|
53 | "<layer name=\"single_node_in_way\" style=\"default\" />" +
|
---|
54 | "</defaultLayers>" +
|
---|
55 | "</entry>\n" +
|
---|
56 | "</imagery>"
|
---|
57 | )));
|
---|
58 | mapsMock.start();
|
---|
59 | Config.getPref().put("josm.url", mapsMock.url("/"));
|
---|
60 | ImageryLayerInfo.instance.loadDefaults(true, null, false);
|
---|
61 | assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
|
---|
62 | ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
|
---|
63 | assertEquals("single_node_in_way", wmsImageryInfo.getDefaultLayers().get(0).getLayerName());
|
---|
64 | WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
|
---|
65 | tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
66 | assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&"
|
---|
67 | + "LAYERS=single_node_in_way&STYLES=default&"
|
---|
68 | + "SRS=EPSG:3857&WIDTH=512&HEIGHT=512&"
|
---|
69 | + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
|
---|
70 |
|
---|
71 | }
|
---|
72 | }
|
---|