summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmichai Hemli <amichai.hemli@intl.att.com>2020-03-22 09:54:22 +0000
committerGerrit Code Review <gerrit@onap.org>2020-03-22 09:54:22 +0000
commite059877c392d457f34dc947bd4fd0d3ba19714aa (patch)
tree434724dee005226ed8d6ca0598ff8e51f20fd7ee
parent3f7f2146b06bc9c8b64a00832b06eeafa266ed67 (diff)
parent058752eb915d0cb30778d19980b6da0fa968d795 (diff)
Merge "Tests: Verbose login failures"
-rw-r--r--vid-automation/src/main/java/vid/automation/test/utils/CookieAndJsonHttpHeadersInterceptor.java17
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;
+ }
+
}