Resources under WEB-INF location can also be used with spring-test-mvc, this way:
xmlConfigSetup("/WEB-INF/spring/webmvc-config.xml","classpath:/org/bk/lmt/web/contextcontrollertest.xml") .configureWebAppRootDir("src/main/webapp", false).build() .perform(post("/contexts").param("name", "context1")) .andExpect(status().isOk()) .andExpect(view().name("redirect:/contexts")); xmlConfigSetup("/WEB-INF/spring/webmvc-config.xml", "classpath:/org/bk/lmt/web/contextcontrollertest.xml") .configureWebAppRootDir("src/main/webapp", false).build() .perform(get("/contexts")) .andExpect(status().isOk()) .andExpect(view().name("contexts/list"));
the Web Application path can be specified as shown in the highlighted lines above. This works because the unit test current working directory is typically the root of the project, and if the structure is a typical maven project structure then the web root will be "src/main/webapp" folder which can be resolved from the root of the project.
No comments:
Post a Comment