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 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Unit tests for class {@link AddImageryLayerAction}.
|
---|
22 | */
|
---|
23 | public final class AddImageryLayerActionTest {
|
---|
24 | /**
|
---|
25 | * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
|
---|
26 | * The timeout is set to default httpclient read timeout + connect timeout + a small delay to ignore
|
---|
27 | * common but harmless network issues.
|
---|
28 | */
|
---|
29 | @Rule
|
---|
30 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
31 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI().timeout(45500);
|
---|
32 |
|
---|
33 | /**
|
---|
34 | * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
|
---|
35 | */
|
---|
36 | @Test
|
---|
37 | public void testEnabledState() {
|
---|
38 | assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
|
---|
39 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
|
---|
40 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
|
---|
41 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
|
---|
42 | assertFalse(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
|
---|
43 | }
|
---|
44 |
|
---|
45 | /**
|
---|
46 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
|
---|
47 | */
|
---|
48 | @Test
|
---|
49 | public void testActionPerformedEnabled() {
|
---|
50 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
51 | new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
|
---|
52 | List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
|
---|
53 | assertEquals(1, tmsLayers.size());
|
---|
54 |
|
---|
55 | try {
|
---|
56 | new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
|
---|
57 | "wms_endpoint", null, null)).actionPerformed(null);
|
---|
58 | List<WMSLayer> wmsLayers = Main.getLayerManager().getLayersOfType(WMSLayer.class);
|
---|
59 | assertEquals(1, wmsLayers.size());
|
---|
60 |
|
---|
61 | Main.getLayerManager().removeLayer(wmsLayers.get(0));
|
---|
62 | } finally {
|
---|
63 | Main.getLayerManager().removeLayer(tmsLayers.get(0));
|
---|
64 | }
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
|
---|
69 | */
|
---|
70 | @Test
|
---|
71 | public void testActionPerformedDisabled() {
|
---|
72 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
73 | try {
|
---|
74 | new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
|
---|
75 | } catch (IllegalArgumentException expected) {
|
---|
76 | assertEquals("Parameter 'info.url' must not be null", expected.getMessage());
|
---|
77 | }
|
---|
78 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
79 | }
|
---|
80 | }
|
---|