source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.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: 3.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.Main;
8import org.openstreetmap.josm.data.osm.DataSet;
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 AddWayHandler} class.
17 */
18public class AddWayHandlerTest {
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 AddWayHandler newHandler(String url) throws RequestHandlerBadRequestException {
34 AddWayHandler req = new AddWayHandler();
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 way");
48 newHandler("https://localhost?way=0,0;1,1").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("Invalid coordinates: []");
59 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
60 try {
61 Main.getLayerManager().addLayer(layer);
62 newHandler(null).handle();
63 } finally {
64 Main.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: way");
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: way");
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 Main.getLayerManager().addLayer(layer);
99 newHandler("https://localhost?way=0,0;1,1").handle();
100 } finally {
101 Main.getLayerManager().removeLayer(layer);
102 }
103 }
104}
Note: See TracBrowser for help on using the repository browser.