[9666] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
| 3 |
|
---|
| 4 | import static org.junit.Assert.assertFalse;
|
---|
| 5 | import static org.junit.Assert.assertNotNull;
|
---|
| 6 | import static org.junit.Assert.assertTrue;
|
---|
| 7 |
|
---|
| 8 | import java.util.concurrent.ExecutionException;
|
---|
| 9 |
|
---|
[10945] | 10 | import org.junit.Rule;
|
---|
[9666] | 11 | import org.junit.Test;
|
---|
| 12 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
[10945] | 13 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
[9666] | 14 |
|
---|
[10945] | 15 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
| 16 |
|
---|
[9666] | 17 | /**
|
---|
| 18 | * Unit tests for class {@link DownloadOsmTask}.
|
---|
| 19 | */
|
---|
| 20 | public class DownloadOsmTaskTest {
|
---|
| 21 |
|
---|
| 22 | private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/data_nodist/direction-arrows.osm";
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * Setup test.
|
---|
| 26 | */
|
---|
[10945] | 27 | @Rule
|
---|
| 28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
[12248] | 29 | public JOSMTestRules test = new JOSMTestRules().https();
|
---|
[9666] | 30 |
|
---|
| 31 | /**
|
---|
| 32 | * Unit test of {@code DownloadOsmTask#acceptsUrl} method.
|
---|
| 33 | */
|
---|
| 34 | @Test
|
---|
| 35 | public void testAcceptsURL() {
|
---|
| 36 | DownloadOsmTask task = new DownloadOsmTask();
|
---|
| 37 | assertFalse(task.acceptsUrl(null));
|
---|
| 38 | assertFalse(task.acceptsUrl(""));
|
---|
| 39 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/node/100"));
|
---|
| 40 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/way/100"));
|
---|
| 41 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relation/100"));
|
---|
| 42 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/nodes?nodes=101,102,103"));
|
---|
| 43 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/ways?ways=101,102,103"));
|
---|
| 44 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relations?relations=101,102,103"));
|
---|
| 45 | assertTrue(task.acceptsUrl(REMOTE_FILE));
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | /**
|
---|
| 49 | * Unit test of {@code DownloadOsmTask#loadUrl} method with an external file.
|
---|
| 50 | * @throws ExecutionException if the computation threw an exception
|
---|
| 51 | * @throws InterruptedException if the current thread was interrupted while waiting
|
---|
| 52 | */
|
---|
| 53 | @Test
|
---|
| 54 | public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
|
---|
| 55 | DownloadOsmTask task = new DownloadOsmTask();
|
---|
| 56 | task.loadUrl(false, REMOTE_FILE, null).get();
|
---|
| 57 | DataSet ds = task.getDownloadedData();
|
---|
| 58 | assertNotNull(ds);
|
---|
| 59 | assertFalse(ds.getNodes().isEmpty());
|
---|
| 60 | assertFalse(ds.getWays().isEmpty());
|
---|
| 61 | }
|
---|
| 62 | }
|
---|