Changeset 16837 in josm for trunk/test/functional/org
- Timestamp:
- 2020-08-03T20:52:27+02:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/functional/org/openstreetmap/josm/tools/HttpClientTest.java
r16737 r16837 36 36 37 37 /** 38 * Tests the {@link HttpClient} using the webservice <a href="https://httpbin.org/">https://httpbin.org/</a>. 38 * Tests the {@link HttpClient} using the webservice <a href="https://httpbingo.org/">https://httpbingo.org/</a>. 39 39 */ 40 40 public class HttpClientTest { … … 83 83 @Test 84 84 public void testConstructorGetterSetter() throws IOException { 85 final HttpClient client = HttpClient.create(new URL("https://httpbin.org/")); 86 assertThat(client.getURL(), is(new URL("https://httpbin.org/"))); 85 final HttpClient client = HttpClient.create(new URL("https://httpbingo.org/")); 86 assertThat(client.getURL(), is(new URL("https://httpbingo.org/"))); 87 87 assertThat(client.getRequestMethod(), is("GET")); 88 88 assertThat(client.getRequestHeader("Accept"), is("*/*")); … … 104 104 @Test 105 105 public void testGet() throws IOException { 106 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/get?foo=bar")).connect(progress); 106 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/get?foo=bar")).connect(progress); 107 107 assertThat(response.getRequestMethod(), is("GET")); 108 108 assertThat(response.getResponseCode(), is(200)); 109 109 assertThat(response.getResponseMessage(), equalToIgnoringCase("OK")); 110 assertThat(response.getContentType(), is("application/json")); 111 assertThat(response.getHeaderField("Content-Type"), is("application/json")); 112 assertThat(response.getHeaderField("Content-TYPE"), is("application/json")); 113 assertThat(response.getHeaderFields().get("Content-Type"), is(Collections.singletonList("application/json"))); 114 assertThat(response.getHeaderFields().get("Content-TYPE"), is(Collections.singletonList("application/json"))); 110 assertThat(response.getContentType(), is("application/json; encoding=utf-8")); 111 assertThat(response.getHeaderField("Content-Type"), is("application/json; encoding=utf-8")); 112 assertThat(response.getHeaderField("Content-TYPE"), is("application/json; encoding=utf-8")); 113 assertThat(response.getHeaderFields().get("Content-Type"), is(Collections.singletonList("application/json; encoding=utf-8"))); 114 assertThat(response.getHeaderFields().get("Content-TYPE"), is(Collections.singletonList("application/json; encoding=utf-8"))); 115 115 try (InputStream in = response.getContent(); 116 116 JsonReader json = JsonProvider.provider().createReader(in)) { 117 117 final JsonObject root = json.readObject(); 118 assertThat(root.getJsonObject("args").getString( "foo"), is("bar"));119 assertThat(root.getString("url"), is("https://httpbin.org/get?foo=bar")); 118 assertThat(root.getJsonObject("args").getJsonArray("foo").getString(0), is("bar")); 119 assertThat(root.getString("url"), is("https://httpbingo.org/get?foo=bar")); 120 120 assertThat(root.getJsonObject("headers").get("Cache-Control"), nullValue()); 121 121 assertThat(root.getJsonObject("headers").get("Pragma"), nullValue()); … … 129 129 @Test 130 130 public void testHeaders() throws IOException { 131 try (InputStream in = HttpClient.create(new URL("https://httpbin.org/headers")).connect(progress).getContent(); 131 try (InputStream in = HttpClient.create(new URL("https://httpbingo.org/headers")).connect(progress).getContent(); 132 132 JsonReader json = JsonProvider.provider().createReader(in)) { 133 133 final JsonObject headers = json.readObject().getJsonObject("headers"); 134 assertThat(headers.get String("Accept"), is("*/*"));135 assertThat(headers.get String("Accept-Encoding"), is("gzip, deflate"));136 assertThat(headers.get String("User-Agent"), is(Version.getInstance().getFullAgentString()));134 assertThat(headers.getJsonArray("Accept").getString(0), is("*/*")); 135 assertThat(headers.getJsonArray("Accept-Encoding").getString(0), is("gzip, deflate")); 136 assertThat(headers.getJsonArray("User-Agent").getString(0), is(Version.getInstance().getFullAgentString())); 137 137 } 138 138 } … … 144 144 @Test 145 145 public void testUserAgent() throws IOException { 146 try (InputStream in = HttpClient.create(new URL("https://httpbin.org/user-agent")).connect(progress).getContent(); 146 try (InputStream in = HttpClient.create(new URL("https://httpbingo.org/user-agent")).connect(progress).getContent(); 147 147 JsonReader json = JsonProvider.provider().createReader(in)) { 148 148 assertThat(json.readObject().getString("user-agent"), is(Version.getInstance().getFullAgentString())); … … 156 156 @Test 157 157 public void testFetchUtf8Content() throws IOException { 158 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/encoding/utf8")).connect(progress); 158 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/encoding/utf8")).connect(progress); 159 159 assertThat(response.getResponseCode(), is(200)); 160 160 final String content = response.fetchContent(); … … 170 170 public void testPost() throws IOException { 171 171 final String text = "Hello World!\nGeetings from JOSM, the Java OpenStreetMap Editor"; 172 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST") 172 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/post"), "POST") 173 173 .setHeader("Content-Type", "text/plain") 174 174 .setRequestBody(text.getBytes(StandardCharsets.UTF_8)) … … 184 184 @Test 185 185 public void testPostZero() throws IOException { 186 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/post"), "POST") 186 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/post"), "POST") 187 187 .setHeader("Content-Type", "text/plain") 188 188 .setRequestBody("".getBytes(StandardCharsets.UTF_8)) … … 196 196 } 197 197 198 /*@Test198 @Test 199 199 public void testRelativeRedirects() throws IOException { 200 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/relative-redirect/3")).connect(progress); 200 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/relative-redirect/3")).connect(progress); 201 201 assertThat(response.getResponseCode(), is(200)); 202 202 assertThat(response.getContentLength() > 100, is(true)); 203 } */204 205 /*@Test203 } 204 205 @Test 206 206 public void testAbsoluteRedirects() throws IOException { 207 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/absolute-redirect/3")).connect(progress); 207 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/absolute-redirect/3")).connect(progress); 208 208 assertThat(response.getResponseCode(), is(200)); 209 209 assertThat(response.getContentLength() > 100, is(true)); 210 } */210 } 211 211 212 212 /** … … 214 214 * @throws IOException if an I/O error occurs 215 215 */ 216 /*@Test(expected = IOException.class)216 @Test(expected = IOException.class) 217 217 public void testTooMuchRedirects() throws IOException { 218 HttpClient.create(new URL("https://httpbin.org/redirect/3")).setMaxRedirects(2).connect(progress); 219 } */218 HttpClient.create(new URL("https://httpbingo.org/redirect/3")).setMaxRedirects(2).connect(progress); 219 } 220 220 221 221 /** … … 226 226 public void testHttp418() throws IOException { 227 227 // https://tools.ietf.org/html/rfc2324 228 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/418")).connect(progress); 228 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/418")).connect(progress); 229 229 assertThat(response.getResponseCode(), is(418)); 230 final String content = response.fetchContent(); 231 assertThat(content, containsString("-=[ teapot ]=-")); 232 assertThat(captured.getMessage(), containsString("-=[ teapot ]=-")); 230 assertThat(response.getHeaderField("X-More-Info"), is("http://tools.ietf.org/html/rfc2324")); 231 final String content = response.fetchContent(); 232 assertThat(content, containsString("I'm a teapot!")); 233 assertThat(captured.getMessage(), containsString("I'm a teapot!")); 233 234 assertThat(captured.getLevel(), is(Logging.LEVEL_DEBUG)); 234 235 } … … 241 242 public void testHttp401() throws IOException { 242 243 // https://tools.ietf.org/html/rfc2324 243 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/401")).connect(progress); 244 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/401")).connect(progress); 244 245 assertThat(response.getResponseCode(), is(401)); 245 246 assertThat(response.getResponseMessage(), equalToIgnoringCase("UNAUTHORIZED")); … … 257 258 public void testHttp402() throws IOException { 258 259 // https://tools.ietf.org/html/rfc2324 259 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/402")).connect(progress); 260 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/402")).connect(progress); 260 261 assertThat(response.getResponseCode(), is(402)); 261 262 assertThat(response.getResponseMessage(), equalToIgnoringCase("PAYMENT REQUIRED")); … … 273 274 public void testHttp403() throws IOException { 274 275 // https://tools.ietf.org/html/rfc2324 275 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/403")).connect(progress); 276 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/403")).connect(progress); 276 277 assertThat(response.getResponseCode(), is(403)); 277 278 assertThat(response.getResponseMessage(), equalToIgnoringCase("FORBIDDEN")); … … 289 290 public void testHttp404() throws IOException { 290 291 // https://tools.ietf.org/html/rfc2324 291 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/404")).connect(progress); 292 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/404")).connect(progress); 292 293 assertThat(response.getResponseCode(), is(404)); 293 294 assertThat(response.getResponseMessage(), equalToIgnoringCase("NOT FOUND")); … … 305 306 public void testHttp500() throws IOException { 306 307 // https://tools.ietf.org/html/rfc2324 307 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/status/500")).connect(progress); 308 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/status/500")).connect(progress); 308 309 assertThat(response.getResponseCode(), is(500)); 309 310 assertThat(response.getResponseMessage(), equalToIgnoringCase("INTERNAL SERVER ERROR")); … … 320 321 @Test 321 322 public void testRequestInTime() throws IOException { 322 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(2000).connect(progress); 323 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(2000).connect(progress); 323 324 assertThat(response.getResponseCode(), is(200)); 324 325 } … … 330 331 @Test(expected = IOException.class) 331 332 public void testTakesTooLong() throws IOException { 332 HttpClient.create(new URL("https://httpbin.org/delay/1")).setReadTimeout(500).connect(progress); 333 HttpClient.create(new URL("https://httpbingo.org/delay/1")).setReadTimeout(500).connect(progress); 333 334 } 334 335 … … 339 340 @Test 340 341 public void testDeflate() throws IOException { 341 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/deflate")).connect(progress); 342 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/deflate")).connect(progress); 342 343 assertThat(response.getResponseCode(), is(200)); 343 344 try (InputStream in = response.getContent(); … … 353 354 @Test 354 355 public void testGzip() throws IOException { 355 final HttpClient.Response response = HttpClient.create(new URL("https://httpbin.org/gzip")).connect(progress); 356 final HttpClient.Response response = HttpClient.create(new URL("https://httpbingo.org/gzip")).connect(progress); 356 357 assertThat(response.getResponseCode(), is(200)); 357 358 try (InputStream in = response.getContent();
Note:
See TracChangeset
for help on using the changeset viewer.