0
私は**ルートURLにすべてのHTML5のルートをリダイレクトし、単一の方法では、次のコントローラを持っています。コントローラメソッドがリクエストを特定のURLに転送するかどうかをテストする方法?私の春のブートアプリケーションで
@Controller
public class RedirectController {
@RequestMapping(value = "/**/{path:[^\\.]*}")
public String redirect() {
return "forward:/";
}
}
私は適切に期待どおりに動作することをテストする必要がありますどのように?
動作しませんMockMvcResultMatchers
クラスのcontent()
メソッドを呼び出す:
@Test
public void givenPathWithoutDotShouldReturnString() throws Exception {
this.mockMvc.perform(get("/somePath"))
.andExpect(content().string("forward:/"));
}
>>> java.lang.AssertionError: Response content
>>> Expected :forward:/
>>> Actual :
は**私は
this Spring tutorialを次からこのソリューションを知りました。方法で(
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL =/
Redirected URL = null
Cookies = []
ここ
私は春には、単純な文字列の結果としてreturn "forward:/";
を扱わないことに気づいたが、URL転送:私はmockMvc
クラスのandDo(print())
を呼ばれると