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.BeforeClass;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.JOSMFixture;
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
14 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
15 | import org.openstreetmap.josm.gui.layer.GpxLayerTest;
|
---|
16 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
17 | import org.openstreetmap.josm.gui.layer.gpx.DownloadWmsAlongTrackAction.PrecacheWmsTask;
|
---|
18 |
|
---|
19 | /**
|
---|
20 | * Unit tests of {@link DownloadWmsAlongTrackAction} class.
|
---|
21 | */
|
---|
22 | public class DownloadWmsAlongTrackActionTest {
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * Setup test.
|
---|
26 | */
|
---|
27 | @BeforeClass
|
---|
28 | public static void setUpBeforeClass() {
|
---|
29 | JOSMFixture.createUnitTestFixture().init(true);
|
---|
30 | }
|
---|
31 |
|
---|
32 | /**
|
---|
33 | * Test action without layer.
|
---|
34 | */
|
---|
35 | @Test
|
---|
36 | public void testNoLayer() {
|
---|
37 | assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Test action with a TMS layer.
|
---|
42 | * @throws Exception if an error occurs
|
---|
43 | */
|
---|
44 | @Test
|
---|
45 | public void testTMSLayer() throws Exception {
|
---|
46 | // Create new TMS layer and clear cache
|
---|
47 | TMSLayer layer = new TMSLayer(new ImageryInfo("OSM TMS", "https://a.tile.openstreetmap.org/{zoom}/{x}/{y}.png", "tms", null, null));
|
---|
48 | try {
|
---|
49 | Main.getLayerManager().addLayer(layer);
|
---|
50 | TMSLayer.getCache().clear();
|
---|
51 | assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
52 | // Perform action
|
---|
53 | PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
|
---|
54 | assertNotNull(task);
|
---|
55 | task.run();
|
---|
56 | // Ensure cache is not empty
|
---|
57 | assertFalse(TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
58 | } finally {
|
---|
59 | // Ensure we clean the place before leaving, even if test fails.
|
---|
60 | Main.getLayerManager().removeLayer(layer);
|
---|
61 | }
|
---|
62 | }
|
---|
63 | }
|
---|