|
17 | 17 |
|
18 | 18 | package org.openqa.selenium.remote.codec.w3c;
|
19 | 19 |
|
| 20 | +import static java.net.HttpURLConnection.HTTP_BAD_GATEWAY; |
| 21 | +import static java.net.HttpURLConnection.HTTP_GATEWAY_TIMEOUT; |
20 | 22 | import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
|
21 | 23 | import static java.net.HttpURLConnection.HTTP_OK;
|
22 | 24 | import static java.nio.charset.StandardCharsets.UTF_8;
|
@@ -58,6 +60,56 @@ public void noErrorNoCry() {
|
58 | 60 | assertThat(decoded.getValue()).isEqualTo("cheese");
|
59 | 61 | }
|
60 | 62 |
|
| 63 | + @Test |
| 64 | + public void shouldBeAbleToHandleGatewayTimeoutError() { |
| 65 | + String responseString = "<html>\r\n" + |
| 66 | + "<body>\r\n" + |
| 67 | + "<h1>504 Gateway Time-out</h1>\r\n" + |
| 68 | + "The server didn't respond in time.\r\n" + |
| 69 | + "</body>\r\n" + |
| 70 | + "</html>"; |
| 71 | + |
| 72 | + byte[] contents = responseString.getBytes(UTF_8); |
| 73 | + |
| 74 | + HttpResponse response = new HttpResponse(); |
| 75 | + response.setStatus(HTTP_GATEWAY_TIMEOUT); |
| 76 | + response.addHeader("Server", "nginx"); |
| 77 | + response.addHeader("Content-Type", "text/html"); |
| 78 | + response.addHeader("Content-Length", String.valueOf(contents.length)); |
| 79 | + response.setContent(bytes(contents)); |
| 80 | + |
| 81 | + Response decoded = new W3CHttpResponseCodec().decode(response); |
| 82 | + |
| 83 | + assertThat(decoded.getStatus().intValue()).isEqualTo(ErrorCodes.UNHANDLED_ERROR); |
| 84 | + assertThat(decoded.getValue()).isEqualTo(responseString); |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + @Test |
| 89 | + public void shouldBeAbleToHandleBadGatewayError() { |
| 90 | + String responseString = "<html>\r\n" + |
| 91 | + "<head><title>502 Bad Gateway</title></head>\r\n" + |
| 92 | + "<body>\r\n" + |
| 93 | + "<center><h1>502 Bad Gateway</h1></center>\r\n" + |
| 94 | + "<hr><center>nginx</center>\r\n" + |
| 95 | + "</body>\r\n" + |
| 96 | + "</html>"; |
| 97 | + |
| 98 | + byte[] contents = responseString.getBytes(UTF_8); |
| 99 | + |
| 100 | + HttpResponse response = new HttpResponse(); |
| 101 | + response.setStatus(HTTP_BAD_GATEWAY); |
| 102 | + response.addHeader("Server", "nginx"); |
| 103 | + response.addHeader("Content-Type", "text/html"); |
| 104 | + response.addHeader("Content-Length", String.valueOf(contents.length)); |
| 105 | + response.setContent(bytes(contents)); |
| 106 | + |
| 107 | + Response decoded = new W3CHttpResponseCodec().decode(response); |
| 108 | + |
| 109 | + assertThat(decoded.getStatus().intValue()).isEqualTo(ErrorCodes.UNHANDLED_ERROR); |
| 110 | + assertThat(decoded.getValue()).isEqualTo(responseString); |
| 111 | + } |
| 112 | + |
61 | 113 | @Test
|
62 | 114 | public void decodingAnErrorWithoutAStacktraceIsDecodedProperlyForNonCompliantImplementations() {
|
63 | 115 | Map<String, Object> error = new HashMap<>();
|
|
0 commit comments