1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.gui.preferences.server;
|
---|
3 |
|
---|
4 | import static org.junit.Assert.assertFalse;
|
---|
5 | import static org.junit.Assert.assertTrue;
|
---|
6 |
|
---|
7 | import java.awt.Component;
|
---|
8 |
|
---|
9 | import javax.swing.JLabel;
|
---|
10 |
|
---|
11 | import org.junit.Rule;
|
---|
12 | import org.junit.Test;
|
---|
13 | import org.openstreetmap.josm.spi.preferences.Config;
|
---|
14 | import org.openstreetmap.josm.testutils.JOSMTestRules;
|
---|
15 |
|
---|
16 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * Unit tests of {@link ApiUrlTestTask} class.
|
---|
20 | */
|
---|
21 | public 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 | }
|
---|