Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public String Login() {
- // login url
- String loginURL = baseURL+"/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login Name";
- // set headers
- HttpHeaders headers = new HttpHeaders();
- headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
- // create the request with headers
- HttpEntity<String> request = new HttpEntity<String>(headers);
- // get a new rest Template
- RestTemplate restTemplate = new RestTemplate();
- // call the url
- HttpEntity<String> response = restTemplate.exchange(loginURL, HttpMethod.POST, request, String.class);
- HttpHeaders headerResponse = response.getHeaders();
- // get the cookie
- cookie = headerResponse.getFirst(HttpHeaders.SET_COOKIE);
- return cookie;
- }
- @Test
- public void TestLoginShouldReturnCookie1() {
- stubFor(post(urlEqualTo(myURL+"/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name"))
- .willReturn(aResponse().withStatus(200))
- .withCookie("COOKIE", containing(REMEMBER_ME)));
- String cookie = loginService.Login();
- assertEquals(REMEMBER_ME, cookie);
- }
- 14:27:10.488 [qtp878991463-70] ERROR WireMock - Request was not matched:
- {
- "url" : "/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
- "absoluteUrl" : "http://localhost:8089/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
- "method" : "POST",
- "clientIp" : "127.0.0.1",
- "headers" : {
- "User-Agent" : "Java/1.8.0_101",
- "Connection" : "keep-alive",
- "Host" : "localhost:8089",
- "Accept" : "text/plain, application/json, application/*+json, */*",
- "Content-Length" : "0",
- "Content-Type" : "application/x-www-form-urlencoded"
- },
- "cookies" : { },
- "browserProxyRequest" : false,
- "loggedDate" : 1516544830458,
- "bodyAsBase64" : "",
- "body" : "",
- "loggedDateString" : "2018-01-21T14:27:10Z"
- }
- Closest match:
- {
- "url" : "http://localhost:8089/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
- "method" : "POST",
- "cookies" : {
- "COOKIE" : {
- "contains" :
- "FNROTlvZz09Onp0RmwwRnFqbHd2RXNFOFZiTWNaa"
- }
- }
- }
Add Comment
Please, Sign In to add comment