I am writing SpringMVC3.2 unit test and I imported classes:
import static org.hamcrest.Matchers.containsString;
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.*;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup;
this.mockMvc.perform(post("/maps.do").accept(MediaType.APPLICATION_JSON)
.param("mobileno", "111111")
.param("fromdate", "22-02-2013").param("fromtime", "07:37")
.param("todate", "22-02-2013").param("totime", "08:17")
.andDo(print())
.andExpect(status().isOk())
.andExpect(content().mimeType(MediaType.APPLICATION_JSON)
.andExpect(jsonPath("$.name").value("Lee"));
But print() and mimeType() still are not resolved. I have been searching but I could not find correct answer.
Thanks.
EDITED I tried to
import static org.springframework.test.web.server.result.MockMvcResultHandlers.print;
but it could not be resolved. What library am I missing and dependency do I add? Above is misspell and below is correct.
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
We create the test data by using a test data builder class. Configure our mock object to return the created test data when its findAll() method is invoked.
MockMvc provides support for Spring MVC testing. It encapsulates all web application beans and makes them available for testing. We'll initialize the mockMvc object in the @BeforeEach annotated method, so that we don't have to initialize it inside every test.
The MockMvcBuilders. standaloneSetup() allows to register one or more controllers without the need to use the full WebApplicationContext .
public static DefaultMockMvcBuilder webAppContextSetup(WebApplicationContext context) Build a MockMvc instance using the given, fully initialized (i.e., refreshed) WebApplicationContext . The DispatcherServlet will use the context to discover Spring MVC infrastructure and application controllers in it.
org.springframework.test.web.servlet.result.MockMvcResultHandlers
Comes from spring-test-3.2.3.RELEASE.jar in my workspace
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With