1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.concurrent.ExecutionException;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Unit tests for class {@link DownloadOsmTask}.
|
---|
15 | */
|
---|
16 | class DownloadOsmTaskTest extends AbstractDownloadTaskTestParent {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Unit test of {@code DownloadOsmTask#acceptsUrl} method.
|
---|
20 | */
|
---|
21 | @Test
|
---|
22 | 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 | void testDownloadExternalFile() throws InterruptedException, ExecutionException {
|
---|
42 | mockHttp();
|
---|
43 | DownloadOsmTask task = new DownloadOsmTask();
|
---|
44 | task.loadUrl(new DownloadParams(), 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 | }
|
---|