source: josm/trunk/test/unit/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTaskTest.java @ 12248

Last change on this file since 12248 was 12248, checked in by Don-vip, 7 months ago

add missing https rules in unit tests

  • Property svn:eol-style set to native
File size: 2.4 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.osm.DataSet;
13import org.openstreetmap.josm.testutils.JOSMTestRules;
14
15import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
16
17/**
18 * Unit tests for class {@link DownloadOsmTask}.
19 */
20public class DownloadOsmTaskTest {
21
22    private static final String REMOTE_FILE = "https://josm.openstreetmap.de/export/head/josm/trunk/data_nodist/direction-arrows.osm";
23
24    /**
25     * Setup test.
26     */
27    @Rule
28    @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
29    public JOSMTestRules test = new JOSMTestRules().https();
30
31    /**
32     * Unit test of {@code DownloadOsmTask#acceptsUrl} method.
33     */
34    @Test
35    public void testAcceptsURL() {
36        DownloadOsmTask task = new DownloadOsmTask();
37        assertFalse(task.acceptsUrl(null));
38        assertFalse(task.acceptsUrl(""));
39        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/node/100"));
40        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/way/100"));
41        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relation/100"));
42        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/nodes?nodes=101,102,103"));
43        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/ways?ways=101,102,103"));
44        assertTrue(task.acceptsUrl("http://api.openstreetmap.org/api/0.6/relations?relations=101,102,103"));
45        assertTrue(task.acceptsUrl(REMOTE_FILE));
46    }
47
48    /**
49     * Unit test of {@code DownloadOsmTask#loadUrl} method with an external file.
50     * @throws ExecutionException if the computation threw an exception
51     * @throws InterruptedException if the current thread was interrupted while waiting
52     */
53    @Test
54    public void testDownloadExternalFile() throws InterruptedException, ExecutionException {
55        DownloadOsmTask task = new DownloadOsmTask();
56        task.loadUrl(false, REMOTE_FILE, null).get();
57        DataSet ds = task.getDownloadedData();
58        assertNotNull(ds);
59        assertFalse(ds.getNodes().isEmpty());
60        assertFalse(ds.getWays().isEmpty());
61    }
62}
Note: See TracBrowser for help on using the repository browser.