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 |
|
---|
10 | import org.junit.BeforeClass;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.JOSMFixture;
|
---|
13 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Unit tests for class {@link DownloadGpsTask}.
|
---|
17 | */
|
---|
18 | public class DownloadGpsTaskTest {
|
---|
19 |
|
---|
20 | private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/data_nodist/munich.gpx";
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUp() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init();
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unit test of {@code DownloadGpsTask#acceptsUrl} method.
|
---|
32 | */
|
---|
33 | @Test
|
---|
34 | public void testAcceptsURL() {
|
---|
35 | DownloadGpsTask task = new DownloadGpsTask();
|
---|
36 | assertFalse(task.acceptsUrl(null));
|
---|
37 | assertFalse(task.acceptsUrl(""));
|
---|
38 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/trackpoints?bbox=0,51.5,0.25,51.75"));
|
---|
39 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/trackpoints?bbox=0,51.5,0.25,51.75&page=0"));
|
---|
40 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/trace/5000/data"));
|
---|
41 | assertTrue(task.acceptsUrl("http://www.openstreetmap.org/trace/5000/data"));
|
---|
42 | assertTrue(task.acceptsUrl("http://www.trackmyjourney.co.uk/exportgpx.php?session=S6rZR2Bh6GwX1wpB0C&trk=79292"));
|
---|
43 | assertTrue(task.acceptsUrl(REMOTE_FILE));
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * Unit test of {@code DownloadGpsTask#loadUrl} method with an external file.
|
---|
48 | * @throws ExecutionException if the computation threw an exception
|
---|
49 | * @throws InterruptedException if the current thread was interrupted while waiting
|
---|
50 | */
|
---|
51 | @Test
|
---|
52 | public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
|
---|
53 | DownloadGpsTask task = new DownloadGpsTask();
|
---|
54 | task.loadUrl(false, REMOTE_FILE, null).get();
|
---|
55 | GpxData data = task.getDownloadedData();
|
---|
56 | assertNotNull(data);
|
---|
57 | assertFalse(data.waypoints.isEmpty());
|
---|
58 | assertFalse(data.tracks.isEmpty());
|
---|
59 | }
|
---|
60 | }
|
---|