| 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.gui.layer.WMSLayer;
|
|---|
| 15 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
|---|
| 16 |
|
|---|
| 17 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * Unit tests for class {@link AddImageryLayerAction}.
|
|---|
| 21 | */
|
|---|
| 22 | public final class AddImageryLayerActionTest {
|
|---|
| 23 | /**
|
|---|
| 24 | * We need prefs for this. We need platform for actions and the OSM API for checking blacklist.
|
|---|
| 25 | * The timeout is set to default httpclient read timeout + connect timeout + a small delay to ignore
|
|---|
| 26 | * common but harmless network issues.
|
|---|
| 27 | */
|
|---|
| 28 | @Rule
|
|---|
| 29 | @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
|
|---|
| 30 | public JOSMTestRules test = new JOSMTestRules().preferences().platform().fakeAPI().timeout(45500);
|
|---|
| 31 |
|
|---|
| 32 | /**
|
|---|
| 33 | * Unit test of {@link AddImageryLayerAction#updateEnabledState}.
|
|---|
| 34 | */
|
|---|
| 35 | @Test
|
|---|
| 36 | public void testEnabledState() {
|
|---|
| 37 | assertTrue(new AddImageryLayerAction(new ImageryInfo()).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 | assertTrue(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.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 50 | new AddImageryLayerAction(new ImageryInfo("foo_tms", "http://bar", "tms", null, null)).actionPerformed(null);
|
|---|
| 51 | List<TMSLayer> tmsLayers = Main.getLayerManager().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.getLayerManager().getLayersOfType(WMSLayer.class);
|
|---|
| 58 | assertEquals(1, wmsLayers.size());
|
|---|
| 59 |
|
|---|
| 60 | Main.getLayerManager().removeLayer(wmsLayers.get(0));
|
|---|
| 61 | } finally {
|
|---|
| 62 | Main.getLayerManager().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.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 72 | try {
|
|---|
| 73 | new AddImageryLayerAction(new ImageryInfo()).actionPerformed(null);
|
|---|
| 74 | } catch (IllegalArgumentException expected) {
|
|---|
| 75 | assertEquals("Parameter 'info.url' must not be null", expected.getMessage());
|
|---|
| 76 | }
|
|---|
| 77 | assertTrue(Main.getLayerManager().getLayersOfType(TMSLayer.class).isEmpty());
|
|---|
| 78 | }
|
|---|
| 79 | }
|
|---|