Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mockmvc put method is not working spring

I am writing test cases for my spring restful services. We have a put service in the controller, the syntax is as follows

@RequestMapping(value="/update", method=RequestMethod.PUT)
public @ResponseBody List<PaidUpResponse> updateStatus(
       @RequestBody @Valid PaidUpRequest paidUpRequest,
       HttpServletRequest request, HttpServletResponse response) {
}

to write test case, I used the following method

mockMvc.perform(put("/update").contentType(UnitTestUtil.APPLICATION_JSON_UTF8)
            .content(UnitTestUtil.convertObjectToJsonBytes(request)))
            .andExpect(status().isOk());

but it is giving compilation error, saying "The method put(String) is undefined". could you suggest me how to test put method?

like image 210
Suja C Avatar asked Aug 16 '15 15:08

Suja C


1 Answers

You have to import the appropriate dependency:

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;

or

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
like image 65
Evil Toad Avatar answered Nov 02 '22 13:11

Evil Toad