diff options
author | Ittay Stern <ittay.stern@att.com> | 2020-03-19 12:51:24 +0200 |
---|---|---|
committer | Ittay Stern <ittay.stern@att.com> | 2020-03-19 12:51:24 +0200 |
commit | 058752eb915d0cb30778d19980b6da0fa968d795 (patch) | |
tree | a41fbcc84d49291a08986f9de6abd4f7ae4ce656 | |
parent | 0ed46b431710e216ebb69293e221221380b0183c (diff) |
Tests: Verbose login failures
Issue-ID: VID-647
Change-Id: Iab15ef79a52f3390d25ae3db4367137300411e41
Signed-off-by: Ittay Stern <ittay.stern@att.com>
-rw-r--r-- | vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java index 0117a8a99..ac2291f09 100644 --- a/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java +++ b/vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java @@ -37,10 +37,13 @@ public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInt protected HttpHeaders getCookieAndJsonHttpHeaders(URI uri, UserCredentials userCredentials) { HttpHeaders loginRequestHeaders = new HttpHeaders(); loginRequestHeaders.setContentType(MediaType.APPLICATION_FORM_URLENCODED); + HttpEntity<String> requestEntity = + new HttpEntity<>("loginId=" + userCredentials.getUserId() + "&password=" + userCredentials.getPassword(), loginRequestHeaders); + RestTemplate restTemplate = InsecureHttpsClient.newRestTemplate(); - ResponseEntity<String> loginRes = restTemplate.postForEntity(uri.toASCIIString() + "/login_external.htm", new HttpEntity<>("loginId=" + userCredentials.getUserId() + "&password=" + userCredentials.getPassword(), loginRequestHeaders), String.class); - Assert.assertEquals("Login failed - wrong http status with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), HttpStatus.FOUND, loginRes.getStatusCode()); - Assert.assertNull("Failed to login with user:" + userCredentials.getUserId() + " password:" + userCredentials.getPassword(), loginRes.getBody()); + ResponseEntity<String> loginRes = restTemplate.postForEntity(uri.toASCIIString() + "/login_external.htm", requestEntity, String.class); + Assert.assertEquals("Failed to login " + describeLoginRes(uri, requestEntity, loginRes), HttpStatus.FOUND, loginRes.getStatusCode()); + Assert.assertNull("Failed to login " + describeLoginRes(uri, requestEntity, loginRes), loginRes.getBody()); HttpHeaders loginResponseHeaders = loginRes.getHeaders(); List<String> cookie = loginResponseHeaders.get(HttpHeaders.SET_COOKIE); @@ -51,4 +54,12 @@ public class CookieAndJsonHttpHeadersInterceptor implements ClientHttpRequestInt return headers; } + private String describeLoginRes(URI uri, HttpEntity<String> requestEntity, ResponseEntity<String> loginRes) { + return "" + + "Request was: " + + uri.toASCIIString() + " POST " + requestEntity + + "And response is: " + + loginRes; + } + } |