source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandlerTest.java@ 12558

Last change on this file since 12558 was 12558, checked in by Don-vip, 7 years ago

see #15102 - unit tests update

  • Property svn:eol-style set to native
File size: 2.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import org.junit.Rule;
5import org.junit.Test;
6import org.junit.rules.ExpectedException;
7import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
8import org.openstreetmap.josm.testutils.JOSMTestRules;
9
10import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
11
12/**
13 * Unit tests of {@link LoadObjectHandler} class.
14 */
15public 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 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules();
29
30 private static LoadObjectHandler newHandler(String url) throws RequestHandlerBadRequestException {
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}
Note: See TracBrowser for help on using the repository browser.