simonjenga/CompanyRestService

ControllerTest class should be updated to make use of MockMvc

Closed this issue · 0 comments

The class org.springframework.test.web.servlet.MockMvc is the Main entry point for server-side Spring MVC test support.

static imports:
MockMvcBuilders.*, MockMvcRequestBuilders.*, MockMvcResultMatchers.*

WebApplicationContext wac = ...;

MockMvc mockMvc = webAppContextSetup(wac).build();

mockMvc.perform(get("/form"))
    .andExpect(status().isOk())
    .andExpect(content().mimeType("text/html"))
    .andExpect(forwardedUrl("/WEB-INF/layouts/main.jsp"));

Our test class CompanyControllerTest should be updated and refined to make use of this testing functionality that has more capabilities.

This will also help to eliminate the problem of persisting test data into the production database as opposed to the test database while using org.springframework.web.client.RestTemplate; in the current implementation of the tests:

ResponseEntity<String> response = this.template.getForEntity(this.baseURL + "/companies", String.class);

ResponseEntity<String> response = this.template.getForEntity(this.baseURL + "/company/" + savedCompany.getId(), String.class);