source: josm/trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java@ 16159

Last change on this file since 16159 was 14119, checked in by Don-vip, 6 years ago

see #15229 - deprecate all Main methods returning an URL

  • Property svn:eol-style set to native
File size: 2.5 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.server;
3
4import static org.junit.Assert.assertFalse;
5import static org.junit.Assert.assertTrue;
6
7import java.awt.Component;
8
9import javax.swing.JLabel;
10
11import org.junit.Rule;
12import org.junit.Test;
13import org.openstreetmap.josm.spi.preferences.Config;
14import org.openstreetmap.josm.testutils.JOSMTestRules;
15
16import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
17
18/**
19 * Unit tests of {@link ApiUrlTestTask} class.
20 */
21public class ApiUrlTestTaskTest {
22
23 /**
24 * Setup tests
25 */
26 @Rule
27 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD")
28 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000);
29
30 private static final Component PARENT = new JLabel();
31
32 /**
33 * Unit test of {@link ApiUrlTestTask#ApiUrlTestTask} - null url.
34 */
35 @Test(expected = IllegalArgumentException.class)
36 public void testNullApiUrl() {
37 new ApiUrlTestTask(PARENT, null);
38 }
39
40 /**
41 * Unit test of {@link ApiUrlTestTask} - nominal url.
42 */
43 @Test
44 public void testNominalUrl() {
45 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, Config.getUrls().getDefaultOsmApiUrl());
46 task.run();
47 assertTrue(task.isSuccess());
48 }
49
50 /**
51 * Unit test of {@link ApiUrlTestTask#alertInvalidUrl} - malformed url.
52 */
53 @Test
54 public void testAlertInvalidUrl() {
55 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "malformed url");
56 task.run();
57 assertFalse(task.isSuccess());
58 }
59
60 /**
61 * Unit test of {@link ApiUrlTestTask} - unknown host.
62 */
63 @Test
64 public void testUnknownHost() {
65 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://unknown");
66 task.run();
67 assertFalse(task.isSuccess());
68 }
69
70 /**
71 * Unit test of {@link ApiUrlTestTask#alertInvalidServerResult} - http 404.
72 */
73 @Test
74 public void testAlertInvalidServerResult() {
75 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://www.openstreetmap.org");
76 task.run();
77 assertFalse(task.isSuccess());
78 }
79
80 /**
81 * Unit test of {@link ApiUrlTestTask#alertInvalidCapabilities} - invalid contents.
82 */
83 @Test
84 public void testAlertInvalidCapabilities() {
85 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "https://josm.openstreetmap.de/export/10979/josm/trunk/test/data/invalid_api");
86 task.run();
87 assertFalse(task.isSuccess());
88 }
89}
Note: See TracBrowser for help on using the repository browser.