我是Wiremock的新手,如果我的登录方法检索到cookie,我正在尝试进行单元测试。
以下是我的登录方式:
?base?
我编写了下面的单元测试来检查在调用登录URL时是否返回了cookie。
public String Login() {
// login url
String loginURL = baseURL+"/Login?username=admin&password=test&_spring_security_remember_me=true&submit=Login Name";
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
// create the request with headers
HttpEntity<String> request = new HttpEntity<String>(headers);
RestTemplate restTemplate = new RestTemplate();
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;
}
当我运行测试时,我收到404错误并出现以下错误:
@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);
}
我该如何纠正这个问题?