Here I want to write a
test for following controller method, on executing method of the testclass I'm getting an error as required part formData is not present, I've tried finding a solution for testing an object having 'RequestPart' annotation but no luck, can someone please take a look and suggest a way to write
JUNIT test for @RequestPart
[code]
@PostMapping("/user")
public ResponseEntity<UserDTO> createUser(@RequestPart(value = "files", required= false) MultipartFile[] files,
@RequestPart("formData") UserDTO userDTO) throws URISyntaxException {
userService.save(userDTO, files);
//....
}
Inside TestClass-
@BeforeEach
public void initTest()
{
user = createEntity(em);// inside this method I've set all the properties of userDTO and 'user' is a reference variable to User class
}
public void createUser() throws Exception {
UserDTO userDTO = userMapper.toDto(user);
mockMvc.
perform(post("/api/user")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(userDTO)))
.andExpect(status().isCreated());
}