は、ここで私は私の問題を解決する方法は次のとおりです。
@Test
public void authenticateAndRedirect() {
Result result = route(new Http.RequestBuilder()
.method(POST)
.bodyForm(ImmutableMap.of("email", "[email protected]", "password", "secret"))
.uri(controllers.routes.ApplicationController.authenticate().url()));
assertEquals(SEE_OTHER, result.status());
}
@Test
public void authenticateAndRedirectJson() throws Exception {
JsonNode jsonNode = (new ObjectMapper()).readTree("{ \"email\": \"[email protected]\", \"password\": \"secret\" }");
Http.RequestBuilder request = new Http.RequestBuilder()
.method("POST")
.bodyJson(jsonNode)
.uri(controllers.routes.ApplicationController.authenticate().url());
Result result = route(request);
assertEquals(SEE_OTHER, result.status());
}
のことを、認証されたsの私は「彼いったん別のページにユーザーをリダイレクトするM」があることに注意してくださいなぜ私はコードを期待しているのですか?SEE_OTHER=303
public Result authenticate() {
Form<Login> form = formFactory.form(Login.class).bindFromRequest();
if (form.hasErrors()) {
return badRequest(login.render(form));
}
Optional<User> maybeUser = User.findByEmail(form.get().email);
if (maybeUser.isPresent()) {
session("email", maybeUser.get().email);
return redirect(routes.ApplicationController.index());
}
return badRequest(login.render(form));
}