1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertEquals;
|
---|
5 | import static org.junit.Assert.assertFalse;
|
---|
6 | import static org.junit.Assert.assertTrue;
|
---|
7 |
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import org.junit.Rule;
|
---|
11 | import org.junit.Test;
|
---|
12 | import org.openstreetmap.josm.Main;
|
---|
13 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
14 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
15 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
---|
16 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Unit tests for class {@link AddImageryLayerAction}.
|
---|
20 | */
|
---|
21 | public final class AddImageryLayerActionTest {
|
---|
22 | /**
|
---|
23 | * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
|
---|
24 | */
|
---|
25 | @Rule
|
---|
26 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI();
|
---|
27 |
|
---|
28 | /**
|
---|
29 | * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
|
---|
30 | */
|
---|
31 | @Test
|
---|
32 | public void testEnabledState() {
|
---|
33 | assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
|
---|
34 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
|
---|
35 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
|
---|
36 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
|
---|
37 | assertFalse(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
|
---|
38 | }
|
---|
39 |
|
---|
40 | /**
|
---|
41 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
|
---|
42 | */
|
---|
43 | @Test
|
---|
44 | public void testActionPerformedEnabled() {
|
---|
45 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
46 | new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
|
---|
47 | List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
|
---|
48 | assertEquals(1, tmsLayers.size());
|
---|
49 |
|
---|
50 | try {
|
---|
51 | new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
|
---|
52 | "wms_endpoint", null, null)).actionPerformed(null);
|
---|
53 | List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class);
|
---|
54 | assertEquals(1, wmsLayers.size());
|
---|
55 |
|
---|
56 | Main.map.mapView.removeLayer(wmsLayers.get(0));
|
---|
57 | } finally {
|
---|
58 | Main.map.mapView.removeLayer(tmsLayers.get(0));
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
|
---|
64 | */
|
---|
65 | @Test
|
---|
66 | public void testActionPerformedDisabled() {
|
---|
67 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
68 | new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
|
---|
69 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
70 | }
|
---|
71 | }
|
---|