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