Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // metoda
- public UploadFileResponse uploadFile(@PathVariable String id, @RequestParam("file") MultipartFile file) {
- DbFile dbFile = userService.addFileByUserId(id, file);
- String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath()
- .path(String.format("%s/%s/files/%s/download", usersRoute, id, dbFile.getId()))
- .toUriString();
- return new UploadFileResponse(dbFile.getFileName(), fileDownloadUri, file.getContentType(), file.getSize());
- }
- // test
- @Test
- public void givenUser_whenUploadFile_then200StatusAndUploadFileResponse() throws Exception {
- mvc.perform(fileUpload(String.format("%s/%s/files", basePath, user.getId()))
- .file(new MockMultipartFile("test", "test".getBytes())).with(httpBasic("user", "test")))
- .andExpect(status().isOk())
- .andExpect(jsonPath("fileName", is("test")))
- .andExpect(jsonPath("size", is(4L)))
- .andExpect(jsonPath("userId", is(user.getId())));
- }
Advertisement
Add Comment
Please, Sign In to add comment