Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JsonPathRequestMatchers to ResultMatcher using MockMVC

Tags:

I am testing a todo controller using MockMVC:

            mockMvc.perform(MockMvcRequestBuilders.get("/toDos/")
                    .with(user("user").password("password").roles("ADMIN"))
                    .content("{ \"saved_date\": \"2010-01-01\"}")
                    .accept(MediaType.APPLICATION_JSON_VALUE))
                    .andExpect((ResultMatcher) jsonPath("$.id").doesNotExist())
                    .andExpect(status().isOk())
                    .andExpect( content().contentType("application/json"));
        }

I keep getting this error:

java.lang.ClassCastException: org.springframework.test.web.client.match.JsonPathRequestMatchers$5 cannot be cast to org.springframework.test.web.servlet.ResultMatcher

I want to delete the cast to (ResultMatcher) , but don't know how to create a ResultMatcher that tests the presence of Id. Any ideas ?

like image 435
Chayma Atallah Avatar asked Jun 23 '17 10:06

Chayma Atallah


1 Answers

I think you want to use:

org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath

... instead of:

org.springframework.test.web.client.match.MockMvcResultMatchers.jsonPath
like image 137
glytching Avatar answered Sep 25 '22 11:09

glytching