source: josm/trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTaskTest.java @ 12557

Last change on this file since 12557 was 12557, checked in by Don-vip, 2 weeks ago

see #15102 - first batch of HTTP unit tests mocking, using WireMock 2.7.1

  • Property svn:eol-style set to native
File size: 2.0 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.Test;
11import org.openstreetmap.josm.data.osm.NoteData;
12
13/**
14 * Unit tests for class {@link DownloadNotesTask}.
15 */
16public class DownloadNotesTaskTest extends AbstractDownloadTaskTest {
17
18    /**
19     * Unit test of {@code DownloadNotesTask#acceptsUrl} method.
20     */
21    @Test
22    public 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    public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
40        mockHttp();
41        DownloadNotesTask task = new DownloadNotesTask();
42        task.loadUrl(false, 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}
Note: See TracBrowser for help on using the repository browser.