[13733] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.data.imagery;
|
---|
| 3 |
|
---|
| 4 | import static org.junit.Assert.assertEquals;
|
---|
[13897] | 5 | import static org.junit.Assert.assertTrue;
|
---|
[13733] | 6 |
|
---|
| 7 | import java.nio.file.Files;
|
---|
| 8 | import java.nio.file.Paths;
|
---|
[13735] | 9 | import java.util.Arrays;
|
---|
[13733] | 10 |
|
---|
| 11 | import org.junit.Rule;
|
---|
| 12 | import org.junit.Test;
|
---|
| 13 | import org.openstreetmap.josm.Main;
|
---|
| 14 | import org.openstreetmap.josm.TestUtils;
|
---|
[13872] | 15 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
[13733] | 16 | import org.openstreetmap.josm.data.projection.Projections;
|
---|
| 17 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
| 18 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
| 19 |
|
---|
| 20 | import com.github.tomakehurst.wiremock.client.WireMock;
|
---|
[13735] | 21 | import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
|
---|
| 22 | import com.github.tomakehurst.wiremock.junit.WireMockRule;
|
---|
[13733] | 23 |
|
---|
| 24 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 25 |
|
---|
| 26 | public class WMSEndpointTileSourceTest {
|
---|
| 27 | /**
|
---|
| 28 | * Setup test
|
---|
| 29 | */
|
---|
| 30 | @Rule
|
---|
| 31 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
| 32 | public JOSMTestRules test = new JOSMTestRules().platform().projection();
|
---|
| 33 |
|
---|
[13735] | 34 | @Rule
|
---|
| 35 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
| 36 | public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
|
---|
| 37 |
|
---|
[13733] | 38 | @Test
|
---|
| 39 | public void testDefaultLayerSetInMaps() throws Exception {
|
---|
| 40 |
|
---|
[13735] | 41 | tileServer.stubFor(
|
---|
| 42 | WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
|
---|
| 43 | .willReturn(
|
---|
| 44 | WireMock.aResponse()
|
---|
| 45 | .withBody(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/geofabrik-osm-inspector.xml")))
|
---|
| 46 | )
|
---|
| 47 | );
|
---|
| 48 |
|
---|
| 49 | tileServer.stubFor(WireMock.get(WireMock.urlEqualTo("//maps")).willReturn(WireMock.aResponse().withBody(
|
---|
[13733] | 50 | "<?xml version='1.0' encoding='UTF-8'?>\n" +
|
---|
| 51 | "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
|
---|
| 52 | "<entry>\n" +
|
---|
| 53 | "<name>OSM Inspector: Geometry</name>\n" +
|
---|
| 54 | "<id>OSM_Inspector-Geometry</id>\n" +
|
---|
| 55 | "<type>wms_endpoint</type>\n" +
|
---|
[13735] | 56 | "<url><![CDATA[" + tileServer.url("/capabilities") + "]]></url>\n" +
|
---|
[13742] | 57 | "<icon>data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAsSAAALEgHS3X78AAAB5UlEQVQ4y4WTwWsTURDG" +
|
---|
| 58 | "fy8W1yYmXZOqtGJJFyGw6KF7CEigwYuS0kthrYUi4i0iORS9BU9hQdA/ILcixVBrwENKLz1FUBB0wWOwYFAqxUNYTZq6BfM8yC5d05iBObz3vfnmm3kz4sqDh/zP" +
|
---|
| 59 | "7szdlG5I+Of1zQ1xFA8xxI4GH2cjg4Cl+UUJcC4SJq6c7FPkKRlIoPQk0+NnuDwxHrhvuYd83+8OVuBlHouE/eDXzW8+/qO9DyHB0vyiVHoy2INSNiPdeg23XuPs" +
|
---|
| 60 | "3icmIoofPKXGmFJjjEUjgf4EFNi2TT6fJ5FI0Gg0ePrkMRfnbvn41QsJgEAJAQUdbYZyuQxAcvoSpmnydesFAF+cn8f2KUCw/fGt6GgzWJbF706bVCoFwGxyktnk" +
|
---|
| 61 | "5N8kB79QepL1zQ3xbOulCJWyGbkQHZWlbEZ6JIZhBDI1nQ5Np8P2zi4t9zAwGyNe3QALti11XSedTvsPYrEY73f3Bk+irusAnI6qrNy7z43sNUbFCQC6LYdCoYBb" +
|
---|
| 62 | "r/k1/2sh690HUalUaH7eIRxXA+6RFItF3HqN6+dP9REIb5lK2Yy0bdsHDMMgl8vRbTkAhOMqlmVhmibLq2ui7xsf1d+IV+0D3zVNw7KsPiXVapXnd2/Lodu4vLom" +
|
---|
| 63 | "TNMcSvIHY6bDkqJtEqIAAAAASUVORK5CYII=</icon>\n" +
|
---|
[13733] | 64 | "<attribution-text mandatory=\"true\">© Geofabrik GmbH, OpenStreetMap contributors, CC-BY-SA</attribution-text>\n" +
|
---|
| 65 | "<attribution-url>http://tools.geofabrik.de/osmi/</attribution-url>\n" +
|
---|
| 66 | "<max-zoom>18</max-zoom>\n" +
|
---|
| 67 | "<valid-georeference>true</valid-georeference>\n" +
|
---|
[13757] | 68 | "<default-layers>" +
|
---|
[13733] | 69 | "<layer name=\"single_node_in_way\" style=\"default\" />" +
|
---|
[13757] | 70 | "</default-layers>" +
|
---|
[13733] | 71 | "</entry>\n" +
|
---|
| 72 | "</imagery>"
|
---|
| 73 | )));
|
---|
[13735] | 74 |
|
---|
| 75 | Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
|
---|
[13733] | 76 | ImageryLayerInfo.instance.loadDefaults(true, null, false);
|
---|
| 77 | assertEquals(1, ImageryLayerInfo.instance.getDefaultLayers().size());
|
---|
| 78 | ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
|
---|
| 79 | assertEquals("single_node_in_way", wmsImageryInfo.getDefaultLayers().get(0).getLayerName());
|
---|
| 80 | WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
|
---|
| 81 | tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
[13742] | 82 | assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&"
|
---|
| 83 | + "REQUEST=GetMap&LAYERS=single_node_in_way&STYLES=default&"
|
---|
[13733] | 84 | + "SRS=EPSG:3857&WIDTH=512&HEIGHT=512&"
|
---|
| 85 | + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108", tileSource.getTileUrl(1, 1, 1));
|
---|
| 86 | }
|
---|
[13872] | 87 |
|
---|
| 88 | @Test
|
---|
| 89 | public void testCustomHeaders() throws Exception {
|
---|
| 90 | tileServer.stubFor(
|
---|
| 91 | WireMock.get(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
|
---|
| 92 | .willReturn(
|
---|
| 93 | WireMock.aResponse()
|
---|
| 94 | .withBody(Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/webatlas.no.xml")))
|
---|
| 95 | )
|
---|
| 96 | );
|
---|
| 97 |
|
---|
| 98 | tileServer.stubFor(WireMock.get(WireMock.urlEqualTo("//maps")).willReturn(WireMock.aResponse().withBody(
|
---|
| 99 | "<?xml version='1.0' encoding='UTF-8'?>\n" +
|
---|
| 100 | "<imagery xmlns=\"http://josm.openstreetmap.de/maps-1.0\">\n" +
|
---|
| 101 | " <entry>\n" +
|
---|
| 102 | " <name>Norway Orthophoto (historic)</name>\n" +
|
---|
| 103 | " <name lang=\"nb\">Norge i Bilder (historisk)</name>\n" +
|
---|
| 104 | " <id>geovekst-nib-historic</id>\n" +
|
---|
| 105 | " <type>wms_endpoint</type>\n" +
|
---|
| 106 | " <country-code>NO</country-code>\n" +
|
---|
| 107 | " <description lang=\"en\">Historic Norwegian orthophotos and maps, courtesy of Geovekst and Norkart.</description>\n" +
|
---|
| 108 | " <url><![CDATA[" + tileServer.url("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities") + "]]></url>\n" +
|
---|
| 109 | " <custom-http-header header-name=\"X-WAAPI-TOKEN\" header-value=\"b8e36d51-119a-423b-b156-d744d54123d5\" />\n" +
|
---|
| 110 | " <attribution-text>© Geovekst</attribution-text>\n" +
|
---|
| 111 | " <attribution-url>https://www.norgeibilder.no/</attribution-url>\n" +
|
---|
| 112 | " <permission-ref>https://forum.openstreetmap.org/viewtopic.php?id=62083</permission-ref>\n" +
|
---|
| 113 | " <icon>https://register.geonorge.no/data/organizations/_L_norgeibilder96x96.png</icon>\n" +
|
---|
| 114 | " <max-zoom>21</max-zoom>\n" +
|
---|
| 115 | " <valid-georeference>true</valid-georeference>\n" +
|
---|
| 116 | "</entry>\n" +
|
---|
| 117 | "</imagery>"
|
---|
| 118 | )));
|
---|
| 119 |
|
---|
| 120 | Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
|
---|
| 121 | ImageryLayerInfo.instance.loadDefaults(true, null, false);
|
---|
| 122 | ImageryInfo wmsImageryInfo = ImageryLayerInfo.instance.getDefaultLayers().get(0);
|
---|
[14092] | 123 | wmsImageryInfo.setDefaultLayers(Arrays.asList(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
|
---|
[13872] | 124 | WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, Main.getProjection());
|
---|
| 125 | tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
|
---|
| 126 | assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", wmsImageryInfo.getCustomHttpHeaders().get("X-WAAPI-TOKEN"));
|
---|
| 127 | assertEquals("b8e36d51-119a-423b-b156-d744d54123d5", tileSource.getHeaders().get("X-WAAPI-TOKEN"));
|
---|
[13897] | 128 | assertTrue(wmsImageryInfo.isGeoreferenceValid());
|
---|
[13872] | 129 | tileServer.verify(
|
---|
| 130 | WireMock.getRequestedFor(WireMock.urlEqualTo("/capabilities?SERVICE=WMS&REQUEST=GetCapabilities"))
|
---|
| 131 | .withHeader("X-WAAPI-TOKEN", WireMock.equalTo("b8e36d51-119a-423b-b156-d744d54123d5")));
|
---|
| 132 | assertEquals("http://waapi.webatlas.no/wms-orto-hist/?"
|
---|
| 133 | + "FORMAT=image/png&"
|
---|
| 134 | + "TRANSPARENT=TRUE&"
|
---|
| 135 | + "VERSION=1.1.1&"
|
---|
| 136 | + "SERVICE=WMS&"
|
---|
| 137 | + "REQUEST=GetMap&"
|
---|
| 138 | + "LAYERS=historiske-ortofoto&"
|
---|
| 139 | + "STYLES=&"
|
---|
| 140 | + "SRS=EPSG:3857&"
|
---|
| 141 | + "WIDTH=512&"
|
---|
| 142 | + "HEIGHT=512&"
|
---|
| 143 | + "BBOX=20037506.6204108,-60112521.5836107,60112521.5836107,-20037506.6204108",
|
---|
| 144 | tileSource.getTileUrl(1, 1, 1));
|
---|
| 145 | }
|
---|
[13733] | 146 | }
|
---|