source: josm/trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandlerTest.java@ 17332

Last change on this file since 17332 was 17275, checked in by Don-vip, 3 years ago

see #16567 - upgrade almost all tests to JUnit 5, except those depending on WiremockRule

See https://github.com/tomakehurst/wiremock/issues/684

  • Property svn:eol-style set to native
File size: 3.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
5import static org.junit.jupiter.api.Assertions.assertEquals;
6import static org.junit.jupiter.api.Assertions.assertThrows;
7
8import org.junit.jupiter.api.extension.RegisterExtension;
9import org.junit.jupiter.api.Test;
10import org.openstreetmap.josm.data.osm.DataSet;
11import org.openstreetmap.josm.gui.MainApplication;
12import org.openstreetmap.josm.gui.layer.OsmDataLayer;
13import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests of {@link AddWayHandler} class.
20 */
21class AddWayHandlerTest {
22 /**
23 * Setup test.
24 */
25 @RegisterExtension
26 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
27 public JOSMTestRules test = new JOSMTestRules();
28
29 private static AddWayHandler newHandler(String url) throws RequestHandlerBadRequestException {
30 AddWayHandler req = new AddWayHandler();
31 if (url != null)
32 req.setUrl(url);
33 return req;
34 }
35
36 /**
37 * Unit test for bad request - no layer.
38 */
39 @Test
40 void testBadRequestNoLayer() {
41 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost?way=0,0;1,1").handle());
42 assertEquals("There is no layer opened to add way", e.getMessage());
43 }
44
45 /**
46 * Unit test for bad request - no param.
47 */
48 @Test
49 void testBadRequestNoParam() {
50 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
51 try {
52 MainApplication.getLayerManager().addLayer(layer);
53 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler(null).handle());
54 assertEquals("Invalid coordinates: []", e.getMessage());
55 } finally {
56 MainApplication.getLayerManager().removeLayer(layer);
57 }
58 }
59
60 /**
61 * Unit test for bad request - invalid URL.
62 */
63 @Test
64 void testBadRequestInvalidUrl() {
65 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("invalid_url").handle());
66 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage());
67 }
68
69 /**
70 * Unit test for bad request - incomplete URL.
71 */
72 @Test
73 void testBadRequestIncompleteUrl() {
74 Exception e = assertThrows(RequestHandlerBadRequestException.class, () -> newHandler("https://localhost").handle());
75 assertEquals("The following keys are mandatory, but have not been provided: way", e.getMessage());
76 }
77
78 /**
79 * Unit test for nominal request - local data file.
80 */
81 @Test
82 void testNominalRequest() {
83 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "", null);
84 try {
85 MainApplication.getLayerManager().addLayer(layer);
86 assertDoesNotThrow(() -> newHandler("https://localhost?way=0,0;1,1").handle());
87 } finally {
88 MainApplication.getLayerManager().removeLayer(layer);
89 }
90 }
91}
Note: See TracBrowser for help on using the repository browser.