1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
3 |
|
---|
4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
---|
5 | import static org.junit.jupiter.api.Assertions.assertNotNull;
|
---|
6 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.concurrent.ExecutionException;
|
---|
9 |
|
---|
10 | import org.junit.jupiter.api.Test;
|
---|
11 | import org.openstreetmap.josm.data.osm.NoteData;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Unit tests for class {@link DownloadNotesTask}.
|
---|
15 | */
|
---|
16 | class DownloadNotesTaskTest extends AbstractDownloadTaskTestParent {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Unit test of {@code DownloadNotesTask#acceptsUrl} method.
|
---|
20 | */
|
---|
21 | @Test
|
---|
22 | void testAcceptsURL() {
|
---|
23 | DownloadNotesTask task = new DownloadNotesTask();
|
---|
24 | assertFalse(task.acceptsUrl(null));
|
---|
25 | assertFalse(task.acceptsUrl(""));
|
---|
26 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
27 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.json?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
28 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.xml?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
29 | assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/notes.gpx?bbox=-0.65094,51.312159,0.374908,51.669148"));
|
---|
30 | assertTrue(task.acceptsUrl(getRemoteFileUrl()));
|
---|
31 | }
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Unit test of {@code DownloadNotesTask#loadUrl} method with an external file.
|
---|
35 | * @throws ExecutionException if the computation threw an exception
|
---|
36 | * @throws InterruptedException if the current thread was interrupted while waiting
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | void testDownloadExternalFile() throws InterruptedException, ExecutionException {
|
---|
40 | mockHttp();
|
---|
41 | DownloadNotesTask task = new DownloadNotesTask();
|
---|
42 | task.loadUrl(new DownloadParams(), getRemoteFileUrl(), null).get();
|
---|
43 | NoteData data = task.getDownloadedData();
|
---|
44 | assertNotNull(data);
|
---|
45 | assertFalse(data.getNotes().isEmpty());
|
---|
46 | }
|
---|
47 |
|
---|
48 | @Override
|
---|
49 | protected String getRemoteFile() {
|
---|
50 | return "samples/data.osn";
|
---|
51 | }
|
---|
52 | }
|
---|