source: josm/trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java@ 12557

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

see #15102 - first batch of HTTP unit tests mocking, using WireMock 2.7.1

  • Property svn:eol-style set to native
File size: 2.1 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertTrue;
7
8import java.util.concurrent.ExecutionException;
9
10import org.junit.Test;
11import org.openstreetmap.josm.data.osm.DataSet;
12
13/**
14 * Unit tests for class {@link DownloadOsmTask}.
15 */
16public class DownloadOsmTaskTest extends AbstractDownloadTaskTest {
17
18 /**
19 * Unit test of {@code DownloadOsmTask#acceptsUrl} method.
20 */
21 @Test
22 public void testAcceptsURL() {
23 DownloadOsmTask task = new DownloadOsmTask();
24 assertFalse(task.acceptsUrl(null));
25 assertFalse(task.acceptsUrl(""));
26 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/node/100"));
27 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/way/100"));
28 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relation/100"));
29 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/nodes?nodes=101,102,103"));
30 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/ways?ways=101,102,103"));
31 assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relations?relations=101,102,103"));
32 assertTrue(task.acceptsUrl(getRemoteFileUrl()));
33 }
34
35 /**
36 * Unit test of {@code DownloadOsmTask#loadUrl} method with an external file.
37 * @throws ExecutionException if the computation threw an exception
38 * @throws InterruptedException if the current thread was interrupted while waiting
39 */
40 @Test
41 public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
42 mockHttp();
43 DownloadOsmTask task = new DownloadOsmTask();
44 task.loadUrl(false, getRemoteFileUrl(), null).get();
45 DataSet ds = task.getDownloadedData();
46 assertNotNull(ds);
47 assertFalse(ds.getNodes().isEmpty());
48 assertFalse(ds.getWays().isEmpty());
49 }
50
51 @Override
52 protected String getRemoteFile() {
53 return "samples/data.osm";
54 }
55}
Note: See TracBrowser for help on using the repository browser.