1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.gpx;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertNotNull;
|
---|
6 | import static org.junit.Assert.assertNull;
|
---|
7 | import static org.junit.Assert.assertTrue;
|
---|
8 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
13 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
14 | import org.openstreetmap.josm.gui.layer.GpxLayerTest;
|
---|
15 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
16 | import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
|
---|
17 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
18 |
|
---|
19 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
20 |
|
---|
21 | /**
|
---|
22 | * Unit tests of {@link DownloadWmsAlongTrackAction} class.
|
---|
23 | */
|
---|
24 | public class DownloadWmsAlongTrackActionTest {
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * Setup test.
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules().platform().main().projection();
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Test action without layer.
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testNoLayer() {
|
---|
38 | assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
|
---|
39 | }
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * Test action with a TMS layer.
|
---|
43 | * @throws Exception if an error occurs
|
---|
44 | */
|
---|
45 | @Test
|
---|
46 | public void testTMSLayer() throws Exception {
|
---|
47 | // Create new TMS layer and clear cache
|
---|
48 | TMSLayer layer = new TMSLayer(new ImageryInfo("OSM TMS", "https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", "tms", null, null));
|
---|
49 | try {
|
---|
50 | Main.getLayerManager().addLayer(layer);
|
---|
51 | TMSLayer.getCache().clear();
|
---|
52 | assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
53 | // Perform action
|
---|
54 | PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
|
---|
55 | assertNotNull(task);
|
---|
56 | task.run();
|
---|
57 | // Ensure cache is not empty
|
---|
58 | assertFalse(TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
59 | } finally {
|
---|
60 | // Ensure we clean the place before leaving, even if test fails.
|
---|
61 | Main.getLayerManager().removeLayer(layer);
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|