Thid is my mapping from my controller class , now I want to write unit test case for the same
@GetMapping(value = "/tokenSearch/{id}/{name}/{values}/{data_name}", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getValuesfromToken(
throws ClientProtocolException, IOException, ParseException {
ResponseEntity<String> data = elasticService.getData();
return data;
}
this is what I was trying but its asking for castargument for Result matcher, getting error , can someone pls help me with this
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc
public class ElasticCaseTests extends Mockito {
@Autowired
private MockMvc mockMvc;
@Test
public void testGetValuesfromToken() throws Exception {
String contentAsString = mockMvc.perform(get("/tokenSearch/1/PRODUCT/PRODUCT/189")).andExpect(status().isOk())
.andExpect(jsonPath("$.id", is("1"))).andExpect(jsonPath("$.name", is("product")))
.andExpect(jsonPath("$.values", is("product")))
.andExpect(jsonPath("$.searching_word", is("189"))).andExpect(status().isOk()).andReturn().getResponse()
.getContentAsString();
}
java.lang.AssertionError: No value at JSON path "$.id"' , can someone help me with this