[10116] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.io.remotecontrol.handler;
|
---|
| 3 |
|
---|
| 4 | import org.junit.Rule;
|
---|
| 5 | import org.junit.Test;
|
---|
| 6 | import org.junit.rules.ExpectedException;
|
---|
| 7 | import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
|
---|
[12558] | 8 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
[10116] | 9 |
|
---|
[12558] | 10 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 11 |
|
---|
[10116] | 12 | /**
|
---|
| 13 | * Unit tests of {@link LoadObjectHandler} class.
|
---|
| 14 | */
|
---|
| 15 | public class LoadObjectHandlerTest {
|
---|
| 16 |
|
---|
| 17 | /**
|
---|
| 18 | * Rule used for tests throwing exceptions.
|
---|
| 19 | */
|
---|
| 20 | @Rule
|
---|
| 21 | public ExpectedException thrown = ExpectedException.none();
|
---|
| 22 |
|
---|
| 23 | /**
|
---|
| 24 | * Setup test.
|
---|
| 25 | */
|
---|
[12558] | 26 | @Rule
|
---|
| 27 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
| 28 | public JOSMTestRules test = new JOSMTestRules();
|
---|
[10116] | 29 |
|
---|
[10973] | 30 | private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException {
|
---|
[10116] | 31 | LoadObjectHandler req = new LoadObjectHandler();
|
---|
| 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 | newHandler(null).handle();
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | /**
|
---|
| 47 | * Unit test for bad request - invalid URL.
|
---|
| 48 | * @throws Exception if any error occurs
|
---|
| 49 | */
|
---|
| 50 | @Test
|
---|
| 51 | public void testBadRequestInvalidUrl() throws Exception {
|
---|
| 52 | thrown.expect(RequestHandlerBadRequestException.class);
|
---|
| 53 | thrown.expectMessage("The following keys are mandatory, but have not been provided: objects");
|
---|
| 54 | newHandler("invalid_url").handle();
|
---|
| 55 | }
|
---|
| 56 |
|
---|
| 57 | /**
|
---|
| 58 | * Unit test for bad request - incomplete URL.
|
---|
| 59 | * @throws Exception if any error occurs
|
---|
| 60 | */
|
---|
| 61 | @Test
|
---|
| 62 | public void testBadRequestIncompleteUrl() throws Exception {
|
---|
| 63 | thrown.expect(RequestHandlerBadRequestException.class);
|
---|
| 64 | thrown.expectMessage("The following keys are mandatory, but have not been provided: objects");
|
---|
| 65 | newHandler("https://localhost").handle();
|
---|
| 66 | }
|
---|
| 67 |
|
---|
| 68 | /**
|
---|
| 69 | * Unit test for nominal request - local data file.
|
---|
| 70 | * @throws Exception if any error occurs
|
---|
| 71 | */
|
---|
| 72 | @Test
|
---|
| 73 | public void testNominalRequest() throws Exception {
|
---|
| 74 | newHandler("https://localhost?objects=foo,bar").handle();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|