@Test public void testDownloadSelectedFolderFiles() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); Long rootFolderId = 101L; FileFolderNode file1 = new FileFolderNode(); FileFolderNode file2 = new FileFolderNode(); FileFolderNode rootFolder = new FileFolderNode(); file1.setFolder(false); file1.setObjectId(111L); file2.setFolder(false); file2.setObjectId(222L); rootFolder.setFolder(true); rootFolder.setObjectId(rootFolderId); List<FileFolderNode> selectedFoldersFiles = new ArrayList<>(Arrays.asList(file1, file2, rootFolder)); CompressNode compressNode = new CompressNode(); compressNode.setRootFolderId(rootFolderId); compressNode.setSelectedNodes(selectedFoldersFiles); String fileName = mockZipFile.getPath(); expect(mockedFolderCompressor.compressFolder(isA(CompressNode.class))).andReturn(fileName); replayAll(); MvcResult response = mockMvc.perform( post("/api/v1/service/compressor/download") .contentType(MediaType.APPLICATION_JSON_UTF8_VALUE) .content(objectMapper.writeValueAsString(compressNode)) .accept("application/zip") .session(mockHttpSession)) .andReturn(); verifyAll(); assertEquals(response.getResponse().getStatus(), HttpStatus.OK.value()); assertEquals(response.getResponse().getContentType(), "application/zip"); assertEquals(response.getResponse().getHeader("Content-Disposition"), "attachment; filename=\"acm-101-ROOT.zip\""); }
@RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId) throws AcmFolderException { String fileName = folderCompressor.compressFolder(folderId); return new FolderCompressorResponse(fileName); }
FolderCompressorAPIController { @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId) throws AcmFolderException { String fileName = folderCompressor.compressFolder(folderId); return new FolderCompressorResponse(fileName); } }
FolderCompressorAPIController { @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId) throws AcmFolderException { String fileName = folderCompressor.compressFolder(folderId); return new FolderCompressorResponse(fileName); }  }
FolderCompressorAPIController { @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId) throws AcmFolderException { String fileName = folderCompressor.compressFolder(folderId); return new FolderCompressorResponse(fileName); }  @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId); @RequestMapping(value = "/download/{folderId}", method = RequestMethod.GET) @ResponseBody void getCompressedFolder(@PathVariable(value = "folderId") long folderId, HttpServletResponse response); @RequestMapping(value = "/download", method = RequestMethod.POST) @ResponseBody void getCompressedSelectedFolderAndFiles(@RequestBody CompressNode compressNode, HttpServletResponse response); void downloadCompressedFolder(String filePath, String fileName, HttpServletResponse response); void setFolderCompressor(FolderCompressor folderCompressor); }
FolderCompressorAPIController { @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody public FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId) throws AcmFolderException { String fileName = folderCompressor.compressFolder(folderId); return new FolderCompressorResponse(fileName); }  @RequestMapping(value = "/{folderId}", method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE, MediaType.TEXT_PLAIN_VALUE }) @ResponseBody FolderCompressorResponse compressFolder(@PathVariable(value = "folderId") long folderId); @RequestMapping(value = "/download/{folderId}", method = RequestMethod.GET) @ResponseBody void getCompressedFolder(@PathVariable(value = "folderId") long folderId, HttpServletResponse response); @RequestMapping(value = "/download", method = RequestMethod.POST) @ResponseBody void getCompressedSelectedFolderAndFiles(@RequestBody CompressNode compressNode, HttpServletResponse response); void downloadCompressedFolder(String filePath, String fileName, HttpServletResponse response); void setFolderCompressor(FolderCompressor folderCompressor);  }