source: josm/trunk/test/unit/org/openstreetmap/josm/data/imagery/WMSEndpointTileSourceTest.java@ 16636

Last change on this file since 16636 was 16636, checked in by simon04, 4 years ago

Update TemplatedWMSTileSourceTest, WMSEndpointTileSourceTest for increased precision of AbstractWMSTileSource.SCALE_DENOMINATOR_ZOOM_LEVEL_1

File size: 8.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.nio.file.Files;
8import java.nio.file.Paths;
9import java.util.Arrays;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.TestUtils;
14import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
15import org.openstreetmap.josm.data.projection.ProjectionRegistry;
16import org.openstreetmap.josm.data.projection.Projections;
17import org.openstreetmap.josm.spi.preferences.Config;
18import org.openstreetmap.josm.testutils.JOSMTestRules;
19
20import com.github.tomakehurst.wiremock.client.WireMock;
21import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
22import com.github.tomakehurst.wiremock.junit.WireMockRule;
23
24import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
25
26public class WMSEndpointTileSourceTest {
27 /**
28 * Setup test
29 */
30 @Rule
31 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
32 public JOSMTestRules test = new JOSMTestRules().projection();
33
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());
37
38 @Test
39 public void testDefaultLayerSetInMaps() throws Exception {
40
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(
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" +
56 "<url><![CDATA[" + tileServer.url("/capabilities") + "]]></url>\n" +
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" +
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" +
68 "<default-layers>" +
69 "<layer name=\"single_node_in_way\" style=\"default\" />" +
70 "</default-layers>" +
71 "</entry>\n" +
72 "</imagery>"
73 )));
74
75 Config.getPref().putList("imagery.layers.sites", Arrays.asList(tileServer.url("//maps")));
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, ProjectionRegistry.getProjection());
81 tileSource.initProjection(Projections.getProjectionByCode("EPSG:3857"));
82 assertEquals("https://tools.geofabrik.de/osmi/views/geometry/wxs?FORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.3.0&SERVICE=WMS&"
83 + "REQUEST=GetMap&LAYERS=single_node_in_way&STYLES=default&"
84 + "CRS=EPSG:3857&WIDTH=512&HEIGHT=512&"
85 + "BBOX=20037508.3427893,-60112525.0283678,60112525.0283678,-20037508.3427893", tileSource.getTileUrl(1, 1, 1));
86 }
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);
123 wmsImageryInfo.setDefaultLayers(Arrays.asList(new DefaultLayer(ImageryType.WMS_ENDPOINT, "historiske-ortofoto", "", "")));
124 WMSEndpointTileSource tileSource = new WMSEndpointTileSource(wmsImageryInfo, ProjectionRegistry.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"));
128 assertTrue(wmsImageryInfo.isGeoreferenceValid());
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=20037508.3427893,-60112525.0283678,60112525.0283678,-20037508.3427893",
144 tileSource.getTileUrl(1, 1, 1));
145 }
146}
Note: See TracBrowser for help on using the repository browser.