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.assertTrue;
|
---|
6 |
|
---|
7 | import java.util.List;
|
---|
8 |
|
---|
9 | import org.junit.Rule;
|
---|
10 | import org.junit.Test;
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
13 | import org.openstreetmap.josm.gui.layer.TMSLayer;
|
---|
14 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
15 |
|
---|
16 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
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 | * The timeout is set to default httpclient read timeout + connect timeout + a small delay to ignore
|
---|
25 | * common but harmless network issues.
|
---|
26 | */
|
---|
27 | @Rule
|
---|
28 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
---|
29 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI().timeout(45500);
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
|
---|
33 | */
|
---|
34 | @Test
|
---|
35 | public void testEnabledState() {
|
---|
36 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo")).isEnabled());
|
---|
37 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
|
---|
38 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
|
---|
39 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
|
---|
40 | assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
|
---|
41 | }
|
---|
42 |
|
---|
43 | /**
|
---|
44 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases for TMS.
|
---|
45 | */
|
---|
46 | @Test
|
---|
47 | public void testActionPerformedEnabled() {
|
---|
48 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
49 | new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
|
---|
50 | List<TMSLayer> tmsLayers = Main.getLayerManager().getLayersOfType(TMSLayer.class);
|
---|
51 | assertEquals(1, tmsLayers.size());
|
---|
52 | Main.getLayerManager().removeLayer(tmsLayers.get(0));
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
|
---|
57 | */
|
---|
58 | @Test
|
---|
59 | public void testActionPerformedDisabled() {
|
---|
60 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
61 | try {
|
---|
62 | new AddImageryLayerAction(new ImageryInfo("foo")).actionPerformed(null);
|
---|
63 | } catch (IllegalArgumentException expected) {
|
---|
64 | assertEquals("Parameter 'info.url' must not be null", expected.getMessage());
|
---|
65 | }
|
---|
66 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
---|
67 | }
|
---|
68 | }
|
---|