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.osm.NoteData;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * Unit tests for class {@link DownloadNotesTask}.
|
---|
17 | */
|
---|
18 | public class DownloadNotesTaskTest {
|
---|
19 |
|
---|
20 | private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/test/data/planet-notes-extract.osn";
|
---|
21 |
|
---|
22 | /**
|
---|
23 | * Setup test.
|
---|
24 | */
|
---|
25 | @BeforeClass
|
---|
26 | public static void setUp() {
|
---|
27 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
28 | }
|
---|
29 |
|
---|
30 | /**
|
---|
31 | * Unit test of {@code DownloadNotesTask#acceptsUrl} method.
|
---|
32 | */
|
---|
33 | @Test
|
---|
34 | public void testAcceptsURL() {
|
---|
35 | DownloadNotesTask task = new DownloadNotesTask();
|
---|
36 | assertFalse(task.acceptsUrl(null));
|
---|
37 | assertFalse(task.acceptsUrl(""));
|
---|
38 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
39 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.json?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
40 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.xml?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
41 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.gpx?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
42 | assertTrue(task.acceptsUrl(REMOTE_FILE));
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Unit test of {@code DownloadNotesTask#loadUrl} method with an external file.
|
---|
47 | * @throws ExecutionException if the computation threw an exception
|
---|
48 | * @throws InterruptedException if the current thread was interrupted while waiting
|
---|
49 | */
|
---|
50 | @Test
|
---|
51 | public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
|
---|
52 | DownloadNotesTask task = new DownloadNotesTask();
|
---|
53 | task.loadUrl(false, REMOTE_FILE, null).get();
|
---|
54 | NoteData data = task.getDownloadedData();
|
---|
55 | assertNotNull(data);
|
---|
56 | assertFalse(data.getNotes().isEmpty());
|
---|
57 | }
|
---|
58 | }
|
---|