Mockmvc put method is not working spring

13,094

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.*;
Share:
13,094
Suja C
Author by

Suja C

Updated on June 07, 2022

Comments

  • Suja C
    Suja C almost 2 years

    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?

  • Suja C
    Suja C over 8 years
    Thank you so much Evil Toad, it is working. thanks alot.