0

I'm trying to test using Spring MVC, but even when using example from MockMvc:

.andExpect(status().isOk())
.andExpect(content().mimeType("text/html"))

Using MockHttpServletRequestBuilder:

MockHttpServletRequestBuilder mockHttpServletRequestBuilder = MockMvcRequestBuilders
        .post("/servlet/api/update")

I'm getting 2 exceptions:

The method andExpect(ResultMatcher) is undefined for the type MockHttpServletRequestBuilder

The method mimeType(String) is undefined for the type ContentResultMatchers

I'm using the import from example (below), but still seems that I'm missing other imports

 import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
 import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
 import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
Ori Marko
  • 56,308
  • 23
  • 131
  • 233

1 Answers1

1

Since the complete code is not posted it's difficult to guess what would be the mistake. I post working code here, that might help.

         mockMvc.perform(post(path)
                    .contentType(APPLICATION_JSON)
                    .accept(APPLICATION_JSON)
                    .header(AUTHORIZATION, BEARER_AUTHORIZATION)
                    .content(mapper.writeValueAsString(webRequest)))
            .andExpect(status().isCreated())
Rauf Aghayev
  • 300
  • 1
  • 12
  • `status().isCreated()` produce same error `The method andExpect(ResultMatcher) is undefined` for the type MockHttpServletRequestBuilder – Ori Marko Feb 26 '19 at 07:33
  • My code in previous open question https://stackoverflow.com/questions/54867824/how-to-check-json-response-in-spring-mvc-test – Ori Marko Feb 26 '19 at 07:46