source: josm/trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTaskTest.java@ 11124

Last change on this file since 11124 was 11124, checked in by simon04, 8 years ago

see #13749 - Enhance supported URLs for downloading GPS data

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions.downloadtasks;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertNotNull;
6import static org.junit.Assert.assertTrue;
7
8import java.util.concurrent.ExecutionException;
9
10import org.junit.Rule;
11import org.junit.Test;
12import org.openstreetmap.josm.data.gpx.GpxData;
13import org.openstreetmap.josm.testutils.JOSMTestRules;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17/**
18 * Unit tests for class {@link DownloadGpsTask}.
19 */
20public 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();
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}
Note: See TracBrowser for help on using the repository browser.