source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandlerTest.java@ 16589

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

fix #19364 - Remote control /imagery: support all imagery options

  • Property svn:eol-style set to native
File size: 4.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import static org.hamcrest.CoreMatchers.hasItem;
5import static org.junit.Assert.assertEquals;
6import static org.junit.Assert.assertThat;
7
8import java.util.Arrays;
9import java.util.List;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.junit.rules.ExpectedException;
14import org.openstreetmap.josm.data.imagery.ImageryInfo;
15import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
16import org.openstreetmap.josm.testutils.JOSMTestRules;
17
18import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
19
20/**
21 * Unit tests of {@link ImageryHandler} class.
22 */
23public class ImageryHandlerTest {
24
25 /**
26 * Rule used for tests throwing exceptions.
27 */
28 @Rule
29 public ExpectedException thrown = ExpectedException.none();
30
31 /**
32 * Setup test.
33 */
34 @Rule
35 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
36 public JOSMTestRules test = new JOSMTestRules();
37
38 private static ImageryHandler newHandler(String url) throws RequestHandlerBadRequestException {
39 ImageryHandler req = new ImageryHandler();
40 if (url != null)
41 req.setUrl(url);
42 return req;
43 }
44
45 /**
46 * Unit test for bad request - no param.
47 * @throws Exception if any error occurs
48 */
49 @Test
50 public void testBadRequestNoParam() throws Exception {
51 thrown.expect(RequestHandlerBadRequestException.class);
52 thrown.expectMessage("Parameter must not be null");
53 newHandler(null).handle();
54 }
55
56 /**
57 * Unit test for bad request - invalid URL.
58 * @throws Exception if any error occurs
59 */
60 @Test
61 public void testBadRequestInvalidUrl() throws Exception {
62 thrown.expect(RequestHandlerBadRequestException.class);
63 thrown.expectMessage("The following keys are mandatory, but have not been provided: url");
64 newHandler("invalid_url").handle();
65 }
66
67 /**
68 * Unit test for bad request - incomplete URL.
69 * @throws Exception if any error occurs
70 */
71 @Test
72 public void testBadRequestIncompleteUrl() throws Exception {
73 thrown.expect(RequestHandlerBadRequestException.class);
74 thrown.expectMessage("The following keys are mandatory, but have not been provided: url");
75 newHandler("https://localhost").handle();
76 }
77
78 /**
79 * Unit test for nominal request - local data file.
80 * @throws Exception if any error occurs
81 */
82 @Test
83 public void testNominalRequest() throws Exception {
84 newHandler("https://localhost?url=foo").handle();
85 }
86
87 /**
88 * Unit test for {@link ImageryHandler#getOptionalParams()}
89 * @throws Exception if any error occurs
90 */
91 @Test
92 public void testOptionalParams() throws Exception {
93 List<String> optionalParams = Arrays.asList(newHandler("").getOptionalParams());
94 assertThat(optionalParams, hasItem("type"));
95 assertThat(optionalParams, hasItem("min-zoom"));
96 assertThat(optionalParams, hasItem("max-zoom"));
97 assertThat(optionalParams, hasItem("category"));
98 }
99
100 /**
101 * Unit test for {@link ImageryHandler#buildImageryInfo()}
102 * @throws Exception if any error occurs
103 */
104 @Test
105 public void testBuildImageryInfo() throws Exception {
106 String url = "https://localhost/imagery?title=osm"
107 + "&type=tms&min_zoom=3&max_zoom=23&category=osmbasedmap&country_code=XA"
108 + "&url=https://a.tile.openstreetmap.org/%7Bzoom%7D/%7Bx%7D/%7By%7D.png";
109 ImageryInfo imageryInfo = newHandler(url).buildImageryInfo();
110 assertEquals("osm", imageryInfo.getName());
111 assertEquals(ImageryInfo.ImageryType.TMS, imageryInfo.getImageryType());
112 assertEquals("https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", imageryInfo.getUrl());
113 assertEquals(3, imageryInfo.getMinZoom());
114 assertEquals(23, imageryInfo.getMaxZoom());
115 assertEquals(ImageryInfo.ImageryCategory.OSMBASEDMAP, imageryInfo.getImageryCategory());
116 assertEquals("XA", imageryInfo.getCountryCode());
117 }
118}
Note: See TracBrowser for help on using the repository browser.