source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandlerTest.java@ 12636

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

see #15182 - deprecate Main.getLayerManager(). Replacement: gui.MainApplication.getLayerManager()

  • Property svn:eol-style set to native
File size: 3.4 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.data.osm.DataSet;
8import org.openstreetmap.josm.gui.MainApplication;
9import org.openstreetmap.josm.gui.layer.OsmDataLayer;
10import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
11import org.openstreetmap.josm.testutils.JOSMTestRules;
12
13import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
14
15/**
16 * Unit tests of {@link AddNodeHandler} class.
17 */
18public class AddNodeHandlerTest {
19
20 /**
21 * Rule used for tests throwing exceptions.
22 */
23 @Rule
24 public ExpectedException thrown = ExpectedException.none();
25
26 /**
27 * Setup test.
28 */
29 @Rule
30 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
31 public JOSMTestRules test = new JOSMTestRules();
32
33 private static AddNodeHandler newHandler(String url) throws RequestHandlerBadRequestException {
34 AddNodeHandler req = new AddNodeHandler();
35 if (url != null)
36 req.setUrl(url);
37 return req;
38 }
39
40 /**
41 * Unit test for bad request - no layer.
42 * @throws Exception if any error occurs
43 */
44 @Test
45 public void testBadRequestNoLayer() throws Exception {
46 thrown.expect(RequestHandlerBadRequestException.class);
47 thrown.expectMessage("There is no layer opened to add node");
48 newHandler("https://localhost?lat=0&lon=0").handle();
49 }
50
51 /**
52 * Unit test for bad request - no param.
53 * @throws Exception if any error occurs
54 */
55 @Test
56 public void testBadRequestNoParam() throws Exception {
57 thrown.expect(RequestHandlerBadRequestException.class);
58 thrown.expectMessage("NumberFormatException (empty String)");
59 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
60 try {
61 MainApplication.getLayerManager().addLayer(layer);
62 newHandler(null).handle();
63 } finally {
64 MainApplication.getLayerManager().removeLayer(layer);
65 }
66 }
67
68 /**
69 * Unit test for bad request - invalid URL.
70 * @throws Exception if any error occurs
71 */
72 @Test
73 public void testBadRequestInvalidUrl() throws Exception {
74 thrown.expect(RequestHandlerBadRequestException.class);
75 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon");
76 newHandler("invalid_url").handle();
77 }
78
79 /**
80 * Unit test for bad request - incomplete URL.
81 * @throws Exception if any error occurs
82 */
83 @Test
84 public void testBadRequestIncompleteUrl() throws Exception {
85 thrown.expect(RequestHandlerBadRequestException.class);
86 thrown.expectMessage("The following keys are mandatory, but have not been provided: lat, lon");
87 newHandler("https://localhost").handle();
88 }
89
90 /**
91 * Unit test for nominal request - local data file.
92 * @throws Exception if any error occurs
93 */
94 @Test
95 public void testNominalRequest() throws Exception {
96 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
97 try {
98 MainApplication.getLayerManager().addLayer(layer);
99 newHandler("https://localhost?lat=0&lon=0").handle();
100 } finally {
101 MainApplication.getLayerManager().removeLayer(layer);
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.