1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.layer.gpx;
|
---|
3 |
|
---|
4 | import static java.util.concurrent.TimeUnit.MILLISECONDS;
|
---|
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.awaitility.Awaitility;
|
---|
10 | import org.junit.Ignore;
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
14 | import org.openstreetmap.josm.gui.MainApplication;
|
---|
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 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
19 | import org.openstreetmap.josm.testutils.TileSourceRule;
|
---|
20 |
|
---|
21 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * Unit tests of {@link DownloadWmsAlongTrackAction} class.
|
---|
25 | */
|
---|
26 | public class DownloadWmsAlongTrackActionTest {
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Setup test.
|
---|
30 | */
|
---|
31 | @Rule
|
---|
32 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
33 | public JOSMTestRules test = new JOSMTestRules().platform().main().projection().fakeImagery().timeout(20000);
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Test action without layer.
|
---|
37 | */
|
---|
38 | @Test
|
---|
39 | public void testNoLayer() {
|
---|
40 | assertNull(new DownloadWmsAlongTrackAction(new GpxData()).createTask());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Test action with a TMS layer.
|
---|
45 | * @throws Exception if an error occurs
|
---|
46 | */
|
---|
47 | @Test
|
---|
48 | @Ignore("Test fails since r14052 - see #16590")
|
---|
49 | public void testTMSLayer() throws Exception {
|
---|
50 | final TileSourceRule tileSourceRule = this.test.getTileSourceRule();
|
---|
51 |
|
---|
52 | final TMSLayer layer = new TMSLayer(
|
---|
53 | tileSourceRule.getSourcesList().get(0).getImageryInfo(tileSourceRule.port())
|
---|
54 | );
|
---|
55 | try {
|
---|
56 | MainApplication.getLayerManager().addLayer(layer);
|
---|
57 | TMSLayer.getCache().clear();
|
---|
58 | assertTrue(TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
59 | // Perform action
|
---|
60 | PrecacheWmsTask task = new DownloadWmsAlongTrackAction(GpxLayerTest.getMinimalGpxData()).createTask();
|
---|
61 | assertNotNull(task);
|
---|
62 | task.run();
|
---|
63 | // Ensure cache is (eventually) not empty
|
---|
64 | Awaitility.await().atMost(10000, MILLISECONDS).until(() -> !TMSLayer.getCache().getMatching(".*").isEmpty());
|
---|
65 | } finally {
|
---|
66 | // Ensure we clean the place before leaving, even if test fails.
|
---|
67 | MainApplication.getLayerManager().removeLayer(layer);
|
---|
68 | }
|
---|
69 | }
|
---|
70 | }
|
---|