Changeset 9732 in josm for trunk/test/unit
- Timestamp:
- 2016-02-04T00:48:38+01:00 (9 years ago)
- Location:
- trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandlerTest.java
r8876 r9732 4 4 import static org.junit.Assert.assertEquals; 5 5 6 import java.io.File; 7 8 import org.junit.BeforeClass; 9 import org.junit.Rule; 6 10 import org.junit.Test; 11 import org.junit.rules.ExpectedException; 12 import org.openstreetmap.josm.JOSMFixture; 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.TestUtils; 15 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 16 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 17 import org.openstreetmap.josm.tools.Utils; 7 18 8 19 /** … … 12 23 13 24 /** 25 * Rule used for tests throwing exceptions. 26 */ 27 @Rule 28 public ExpectedException thrown = ExpectedException.none(); 29 30 /** 31 * Setup test. 32 */ 33 @BeforeClass 34 public static void setUpBeforeClass() { 35 JOSMFixture.createUnitTestFixture().init(true); 36 } 37 38 private static ImportHandler newHandler(String url) { 39 ImportHandler req = new ImportHandler(); 40 if (url != null) 41 req.setUrl(url); 42 return req; 43 } 44 45 /** 14 46 * Non-regression test for bug #7434. 15 47 */ 16 48 @Test 17 49 public void testTicket7434() { 18 final ImportHandler req = new ImportHandler(); 19 req.setUrl("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive"); 50 ImportHandler req = newHandler("http://localhost:8111/import?url=http://localhost:8888/relations?relations=19711&mode=recursive"); 20 51 assertEquals("http://localhost:8888/relations?relations=19711&mode=recursive", req.args.get("url")); 21 52 } 53 54 /** 55 * Unit test for bad request - no param. 56 * @throws Exception if any error occurs 57 */ 58 @Test 59 public void testBadRequestNoParam() throws Exception { 60 thrown.expect(RequestHandlerBadRequestException.class); 61 thrown.expectMessage("MalformedURLException: null"); 62 newHandler(null).handle(); 63 } 64 65 /** 66 * Unit test for bad request - invalid URL. 67 * @throws Exception if any error occurs 68 */ 69 @Test 70 public void testBadRequestInvalidUrl() throws Exception { 71 thrown.expect(RequestHandlerBadRequestException.class); 72 thrown.expectMessage("MalformedURLException: no protocol: invalid_url"); 73 newHandler("https://localhost?url=invalid_url").handle(); 74 } 75 76 /** 77 * Unit test for bad request - incomplete URL. 78 * @throws Exception if any error occurs 79 */ 80 @Test 81 public void testBadRequestIncompleteUrl() throws Exception { 82 thrown.expect(RequestHandlerBadRequestException.class); 83 thrown.expectMessage("The following keys are mandatory, but have not been provided: url"); 84 newHandler("https://localhost").handle(); 85 } 86 87 /** 88 * Unit test for nominal request - local data file. 89 * @throws Exception if any error occurs 90 */ 91 @Test 92 public void testNominalRequest() throws Exception { 93 String url = new File(TestUtils.getRegressionDataFile(11957, "data.osm")).toURI().toURL().toExternalForm(); 94 try { 95 newHandler("https://localhost?url=" + Utils.encodeUrl(url)).handle(); 96 } finally { 97 for (OsmDataLayer layer : Main.map.mapView.getLayersOfType(OsmDataLayer.class)) { 98 Main.main.removeLayer(layer); 99 } 100 } 101 } 22 102 }
Note:
See TracChangeset
for help on using the changeset viewer.