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

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

use more reliable public WMS server from OpenStreetMap France for unit tests

  • Property svn:eol-style set to native
File size: 3.0 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.assertFalse;
6import static org.junit.Assert.assertTrue;
7
8import java.util.List;
9
10import org.junit.BeforeClass;
11import org.junit.Test;
12import org.openstreetmap.josm.JOSMFixture;
13import org.openstreetmap.josm.Main;
14import org.openstreetmap.josm.data.imagery.ImageryInfo;
15import org.openstreetmap.josm.gui.layer.TMSLayer;
16import org.openstreetmap.josm.gui.layer.WMSLayer;
17
18/**
19 * Unit tests for class {@link AddImageryLayerAction}.
20 */
21public final class AddImageryLayerActionTest {
22
23 /**
24 * Setup test.
25 */
26 @BeforeClass
27 public static void setUp() {
28 JOSMFixture.createUnitTestFixture().init(true);
29 }
30
31 /**
32 * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
33 */
34 @Test
35 public void testEnabledState() {
36 assertFalse(new AddImageryLayerAction(new ImageryInfo()).isEnabled());
37 assertFalse(new AddImageryLayerAction(new ImageryInfo("google", "http://maps.google.com/api", "tms", null, null)).isEnabled());
38 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).isEnabled());
39 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_bing", "http://bar", "bing", null, null)).isEnabled());
40 assertTrue(new AddImageryLayerAction(new ImageryInfo("foo_scanex", "http://bar", "scanex", null, null)).isEnabled());
41 assertFalse(new AddImageryLayerAction(new ImageryInfo("foo_wms_endpoint", "http://bar", "wms_endpoint", null, null)).isEnabled());
42 }
43
44 /**
45 * Unit test of {@link AddImageryLayerAction#actionPerformed} - Enabled cases.
46 */
47 @Test
48 public void testActionPerformedEnabled() {
49 assertTrue(Main.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
50 new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
51 List<TMSLayer> tmsLayers = Main.map.mapView.getLayersOfType(TMSLayer.class);
52 assertEquals(1, tmsLayers.size());
53
54 try {
55 new AddImageryLayerAction(new ImageryInfo("wms.openstreetmap.fr", "http://wms.openstreetmap.fr/wms?",
56 "wms_endpoint", null, null)).actionPerformed(null);
57 List<WMSLayer> wmsLayers = Main.map.mapView.getLayersOfType(WMSLayer.class);
58 assertEquals(1, wmsLayers.size());
59
60 Main.map.mapView.removeLayer(wmsLayers.get(0));
61 } finally {
62 Main.map.mapView.removeLayer(tmsLayers.get(0));
63 }
64 }
65
66 /**
67 * Unit test of {@link AddImageryLayerAction#actionPerformed} - disabled case.
68 */
69 @Test
70 public void testActionPerformedDisabled() {
71 assertTrue(Main.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
72 new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
73 assertTrue(Main.map.mapView.getLayersOfType(TMSLayer.class).isEmpty());
74 }
75}
Note: See TracBrowser for help on using the repository browser.