Writing the Test method

The complete Test method is shown in the following code:

    @Test 
public void basicTest() throws Exception {
this.mockMvc
.perform(
get("/welcome-model-map")
.accept(MediaType.parseMediaType
("application/html;charset=UTF-8")))
.andExpect(model().attribute("name", "XYZ"))
.andExpect(view().name("welcome-model-map"));
}

A number of important elements to note include the following:

  • get("/welcome-model-map"): This executes a GET request to the specified URL.
  • model().attribute("name", "XYZ"): ResultMatcher checks whether the model contains the specified attribute, name, with the specified value, XYZ.
  • view().name("welcome-model-map"): ResultMatcher checks whether the View name returned is as specified.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset