@Test public void testUploadFile() throws Exception { MockMultipartFile mockJpegImageFile = new MockMultipartFile("file", "this is an image.jpeg", "image/jpeg", "image content".getBytes()); MockMultipartFile mockPdfDocumentFile = new MockMultipartFile("file", "lease_agreement.pdf", "application/pdf", "pdf content".getBytes()); when(storageService.save(Arrays.asList(mockJpegImageFile, mockPdfDocumentFile), MODULE, TAG, TENANT_ID)) .thenReturn(Arrays.asList("fileStoreId1", "fileStoreId2")); mockMvc.perform( fileUpload("/v1/files") .file(mockJpegImageFile) .file(mockPdfDocumentFile) .param("module", MODULE) .param("tag", TAG) .param("tenantId", TENANT_ID)) .andExpect(status().isCreated()) .andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)) .andExpect(content().json(getStorageResponse())); verify(storageService) .save(Arrays.asList(mockJpegImageFile, mockPdfDocumentFile), MODULE, TAG, TENANT_ID); }
private StorageResponse getStorageResponse(List<String> fileStorageIds, String tenantId) { List<File> files = new ArrayList<>(); for (String fileStorageId : fileStorageIds) { File f = new File(fileStorageId, tenantId); files.add(f); } return new StorageResponse(files); }
StorageController { private StorageResponse getStorageResponse(List<String> fileStorageIds, String tenantId) { List<File> files = new ArrayList<>(); for (String fileStorageId : fileStorageIds) { File f = new File(fileStorageId, tenantId); files.add(f); } return new StorageResponse(files); } }
StorageController { private StorageResponse getStorageResponse(List<String> fileStorageIds, String tenantId) { List<File> files = new ArrayList<>(); for (String fileStorageId : fileStorageIds) { File f = new File(fileStorageId, tenantId); files.add(f); } return new StorageResponse(files); } StorageController(StorageService storageService, ResponseFactory responseFactory); }
StorageController { private StorageResponse getStorageResponse(List<String> fileStorageIds, String tenantId) { List<File> files = new ArrayList<>(); for (String fileStorageId : fileStorageIds) { File f = new File(fileStorageId, tenantId); files.add(f); } return new StorageResponse(files); } StorageController(StorageService storageService, ResponseFactory responseFactory); @GetMapping("/id") @ResponseBody ResponseEntity<Resource> getFile(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("fileStoreId") String fileStoreId); @GetMapping("/metadata") @ResponseBody ResponseEntity<org.egov.filestore.domain.model.Resource> getMetaData(
			@RequestParam(value = "tenantId") String tenantId, @RequestParam("fileStoreId") String fileStoreId); @GetMapping(value = "/tag", produces = APPLICATION_JSON_UTF8_VALUE) @ResponseBody GetFilesByTagResponse getUrlListByTag(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("tag") String tag); @PostMapping(produces = APPLICATION_JSON_UTF8_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody StorageResponse storeFiles(@RequestParam("file") List<MultipartFile> files,
			@RequestParam(value = "tenantId") String tenantId,
			@RequestParam(value = "module", required = true) String module,
			@RequestParam(value = "tag", required = false) String tag); @GetMapping("/url") @ResponseBody ResponseEntity<Map<String, String>> getUrls(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("fileStoreIds") List<String> fileStoreIds); }
StorageController { private StorageResponse getStorageResponse(List<String> fileStorageIds, String tenantId) { List<File> files = new ArrayList<>(); for (String fileStorageId : fileStorageIds) { File f = new File(fileStorageId, tenantId); files.add(f); } return new StorageResponse(files); } StorageController(StorageService storageService, ResponseFactory responseFactory); @GetMapping("/id") @ResponseBody ResponseEntity<Resource> getFile(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("fileStoreId") String fileStoreId); @GetMapping("/metadata") @ResponseBody ResponseEntity<org.egov.filestore.domain.model.Resource> getMetaData(
			@RequestParam(value = "tenantId") String tenantId, @RequestParam("fileStoreId") String fileStoreId); @GetMapping(value = "/tag", produces = APPLICATION_JSON_UTF8_VALUE) @ResponseBody GetFilesByTagResponse getUrlListByTag(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("tag") String tag); @PostMapping(produces = APPLICATION_JSON_UTF8_VALUE) @ResponseStatus(HttpStatus.CREATED) @ResponseBody StorageResponse storeFiles(@RequestParam("file") List<MultipartFile> files,
			@RequestParam(value = "tenantId") String tenantId,
			@RequestParam(value = "module", required = true) String module,
			@RequestParam(value = "tag", required = false) String tag); @GetMapping("/url") @ResponseBody ResponseEntity<Map<String, String>> getUrls(@RequestParam(value = "tenantId") String tenantId,
			@RequestParam("fileStoreIds") List<String> fileStoreIds);  }