@Test public void deleteTempFile() throws Exception { EcmFile ecmFile = new EcmFile(); ecmFile.setFileId(104L); ecmFile.setFileName("simple.json"); ArrayList<EcmFile> ecmFileList = new ArrayList<>(); ecmFileList.add(ecmFile); expect(mockAuthentication.getName()).andReturn("user").times(2); expect(mockFileFolderServiceImpl.deleteTempFile(ecmFile.getFileName())).andReturn(true); replayAll(); MvcResult result = mockMvc.perform( post("/api/v1/plugin/ecm/temp/delete") .param("fileName", ecmFile.getFileName()) .principal(mockAuthentication) .contentType(MediaType.APPLICATION_JSON)) .andReturn(); verifyAll(); assertEquals(HttpStatus.OK.value(), result.getResponse().getStatus()); log.info("Results: " + result.getResponse().getContentAsString()); ObjectMapper objectMapper = new ObjectMapper(); DeleteFileResult deleteFileResult = objectMapper.readValue(result.getResponse().getContentAsString(), DeleteFileResult.class); assertTrue(deleteFileResult.isSuccess()); }
@RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request, Authentication authentication, HttpSession session) { log.debug("Deleting temp file {} by {}", fileName, authentication.getName()); DeleteFileResult deleteFileResult = new DeleteFileResult(); boolean fileDeleted = getFileFolderService().deleteTempFile(fileName); if (!fileDeleted) { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(false); log.warn("The temp file {} was not deleted. The server file system will require manual cleanup.", fileName); } else { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(true); } return deleteFileResult; }
UploadTempFilesAPIController { @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request, Authentication authentication, HttpSession session) { log.debug("Deleting temp file {} by {}", fileName, authentication.getName()); DeleteFileResult deleteFileResult = new DeleteFileResult(); boolean fileDeleted = getFileFolderService().deleteTempFile(fileName); if (!fileDeleted) { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(false); log.warn("The temp file {} was not deleted. The server file system will require manual cleanup.", fileName); } else { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(true); } return deleteFileResult; } }
UploadTempFilesAPIController { @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request, Authentication authentication, HttpSession session) { log.debug("Deleting temp file {} by {}", fileName, authentication.getName()); DeleteFileResult deleteFileResult = new DeleteFileResult(); boolean fileDeleted = getFileFolderService().deleteTempFile(fileName); if (!fileDeleted) { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(false); log.warn("The temp file {} was not deleted. The server file system will require manual cleanup.", fileName); } else { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(true); } return deleteFileResult; }  }
UploadTempFilesAPIController { @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request, Authentication authentication, HttpSession session) { log.debug("Deleting temp file {} by {}", fileName, authentication.getName()); DeleteFileResult deleteFileResult = new DeleteFileResult(); boolean fileDeleted = getFileFolderService().deleteTempFile(fileName); if (!fileDeleted) { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(false); log.warn("The temp file {} was not deleted. The server file system will require manual cleanup.", fileName); } else { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(true); } return deleteFileResult; }  @RequestMapping(value = "upload", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody List<EcmFile> uploadTempFiles(HttpServletRequest request, Authentication authentication, HttpSession session); @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request,
            Authentication authentication, HttpSession session); EcmFileService getFileFolderService(); void setFileFolderService(EcmFileService fileFolderService); }
UploadTempFilesAPIController { @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody public DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request, Authentication authentication, HttpSession session) { log.debug("Deleting temp file {} by {}", fileName, authentication.getName()); DeleteFileResult deleteFileResult = new DeleteFileResult(); boolean fileDeleted = getFileFolderService().deleteTempFile(fileName); if (!fileDeleted) { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(false); log.warn("The temp file {} was not deleted. The server file system will require manual cleanup.", fileName); } else { deleteFileResult.setDeletedFileName(fileName); deleteFileResult.setSuccess(true); } return deleteFileResult; }  @RequestMapping(value = "upload", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody List<EcmFile> uploadTempFiles(HttpServletRequest request, Authentication authentication, HttpSession session); @RequestMapping(value = "delete", method = RequestMethod.POST, produces = { MediaType.APPLICATION_JSON_VALUE }) @ResponseBody DeleteFileResult deleteTempFile(@RequestParam(value = "fileName") String fileName, HttpServletRequest request,
            Authentication authentication, HttpSession session); EcmFileService getFileFolderService(); void setFileFolderService(EcmFileService fileFolderService);  }