Changeset 18106 in josm for trunk/test/functional/org
- Timestamp:
- 2021-08-01T21:21:38+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r17211 r18106 16 16 import static org.hamcrest.MatcherAssert.assertThat; 17 17 import static org.hamcrest.text.IsEqualIgnoringCase.equalToIgnoringCase; 18 import static org.junit.Assert.assertEquals; 19 import static org.junit.Assert.assertTrue; 18 import static org.junit.jupiter.api.Assertions.assertEquals; 19 import static org.junit.jupiter.api.Assertions.assertThrows; 20 import static org.junit.jupiter.api.Assertions.assertTrue; 20 21 21 22 import java.io.BufferedReader; … … 34 35 import java.util.stream.Collectors; 35 36 36 import org.junit. Before;37 import org.junit. Rule;38 import org.junit. Test;37 import org.junit.jupiter.api.BeforeEach; 38 import org.junit.jupiter.api.Test; 39 import org.junit.jupiter.api.Timeout; 39 40 import org.openstreetmap.josm.TestUtils; 40 41 import org.openstreetmap.josm.data.Version; 41 42 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 42 import org.openstreetmap.josm.testutils.JOSMTestRules; 43 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 44 import org.openstreetmap.josm.testutils.annotations.BasicWiremock; 45 import org.openstreetmap.josm.testutils.annotations.HTTP; 43 46 import org.openstreetmap.josm.tools.HttpClient.Response; 44 47 45 import com.github.tomakehurst.wiremock. core.WireMockConfiguration;48 import com.github.tomakehurst.wiremock.WireMockServer; 46 49 import com.github.tomakehurst.wiremock.http.HttpHeader; 47 50 import com.github.tomakehurst.wiremock.http.HttpHeaders; 48 import com.github.tomakehurst.wiremock.junit.WireMockRule;49 51 import com.github.tomakehurst.wiremock.matching.UrlPattern; 50 51 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;52 52 53 53 /** 54 54 * Tests the {@link HttpClient}. 55 55 */ 56 public class HttpClientTest { 57 58 /** 59 * Setup test 60 */ 61 @Rule 62 @SuppressFBWarnings(value = "URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD") 63 public JOSMTestRules test = new JOSMTestRules().preferences().timeout(15000); 64 56 @HTTP 57 @BasicWiremock 58 @BasicPreferences 59 @Timeout(15) 60 class HttpClientTest { 65 61 /** 66 62 * mocked local http server 67 63 */ 68 @ Rule69 public WireMock Rule localServer = new WireMockRule(WireMockConfiguration.options().dynamicPort());64 @BasicWiremock 65 public WireMockServer localServer; 70 66 71 67 private ProgressMonitor progress; … … 91 87 * Setup test. 92 88 */ 93 @Before 89 @BeforeEach 94 90 public void setUp() { 95 91 localServer.resetAll(); … … 105 101 */ 106 102 @Test 107 publicvoid testConstructorGetterSetter() throws IOException {103 void testConstructorGetterSetter() throws IOException { 108 104 final URL localUrl = url(""); 109 105 final HttpClient client = HttpClient.create(localUrl); … … 127 123 */ 128 124 @Test 129 publicvoid testGet() throws IOException {125 void testGet() throws IOException { 130 126 final UrlPattern pattern = urlEqualTo("/get?foo=bar"); 131 127 localServer.stubFor(get(pattern).willReturn(aResponse().withStatusMessage("OK") … … 151 147 */ 152 148 @Test 153 publicvoid testHeaders() throws IOException {149 void testHeaders() throws IOException { 154 150 final UrlPattern pattern = urlEqualTo("/headers"); 155 151 localServer.stubFor(get(pattern).willReturn(aResponse())); … … 166 162 */ 167 163 @Test 168 publicvoid testFetchUtf8Content() throws IOException {164 void testFetchUtf8Content() throws IOException { 169 165 localServer.stubFor(get(urlEqualTo("/encoding/utf8")) 170 166 .willReturn(aResponse().withBody("∀x∈ℝ: UTF-8 encoded sample plain-text file"))); … … 181 177 */ 182 178 @Test 183 publicvoid testPost() throws IOException {179 void testPost() throws IOException { 184 180 final UrlPattern pattern = urlEqualTo("/post"); 185 181 localServer.stubFor(post(pattern).willReturn(aResponse())); … … 200 196 */ 201 197 @Test 202 publicvoid testPostZero() throws IOException {198 void testPostZero() throws IOException { 203 199 final UrlPattern pattern = urlEqualTo("/post"); 204 200 localServer.stubFor(post(pattern).willReturn(aResponse())); … … 215 211 216 212 @Test 217 publicvoid testRelativeRedirects() throws IOException {213 void testRelativeRedirects() throws IOException { 218 214 mockRedirects(false, 3); 219 215 final Response response = connect("/relative-redirect/3"); … … 223 219 224 220 @Test 225 publicvoid testAbsoluteRedirects() throws IOException {221 void testAbsoluteRedirects() throws IOException { 226 222 mockRedirects(true, 3); 227 223 final Response response = connect("/absolute-redirect/3"); … … 234 230 * @throws IOException if an I/O error occurs 235 231 */ 236 @Test (expected = IOException.class)237 publicvoid testTooMuchRedirects() throws IOException {232 @Test 233 void testTooMuchRedirects() throws IOException { 238 234 mockRedirects(false, 3); 239 HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2).connect(progress);235 assertThrows(IOException.class, () -> HttpClient.create(url("/relative-redirect/3")).setMaxRedirects(2).connect(progress)); 240 236 } 241 237 … … 245 241 */ 246 242 @Test 247 publicvoid testHttp418() throws IOException {243 void testHttp418() throws IOException { 248 244 // https://tools.ietf.org/html/rfc2324 249 245 final Response response = doTestHttp(418, "I'm a teapot!", "I'm a teapot!", … … 257 253 */ 258 254 @Test 259 publicvoid testHttp401() throws IOException {255 void testHttp401() throws IOException { 260 256 // https://tools.ietf.org/html/rfc2324 261 257 doTestHttp(401, "UNAUTHORIZED", null); … … 267 263 */ 268 264 @Test 269 publicvoid testHttp402() throws IOException {265 void testHttp402() throws IOException { 270 266 // https://tools.ietf.org/html/rfc2324 271 267 doTestHttp(402, "PAYMENT REQUIRED", "Fuck you, pay me!"); … … 277 273 */ 278 274 @Test 279 publicvoid testHttp403() throws IOException {275 void testHttp403() throws IOException { 280 276 // https://tools.ietf.org/html/rfc2324 281 277 doTestHttp(403, "FORBIDDEN", null); … … 287 283 */ 288 284 @Test 289 publicvoid testHttp404() throws IOException {285 void testHttp404() throws IOException { 290 286 // https://tools.ietf.org/html/rfc2324 291 287 doTestHttp(404, "NOT FOUND", null); … … 297 293 */ 298 294 @Test 299 publicvoid testHttp500() throws IOException {295 void testHttp500() throws IOException { 300 296 // https://tools.ietf.org/html/rfc2324 301 297 doTestHttp(500, "INTERNAL SERVER ERROR", null); … … 307 303 */ 308 304 @Test 309 publicvoid testRequestInTime() throws IOException {305 void testRequestInTime() throws IOException { 310 306 mockDelay(1); 311 307 final Response response = HttpClient.create(url("/delay/1")).setReadTimeout(2000).connect(progress); … … 317 313 * @throws IOException always 318 314 */ 319 @Test (expected = IOException.class)320 publicvoid testTakesTooLong() throws IOException {315 @Test 316 void testTakesTooLong() throws IOException { 321 317 mockDelay(1); 322 HttpClient.create(url("/delay/1")).setReadTimeout(500).connect(progress);318 assertThrows(IOException.class, () -> HttpClient.create(url("/delay/1")).setReadTimeout(500).connect(progress)); 323 319 } 324 320 … … 328 324 */ 329 325 @Test 330 publicvoid testGzip() throws IOException {326 void testGzip() throws IOException { 331 327 localServer.stubFor(get(urlEqualTo("/gzip")).willReturn(aResponse().withBody("foo"))); 332 328 final Response response = connect("/gzip"); … … 341 337 */ 342 338 @Test 343 publicvoid testOpenUrlGzip() throws IOException {339 void testOpenUrlGzip() throws IOException { 344 340 final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.gz"); 345 341 final byte[] gpx = Files.readAllBytes(path); … … 361 357 */ 362 358 @Test 363 publicvoid testOpenUrlBzip() throws IOException {359 void testOpenUrlBzip() throws IOException { 364 360 final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2"); 365 361 final byte[] gpx = Files.readAllBytes(path); … … 381 377 */ 382 378 @Test 383 publicvoid testOpenUrlBzipAccordingToContentDisposition() throws IOException {379 void testOpenUrlBzipAccordingToContentDisposition() throws IOException { 384 380 final Path path = Paths.get(TestUtils.getTestDataRoot(), "tracks/tracks.gpx.bz2"); 385 381 final byte[] gpx = Files.readAllBytes(path); … … 402 398 */ 403 399 @Test 404 publicvoid testTomcatErrorMessage() {400 void testTomcatErrorMessage() { 405 401 Matcher m = HttpClient.getTomcatErrorMatcher( 406 402 "<html><head><title>Apache Tomcat/DGFiP - Rapport d''erreur</title><style><!--"+
Note:
See TracChangeset
for help on using the changeset viewer.