|
37 | 37 | import java.io.IOException; |
38 | 38 | import java.util.Collections; |
39 | 39 | import java.util.HashMap; |
| 40 | +import java.util.List; |
40 | 41 | import java.util.Map; |
41 | 42 | import org.junit.Before; |
42 | 43 | import org.junit.Test; |
@@ -199,4 +200,30 @@ public void testValidationExceptionWithInvalidJsonResponse() throws IOException |
199 | 200 | assertNull(e.getError()); |
200 | 201 | } |
201 | 202 | } |
| 203 | + |
| 204 | + @Test |
| 205 | + public void testRequestException401WithWWWAuthenticateHeader() |
| 206 | + throws IOException, HTTPClientException { |
| 207 | + try { |
| 208 | + Map<String, List<String>> responseHeaders = new HashMap<>(); |
| 209 | + responseHeaders.put("WWW-Authenticate", Collections.singletonList("abcd-1234-xywx-5678")); |
| 210 | + |
| 211 | + when(clientInterfaceMock.request( |
| 212 | + "", "request", null, false, null, ApiConstants.HttpMethod.POST, null)) |
| 213 | + .thenThrow(new HTTPClientException("Unauthorized", 401, responseHeaders, null)); |
| 214 | + |
| 215 | + Resource resource = new Resource(serviceMock, "", null); |
| 216 | + resource.request("request"); |
| 217 | + |
| 218 | + fail("Expected exception"); |
| 219 | + } catch (ApiException e) { |
| 220 | + assertEquals(401, e.getStatusCode()); |
| 221 | + assertNotNull(e.getResponseHeaders()); |
| 222 | + assertTrue(e.getResponseHeaders().containsKey("WWW-Authenticate")); |
| 223 | + assertEquals( |
| 224 | + Collections.singletonList("abcd-1234-xywx-5678"), |
| 225 | + e.getResponseHeaders().get("WWW-Authenticate")); |
| 226 | + assertNull(e.getError()); |
| 227 | + } |
| 228 | + } |
202 | 229 | } |
0 commit comments