ログイン jsp フォームと spring security xml 構成は次のようになります。
<spring:url value="/j_spring_security_check" var="login" />
<form action="${login}" method="POST">
<fieldset>
<legend>Login</legend>
<input type="text" name="j_username" id="username" placeholder="Usename"/>
<input type="text" name="j_password" id="password" placeholder="Password"/>
<input type="submit" value="Login" />
</fieldset>
</form>
...
<security:form-login login-page="/public/authentication/login.htm"
login-processing-url="/j_spring_security_check"
default-target-url="/public/index.htm"
authentication-failure-url="/public/authentication/login.htm?authenticationNok=1"/>
フォーム送信のテストは次のとおりです。
@Test
public void testLoginPostController() throws Exception {
Account account = new AccountBuilder("test", "test", "test@gmail.com", Address.FAKE_EMPTY_ADDRESS4TESTS)
.build();
this.mockMvc.perform(post("/j_spring_security_check").param("j_username", account.getUsername()).param("j_password", "test"))
.andDo(print())
.andExpect(status().isMovedTemporarily())
.andExpect(view().name("redirect:/public/index.htm"));
}
しかし、私は得ています:java.lang.AssertionError: Status expected:<302> but was:<404>
ブラウザでログインページを開くと、生成されたフォームが次のようになっていることがわかります。
<form action="/SpringMvcExample/j_spring_security_check" method="POST">
OK、テストを次のように変更しようとしました:
this.mockMvc.perform(post("/SpringMvcExample/j_spring_security_check").param("j_username", account.getUsername()).param("j_password", "test"))
しかし、同じ結果が得られました。同時に、ブラウザでログインフォームを送信すると、テストで予想されるように、public/index.htm
ページにリダイレクトされます。
私は何を間違っていますか?