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