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