@Test void testCreateFile() throws ExecutionException, InterruptedException { when(userPermissionEvaluator.hasPermission(new EntityTypeIdentity(FILE_META), ADD_DATA)) .thenReturn(true); FileMeta fileMeta = mock(FileMeta.class); String fileId = "MyId"; String filename = "MyFilename"; String contentType = "MyContentType"; Long size = 123L; when(fileMeta.getId()).thenReturn(fileId); when(fileMeta.getFilename()).thenReturn(filename); when(fileMeta.getContentType()).thenReturn(contentType); when(fileMeta.getSize()).thenReturn(size); HttpServletRequest httpServletRequest = mock(HttpServletRequest.class); when(filesApiService.upload(httpServletRequest)) .thenReturn(CompletableFuture.completedFuture(fileMeta)); ResponseEntity<FileResponse> fileResponseResponseEntity = filesApiController.createFile(httpServletRequest).get(); FileResponse expectedFileResponse = FileResponse.builder() .setId(fileId) .setFilename(filename) .setContentType(contentType) .setSize(size) .build(); assertEquals(expectedFileResponse, fileResponseResponseEntity.getBody()); assertEquals(CREATED, fileResponseResponseEntity.getStatusCode()); assertNotNull(fileResponseResponseEntity.getHeaders().getLocation()); }
@ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) public CompletableFuture<ResponseEntity<FileResponse>> createFile( HttpServletRequest httpServletRequest) { validateCreatePermission(); return filesService .upload(httpServletRequest) .thenApply(fileMeta -> this.toFileResponseEntity(fileMeta, httpServletRequest)); }
FilesController extends ApiController { @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) public CompletableFuture<ResponseEntity<FileResponse>> createFile( HttpServletRequest httpServletRequest) { validateCreatePermission(); return filesService .upload(httpServletRequest) .thenApply(fileMeta -> this.toFileResponseEntity(fileMeta, httpServletRequest)); } }
FilesController extends ApiController { @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) public CompletableFuture<ResponseEntity<FileResponse>> createFile( HttpServletRequest httpServletRequest) { validateCreatePermission(); return filesService .upload(httpServletRequest) .thenApply(fileMeta -> this.toFileResponseEntity(fileMeta, httpServletRequest)); } FilesController(FilesService filesService, UserPermissionEvaluator userPermissionEvaluator); }
FilesController extends ApiController { @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) public CompletableFuture<ResponseEntity<FileResponse>> createFile( HttpServletRequest httpServletRequest) { validateCreatePermission(); return filesService .upload(httpServletRequest) .thenApply(fileMeta -> this.toFileResponseEntity(fileMeta, httpServletRequest)); } FilesController(FilesService filesService, UserPermissionEvaluator userPermissionEvaluator); @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) CompletableFuture<ResponseEntity<FileResponse>> createFile(
      HttpServletRequest httpServletRequest); @PostMapping(consumes = {"application/x-www-form-urlencoded", "multipart/form-data"}) @ResponseStatus(BAD_REQUEST) CompletableFuture<ResponseEntity<FileResponse>> createFileFromForm(
      HttpServletRequest httpServletRequest); @ApiOperation("Retrieve file metadata (see documentation)") @GetMapping(value = "/{fileId}") FileResponse readFile(@PathVariable("fileId") String fileId); @ApiOperation("Download file (see documentation)") @GetMapping(value = "/{fileId}", params = "alt=media") ResponseEntity<StreamingResponseBody> downloadFile(@PathVariable("fileId") String fileId); @ApiOperation("Delete file (see documentation)") @DeleteMapping(value = "/{fileId}") @ResponseStatus(NO_CONTENT) void deleteFile(@PathVariable("fileId") String fileId); }
FilesController extends ApiController { @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) public CompletableFuture<ResponseEntity<FileResponse>> createFile( HttpServletRequest httpServletRequest) { validateCreatePermission(); return filesService .upload(httpServletRequest) .thenApply(fileMeta -> this.toFileResponseEntity(fileMeta, httpServletRequest)); } FilesController(FilesService filesService, UserPermissionEvaluator userPermissionEvaluator); @ApiOperation("Upload file (see documentation)") @PostMapping @ResponseStatus(CREATED) CompletableFuture<ResponseEntity<FileResponse>> createFile(
      HttpServletRequest httpServletRequest); @PostMapping(consumes = {"application/x-www-form-urlencoded", "multipart/form-data"}) @ResponseStatus(BAD_REQUEST) CompletableFuture<ResponseEntity<FileResponse>> createFileFromForm(
      HttpServletRequest httpServletRequest); @ApiOperation("Retrieve file metadata (see documentation)") @GetMapping(value = "/{fileId}") FileResponse readFile(@PathVariable("fileId") String fileId); @ApiOperation("Download file (see documentation)") @GetMapping(value = "/{fileId}", params = "alt=media") ResponseEntity<StreamingResponseBody> downloadFile(@PathVariable("fileId") String fileId); @ApiOperation("Delete file (see documentation)") @DeleteMapping(value = "/{fileId}") @ResponseStatus(NO_CONTENT) void deleteFile(@PathVariable("fileId") String fileId);  }