Guest User

Untitled

a guest
Jan 21st, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. public String Login() {
  2. // login url
  3. String loginURL = baseURL+"/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login Name";
  4. // set headers
  5. HttpHeaders headers = new HttpHeaders();
  6. headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
  7. // create the request with headers
  8. HttpEntity<String> request = new HttpEntity<String>(headers);
  9. // get a new rest Template
  10. RestTemplate restTemplate = new RestTemplate();
  11. // call the url
  12. HttpEntity<String> response = restTemplate.exchange(loginURL, HttpMethod.POST, request, String.class);
  13. HttpHeaders headerResponse = response.getHeaders();
  14. // get the cookie
  15. cookie = headerResponse.getFirst(HttpHeaders.SET_COOKIE);
  16. return cookie;
  17. }
  18.  
  19. @Test
  20. public void TestLoginShouldReturnCookie1() {
  21. stubFor(post(urlEqualTo(myURL+"/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name"))
  22. .willReturn(aResponse().withStatus(200))
  23. .withCookie("COOKIE", containing(REMEMBER_ME)));
  24.  
  25. String cookie = loginService.Login();
  26.  
  27. assertEquals(REMEMBER_ME, cookie);
  28.  
  29. }
  30.  
  31. 14:27:10.488 [qtp878991463-70] ERROR WireMock - Request was not matched:
  32.  
  33. {
  34. "url" : "/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
  35. "absoluteUrl" : "http://localhost:8089/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
  36. "method" : "POST",
  37. "clientIp" : "127.0.0.1",
  38. "headers" : {
  39. "User-Agent" : "Java/1.8.0_101",
  40. "Connection" : "keep-alive",
  41. "Host" : "localhost:8089",
  42. "Accept" : "text/plain, application/json, application/*+json, */*",
  43. "Content-Length" : "0",
  44. "Content-Type" : "application/x-www-form-urlencoded"
  45. },
  46. "cookies" : { },
  47. "browserProxyRequest" : false,
  48. "loggedDate" : 1516544830458,
  49. "bodyAsBase64" : "",
  50. "body" : "",
  51. "loggedDateString" : "2018-01-21T14:27:10Z"
  52. }
  53. Closest match:
  54. {
  55. "url" : "http://localhost:8089/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login%20Name",
  56. "method" : "POST",
  57. "cookies" : {
  58. "COOKIE" : {
  59. "contains" :
  60. "FNROTlvZz09Onp0RmwwRnFqbHd2RXNFOFZiTWNaa"
  61. }
  62. }
  63. }
Add Comment
Please, Sign In to add comment