source: josm/trunk/test/unit/org/openstreetmap/josm/io/imagery/WMSImageryTest.java@ 13735

Last change on this file since 13735 was 13735, checked in by wiktorn, 6 years ago

Fix tests

  • Property svn:eol-style set to native
File size: 4.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.imagery;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.io.IOException;
8import java.nio.file.Files;
9import java.nio.file.Paths;
10import java.util.List;
11
12import org.junit.Rule;
13import org.junit.Test;
14import org.openstreetmap.josm.TestUtils;
15import org.openstreetmap.josm.io.imagery.WMSImagery.WMSGetCapabilitiesException;
16import org.openstreetmap.josm.testutils.JOSMTestRules;
17
18import com.github.tomakehurst.wiremock.client.WireMock;
19import com.github.tomakehurst.wiremock.core.WireMockConfiguration;
20import com.github.tomakehurst.wiremock.junit.WireMockRule;
21
22import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
23
24/**
25 * Unit tests of {@link WMSImagery} class.
26 */
27public class WMSImageryTest {
28
29 /**
30 * Setup test
31 */
32 @Rule
33 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
34 public JOSMTestRules test = new JOSMTestRules().platform().projection();
35
36 @Rule
37 public WireMockRule tileServer = new WireMockRule(WireMockConfiguration.options()
38 .dynamicPort());
39 /**
40 * Unit test of {@code WMSImagery.WMSGetCapabilitiesException} class
41 */
42 @Test
43 public void testWMSGetCapabilitiesException() {
44 Exception cause = new Exception("test");
45 WMSGetCapabilitiesException exc = new WMSGetCapabilitiesException(cause, "bar");
46 assertEquals(cause, exc.getCause());
47 assertEquals("bar", exc.getIncomingData());
48 exc = new WMSGetCapabilitiesException("foo", "bar");
49 assertEquals("foo", exc.getMessage());
50 assertEquals("bar", exc.getIncomingData());
51 }
52
53 /**
54 * Non-regression test for bug #15730.
55 * @throws IOException if any I/O error occurs
56 * @throws WMSGetCapabilitiesException never
57 */
58 @Test
59 public void testTicket15730() throws IOException, WMSGetCapabilitiesException {
60 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
61 Files.readAllBytes(Paths.get(TestUtils.getRegressionDataDir(15730), "capabilities.xml"))
62 )));
63
64 WMSImagery wms = new WMSImagery(tileServer.url("capabilities.xml"));
65 assertEquals(1, wms.getLayers().size());
66 assertTrue(wms.getLayers().get(0).getAbstract().startsWith("South Carolina NAIP Imagery 2017 Resolution: 100CM "));
67 }
68
69 @Test
70 public void testNestedLayers() throws Exception {
71 tileServer.stubFor(WireMock.get(WireMock.anyUrl()).willReturn(WireMock.aResponse().withBody(
72 Files.readAllBytes(Paths.get(TestUtils.getTestDataRoot() + "wms/mapa-um-warszawa-pl.xml")))));
73 WMSImagery wmsi = new WMSImagery(tileServer.url("/serwis"));
74 assertEquals(1, wmsi.getLayers().size());
75 assertEquals("Server WMS m.st. Warszawy", wmsi.getLayers().get(0).toString());
76 assertEquals(202, wmsi.getLayers().get(0).getChildren().size());
77 }
78
79 /**
80 * Non-regression test for bug #16248.
81 * @throws IOException if any I/O error occurs
82 * @throws WMSGetCapabilitiesException never
83 */
84 @Test
85 public void testTicket16248() throws IOException, WMSGetCapabilitiesException {
86 tileServer.stubFor(
87 WireMock.get(WireMock.anyUrl())
88 .willReturn(WireMock.aResponse().withBody(Files.readAllBytes(Paths.get(TestUtils.getRegressionDataFile(16248, "capabilities.xml"))))));
89 WMSImagery wms = new WMSImagery(tileServer.url("any"));
90 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25k", wms.buildRootUrl());
91 assertEquals("wms.hgis.cartomatic.pl", wms.getLayers().get(0).getName());
92 assertEquals("http://wms.hgis.cartomatic.pl/topo/3857/m25kFORMAT=image/png&TRANSPARENT=TRUE&VERSION=1.1.1&SERVICE=WMS&REQUEST=GetMap&"
93 + "LAYERS=wms.hgis.cartomatic.pl&STYLES=&SRS={proj}&WIDTH={width}&HEIGHT={height}&BBOX={bbox}",
94 wms.buildGetMapUrl(wms.getLayers(), (List<String>)null, true));
95 }
96}
97
Note: See TracBrowser for help on using the repository browser.