Guest User

Untitled

a guest
Sep 10th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. // metoda
  2. public UploadFileResponse uploadFile(@PathVariable String id, @RequestParam("file") MultipartFile file) {
  3.         DbFile dbFile = userService.addFileByUserId(id, file);
  4.  
  5.         String fileDownloadUri = ServletUriComponentsBuilder.fromCurrentContextPath()
  6.                 .path(String.format("%s/%s/files/%s/download", usersRoute, id, dbFile.getId()))
  7.                 .toUriString();
  8.  
  9.         return new UploadFileResponse(dbFile.getFileName(), fileDownloadUri, file.getContentType(), file.getSize());
  10.     }
  11.  
  12. // test
  13.  
  14. @Test
  15.    public void givenUser_whenUploadFile_then200StatusAndUploadFileResponse() throws Exception {
  16.         mvc.perform(fileUpload(String.format("%s/%s/files", basePath, user.getId()))
  17.                 .file(new MockMultipartFile("test", "test".getBytes())).with(httpBasic("user", "test")))
  18.                 .andExpect(status().isOk())
  19.                 .andExpect(jsonPath("fileName", is("test")))
  20.                 .andExpect(jsonPath("size", is(4L)))
  21.                 .andExpect(jsonPath("userId", is(user.getId())));
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment