samedi 14 novembre 2015

How to test confguration of static resources in Spring MVC test framework

I am using Spring MVC test framework for Integrated testing of my Spring Controllers. Below is the code for my Controller and its Test currently using.

@RequestMapping("/login")
public ModelAndView goLogin(){
    ModelAndView mv = new ModelAndView("login");
    mv.addObject("loginForm", new loginForm());
    return mv;
}

@Test
public void goLoginPage() throws Exception{
    this.mockMvc.perform(get("/login")).andExpect(status().isOk())
    .andExpect(forwardedUrl("/WEB-INF/template/default.jsp"))
    .andExpect(model().attribute("loginForm", any(loginForm.class)));   
}

I am using Apache Tiles as view framework. Below is the layout configuration code for loginForm page.

<definition name="login" template="/WEB-INF/template/default.jsp">
    <put-attribute name="title" value="Login - Spring Web Testing"></put-attribute>
    <put-attribute name="header" value="/WEB-INF/tile/header.jsp"></put-attribute>
    <put-attribute name="body" value="/WEB-INF/tile/login_body.jsp"></put-attribute>
    <put-list-attribute name="javascripts">
        <add-attribute value="/static/script/jquery-2.1.4.js"></add-attribute>
    </put-list-attribute>
    <put-list-attribute name="stylesheets">
        <add-attribute value="/static/style/general.css" />
    </put-list-attribute>
</definition>

How can I test if Javascript and stylesheet files in Apache Tiles configuration are correctly configured? And expect an error if file(s) are not found.

Aucun commentaire:

Enregistrer un commentaire