1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol.handler;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
---|
7 |
|
---|
8 | import org.junit.jupiter.api.extension.RegisterExtension;
|
---|
9 | import org.junit.jupiter.api.Test;
|
---|
10 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
---|
11 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
12 |
|
---|
13 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Unit tests of {@link LoadAndZoomHandler} class.
|
---|
17 | */
|
---|
18 | class LoadAndZoomHandlerTest {
|
---|
19 | /**
|
---|
20 | * Setup test.
|
---|
21 | */
|
---|
22 | @RegisterExtension
|
---|
23 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
24 | public JOSMTestRules test = new JOSMTestRules();
|
---|
25 |
|
---|
26 | private static LoadAndZoomHandler newHandler(String url) throws RequestHandlerBadRequestException {
|
---|
27 | LoadAndZoomHandler req = new LoadAndZoomHandler();
|
---|
28 | if (url != null)
|
---|
29 | req.setUrl(url);
|
---|
30 | return req;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Unit test for bad request - no param.
|
---|
35 | * @throws Exception if any error occurs
|
---|
36 | */
|
---|
37 | @Test
|
---|
38 | void testBadRequestNoParam() throws Exception {
|
---|
39 | Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
|
---|
40 | assertEquals("NumberFormatException (empty String)", e.getMessage());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Unit test for bad request - invalid URL.
|
---|
45 | * @throws Exception if any error occurs
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | void testBadRequestInvalidUrl() throws Exception {
|
---|
49 | Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle());
|
---|
50 | assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage());
|
---|
51 | }
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * Unit test for bad request - incomplete URL.
|
---|
55 | * @throws Exception if any error occurs
|
---|
56 | */
|
---|
57 | @Test
|
---|
58 | void testBadRequestIncompleteUrl() throws Exception {
|
---|
59 | Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle());
|
---|
60 | assertEquals("The following keys are mandatory, but have not been provided: bottom, top, left, right", e.getMessage());
|
---|
61 | }
|
---|
62 |
|
---|
63 | /**
|
---|
64 | * Unit test for nominal request - local data file.
|
---|
65 | * @throws Exception if any error occurs
|
---|
66 | */
|
---|
67 | @Test
|
---|
68 | void testNominalRequest() throws Exception {
|
---|
69 | assertDoesNotThrow(() -> newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle());
|
---|
70 | }
|
---|
71 | }
|
---|