Changeset 17192 in josm for trunk/test/unit/org/openstreetmap/josm/gui/preferences
- Timestamp:
- 2020-10-13T21:36:06+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/gui/preferences/server/ApiUrlTestTaskTest.java
r14119 r17192 2 2 package org.openstreetmap.josm.gui.preferences.server; 3 3 4 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; 5 import static com.github.tomakehurst.wiremock.client.WireMock.get; 6 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; 7 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; 8 import static org.hamcrest.CoreMatchers.containsString; 9 import static org.hamcrest.MatcherAssert.assertThat; 4 10 import static org.junit.Assert.assertFalse; 5 11 import static org.junit.Assert.assertTrue; … … 11 17 import org.junit.Rule; 12 18 import org.junit.Test; 13 import org.openstreetmap.josm. spi.preferences.Config;19 import org.openstreetmap.josm.TestUtils; 14 20 import org.openstreetmap.josm.testutils.JOSMTestRules; 21 import org.openstreetmap.josm.tools.Logging; 15 22 16 23 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 24 25 import com.github.tomakehurst.wiremock.junit.WireMockRule; 17 26 18 27 /** … … 27 36 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 28 37 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(30000); 38 39 /** 40 * HTTP mock. 41 */ 42 @Rule 43 public WireMockRule wireMockRule = new WireMockRule(options().dynamicPort().usingFilesUnderDirectory(TestUtils.getTestDataRoot())); 29 44 30 45 private static final Component PARENT = new JLabel(); … … 43 58 @Test 44 59 public void testNominalUrl() { 45 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, Config.getUrls().getDefaultOsmApiUrl());60 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/osm_api")); 46 61 task.run(); 47 62 assertTrue(task.isSuccess()); … … 53 68 @Test 54 69 public void testAlertInvalidUrl() { 70 Logging.clearLastErrorAndWarnings(); 55 71 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "malformed url"); 56 72 task.run(); 57 73 assertFalse(task.isSuccess()); 74 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 75 "<html>'malformed url' is not a valid OSM API URL.<br>Please check the spelling and validate again.</html>")); 58 76 } 59 77 … … 63 81 @Test 64 82 public void testUnknownHost() { 83 Logging.clearLastErrorAndWarnings(); 65 84 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://unknown"); 66 85 task.run(); 67 86 assertFalse(task.isSuccess()); 87 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 88 "java.net.UnknownHostException: unknown")); 68 89 } 69 90 … … 73 94 @Test 74 95 public void testAlertInvalidServerResult() { 75 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "http://www.openstreetmap.org"); 96 Logging.clearLastErrorAndWarnings(); 97 wireMockRule.stubFor(get(urlEqualTo("/does-not-exist/0.6/capabilities")) 98 .willReturn(aResponse().withStatus(404))); 99 100 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/does-not-exist")); 76 101 task.run(); 77 102 assertFalse(task.isSuccess()); 103 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 104 "The server responded with the return code 404 instead of 200.")); 78 105 } 79 106 … … 83 110 @Test 84 111 public void testAlertInvalidCapabilities() { 85 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, "https://josm.openstreetmap.de/export/10979/josm/trunk/test/data/invalid_api"); 112 Logging.clearLastErrorAndWarnings(); 113 ApiUrlTestTask task = new ApiUrlTestTask(PARENT, wireMockRule.url("/__files/invalid_api")); 86 114 task.run(); 87 115 assertFalse(task.isSuccess()); 116 assertThat(Logging.getLastErrorAndWarnings().toString(), containsString( 117 "The OSM API server at 'XXX' did not return a valid response.<br>It is likely that 'XXX' is not an OSM API server." 118 .replace("XXX", wireMockRule.url("/__files/invalid_api")))); 88 119 } 89 120 }
Note:
See TracChangeset
for help on using the changeset viewer.