diff options
Diffstat (limited to 'vid-automation/src')
-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; + } + } |