source: josm/trunk/test/unit/org/openstreetmap/josm/actions/AddImageryLayerActionTest.java@ 12444

Last change on this file since 12444 was 12444, checked in by Don-vip, 7 years ago

refactor WMS test to integration test as it relies on external WMS server

  • Property svn:eol-style set to native
File size: 2.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertTrue;
6
7import java.util.List;
8
9import org.junit.Rule;
10import org.junit.Test;
11import org.openstreetmap.josm.Main;
12import org.openstreetmap.josm.data.imagery.ImageryInfo;
13import org.openstreetmap.josm.gui.layer.TMSLayer;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests for class {@link AddImageryLayerAction}.
20 */
21public 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}
Note: See TracBrowser for help on using the repository browser.