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.Rule;
|
---|
9 | import org.junit.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 LoadObjectHandler} class.
|
---|
17 | */
|
---|
18 | public class LoadObjectHandlerTest {
|
---|
19 | /**
|
---|
20 | * Setup test.
|
---|
21 | */
|
---|
22 | @Rule
|
---|
23 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
24 | public JOSMTestRules test = new JOSMTestRules();
|
---|
25 |
|
---|
26 | private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException {
|
---|
27 | LoadObjectHandler req = new LoadObjectHandler();
|
---|
28 | if (url != null)
|
---|
29 | req.setUrl(url);
|
---|
30 | return req;
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Unit test for bad request - no param.
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testBadRequestNoParam() {
|
---|
38 | assertDoesNotThrow(() -> newHandler(null).handle());
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Unit test for bad request - invalid URL.
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void testBadRequestInvalidUrl() {
|
---|
46 | Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle());
|
---|
47 | assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage());
|
---|
48 | }
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * Unit test for bad request - incomplete URL.
|
---|
52 | */
|
---|
53 | @Test
|
---|
54 | public void testBadRequestIncompleteUrl() {
|
---|
55 | Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle());
|
---|
56 | assertEquals("The following keys are mandatory, but have not been provided: objects", e.getMessage());
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Unit test for nominal request - local data file.
|
---|
61 | */
|
---|
62 | @Test
|
---|
63 | public void testNominalRequest() {
|
---|
64 | assertDoesNotThrow(() -> newHandler("https://localhost?objects=foo,bar").handle());
|
---|
65 | }
|
---|
66 | }
|
---|