1
@Controller
 @PostMapping("/hello/{studentName}")
    public ResponseEntity<Void> method1(

    @RequestMapping(value = "/upload/{studentName}", method = RequestMethod.POST)
    @ResponseBody
    public String saveAuto(
            @PathVariable(value = "name") String name,` `
            @RequestParam("file") MultipartFile myFile) {
          }
    } 

Hi, I am new to unit test. can anyone please help me for writing test case using mockmvcbuilderrequest.. I tried this but getting 404 mockMvc.perform(MockMvcRequestBuilders.multipart("/hello/{zoneName}","com.example") .file(file).accept(MediaType.MULTIPART_FORM_DATA_VALUE))

Anu Shree
  • 11
  • 1

1 Answers1

0

You have 2 options.

  1. Change the rest path and put: "/hello/{studentName}", in this way the test will work as you have explained.

  2. Leave the rest path "/upload/{studentName}" and change the uri in the test from "/hello/{studentName}" to "/upload/{studentName}".

I leave the way to execute the test, with the correction.

mockMvc.perform(
    MockMvcRequestBuilders.multipart("/upload/{studentName}","Anu Shree") 
        .file(file)
        .accept(MediaType.MULTIPART_FORM_DATA_VALUE)
)

I hope it helps

jGomez
  • 111
  • 3