1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol.handler;
|
---|
3 |
|
---|
4 | import org.junit.BeforeClass;
|
---|
5 | import org.junit.Rule;
|
---|
6 | import org.junit.Test;
|
---|
7 | import org.junit.rules.ExpectedException;
|
---|
8 | import org.openstreetmap.josm.JOSMFixture;
|
---|
9 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * Unit tests of {@link LoadAndZoomHandler} class.
|
---|
13 | */
|
---|
14 | public class LoadAndZoomHandlerTest {
|
---|
15 |
|
---|
16 | /**
|
---|
17 | * Rule used for tests throwing exceptions.
|
---|
18 | */
|
---|
19 | @Rule
|
---|
20 | public ExpectedException thrown = ExpectedException.none();
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUpBeforeClass() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
28 | }
|
---|
29 |
|
---|
30 | private static LoadAndZoomHandler newHandler(String url) {
|
---|
31 | LoadAndZoomHandler req = new LoadAndZoomHandler();
|
---|
32 | if (url != null)
|
---|
33 | req.setUrl(url);
|
---|
34 | return req;
|
---|
35 | }
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Unit test for bad request - no param.
|
---|
39 | * @throws Exception if any error occurs
|
---|
40 | */
|
---|
41 | @Test
|
---|
42 | public void testBadRequestNoParam() throws Exception {
|
---|
43 | thrown.expect(RequestHandlerBadRequestException.class);
|
---|
44 | thrown.expectMessage("NumberFormatException (empty String)");
|
---|
45 | newHandler(null).handle();
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * Unit test for bad request - invalid URL.
|
---|
50 | * @throws Exception if any error occurs
|
---|
51 | */
|
---|
52 | @Test
|
---|
53 | public void testBadRequestInvalidUrl() throws Exception {
|
---|
54 | thrown.expect(RequestHandlerBadRequestException.class);
|
---|
55 | thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right");
|
---|
56 | newHandler("invalid_url").handle();
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Unit test for bad request - incomplete URL.
|
---|
61 | * @throws Exception if any error occurs
|
---|
62 | */
|
---|
63 | @Test
|
---|
64 | public void testBadRequestIncompleteUrl() throws Exception {
|
---|
65 | thrown.expect(RequestHandlerBadRequestException.class);
|
---|
66 | thrown.expectMessage("The following keys are mandatory, but have not been provided: bottom, top, left, right");
|
---|
67 | newHandler("https://localhost").handle();
|
---|
68 | }
|
---|
69 |
|
---|
70 | /**
|
---|
71 | * Unit test for nominal request - local data file.
|
---|
72 | * @throws Exception if any error occurs
|
---|
73 | */
|
---|
74 | @Test
|
---|
75 | public void testNominalRequest() throws Exception {
|
---|
76 | newHandler("https://localhost?bottom=0&top=0&left=1&right=1").handle();
|
---|
77 | }
|
---|
78 | }
|
---|