I have the below Velocity config for both test and main in my spring mvc app:
@Bean
public VelocityConfigurer velocityConfig(){
VelocityConfigurer velocityConfig = new VelocityConfigurer();
velocityConfig.setResourceLoaderPath("/WEB-INF/views/");
return velocityConfig;
}
@Bean
public VelocityLayoutViewResolver viewResolver(){
VelocityLayoutViewResolver viewResolver = new VelocityLayoutViewResolver();
viewResolver.setCache(true);
viewResolver.setLayoutUrl("layout.vm");
viewResolver.setPrefix("");
viewResolver.setSuffix(".vm");
return viewResolver;
}
It works correctly when I deploy the WAR and all my MockMvcResultMatchers
in test except for `forwardedUrl which returns null:
@Test
public void testHome() throws Exception{
mockMvc.perform(MockMvcRequestBuilders.get("/"))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.view().name("index"))
.andExpect(MockMvcResultMatchers.forwardedUrl("/WEB-INF/views/layout.vm"))
.andExpect(MockMvcResultMatchers.model().attribute("myData", Matchers.is(Matchers.not(Matchers.empty()))));
The appropriate Controller under test has the following beginning:
@RequestMapping({"/index", "/"})
public ModelAndView home(){
The stacktrace begins:
java.lang.AssertionError: Forwarded URL expected:</WEB-INF/views/layout.vm> but was:<null>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89)
at org.springframework.test.web.servlet.result.MockMvcResultMatchers$1.match(MockMvcResultMatchers.java:93)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
at com...
Why is the forwarded URL incorrect? Is it an issue with the MockMvc or the velocity setup?