SnapshotController { @RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId}/history", method = RequestMethod.GET) public ModelAndView getHistory(@PathVariable("storeId") String storeId, @PathVariable("snapshotId") String snapshotId, @RequestParam(value = "page", required = false) Integer page, @RequestParam(value = "attachment", required = false, defaultValue = "false") Boolean attachment, HttpServletResponse response) { try { SnapshotTaskClient taskClient = getTaskClient(storeId); if (attachment) { StringBuffer contentDisposition = new StringBuffer(); contentDisposition.append("attachment;"); contentDisposition.append("filename=\""); contentDisposition.append(snapshotId + ".history.json"); contentDisposition.append("\""); response.setHeader("Content-Disposition", contentDisposition.toString()); } if (page == null) { page = 0; } streamSnapshotHistory(page, storeId, snapshotId, taskClient, response); return null; } catch (Exception e) { log.error(e.getMessage(), e); throw new RuntimeException(e); } } @Autowired(required = true)  SnapshotController(@Qualifier("contentStoreManager") ContentStoreManager contentStoreManager,
                              @Qualifier("userDetailsSvc") DuracloudUserDetailsService userDetailsService,
                              SnapshotTaskClientManager snapshotTaskClientManager); @RequestMapping(value = "/spaces/snapshot", method = RequestMethod.POST) @ResponseBody String create(HttpServletRequest request,
                         HttpServletResponse response,
                         @RequestParam String spaceId,
                         @RequestParam String storeId,
                         @RequestParam String description); @RequestMapping(value = "/spaces/snapshot", method = RequestMethod.GET) ModelAndView get(@RequestParam String storeId,
                            @RequestParam String spaceId); @RequestMapping(value = "/spaces/snapshots/{storeId}", method = RequestMethod.GET) @ResponseBody String getSnapshotList(@PathVariable("storeId") String storeId); @RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId:.+}", method = RequestMethod.GET) @ResponseBody String getSnapshot(@PathVariable("storeId") String storeId,
                              @PathVariable("snapshotId") String snapshotId); @RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId}/history", method = RequestMethod.GET) ModelAndView getHistory(@PathVariable("storeId") String storeId,
                                   @PathVariable("snapshotId") String snapshotId,
                                   @RequestParam(value = "page", required = false) Integer page,
                                   @RequestParam(value = "attachment", required = false, defaultValue = "false")
                                       Boolean attachment,
                                   HttpServletResponse response); @RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId}/content", method = RequestMethod.GET) ModelAndView getContent(@PathVariable("storeId") String storeId,
                                   @PathVariable("snapshotId") String snapshotId,
                                   @RequestParam(value = "page", required = false) Integer page,
                                   @RequestParam(value = "prefix", required = false) String prefix); @RequestMapping(value = "/spaces/snapshots/{storeId}/{snapshotId}/restore-space-id", method = RequestMethod.GET) @ResponseBody String restoreSpaceId(HttpServletRequest request,
                                 @PathVariable("storeId") String storeId,
                                 @PathVariable("snapshotId") String snapshotId); @RequestMapping(value = "/spaces/restores/{storeId}/by-snapshot/{snapshotId:.+}", method = RequestMethod.GET) @ResponseBody String getRestore(@PathVariable("storeId") String storeId,
                             @PathVariable("snapshotId") String snapshotId); @RequestMapping(value = "/spaces/restores/{storeId}/{restoreId:.+}", method = RequestMethod.GET) @ResponseBody String getRestoreByRestoreId(@PathVariable("storeId") String storeId,
                                        @PathVariable("restoreId") String restoreId); @RequestMapping(value = "/spaces/restores", method = RequestMethod.POST) @ResponseBody String restore(HttpServletRequest request,
                          @RequestParam String storeId,
                          @RequestParam String snapshotId); @RequestMapping(value = "/spaces/restores/request", method = RequestMethod.POST) @ResponseBody String requestRestore(HttpServletRequest request,
                                 @RequestParam String storeId,
                                 @RequestParam String snapshotId);  }
@Test public void testGetHistory() throws Exception { Integer page = 0; Date historyDate = new Date(); long totalCount = 201; List<SnapshotHistoryItem> items = new ArrayList<>(); for (int i = 0; i < totalCount - 1; i++) { SnapshotHistoryItem item = new SnapshotHistoryItem(); item.setHistory("history" + i); item.setHistoryDate(new Date(historyDate.getTime() + i)); items.add(item); } GetSnapshotHistoryTaskResult result = new GetSnapshotHistoryTaskResult(); result.setHistoryItems(items); result.setTotalCount(totalCount); setupGetTaskClient(storeId); EasyMock.expect(taskClient.getSnapshotHistory(snapshotId, page, 200)) .andReturn(result); HttpServletResponse response = createMock(HttpServletResponse.class); File file = File.createTempFile("test", "json"); file.deleteOnExit(); PrintWriter writer = new PrintWriter(new FileOutputStream(file)); EasyMock.expect(response.getWriter()).andReturn(writer); replayAll(); SnapshotController controller = createController(); ModelAndView mav = controller.getHistory(storeId, snapshotId, page, false, response); Assert.assertNull(mav); JsonFactory factory = new JsonFactory(); JsonParser jParser = factory.createJsonParser(new FileInputStream(file)); int topLevelPropCount = 0; while (jParser.nextToken() != JsonToken.END_OBJECT) { String fieldname = jParser.getCurrentName(); if ("storeId".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals(storeId, jParser.getText()); } else if ("snapshotId".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals(snapshotId, jParser.getText()); } else if ("page".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals(page.intValue(), jParser.getIntValue()); } else if ("nextPage".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals(page.intValue() + 1, jParser.getIntValue()); } else if ("totalCount".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals(totalCount, jParser.getLongValue()); } else if ("historyItems".equals(fieldname)) { jParser.nextToken(); int i = 0; while (jParser.nextToken() != JsonToken.END_ARRAY) { while (jParser.nextToken() != JsonToken.END_OBJECT) { String itemFieldName = jParser.getCurrentName(); if ("historyDate".equals(itemFieldName)) { jParser.nextToken(); Assert.assertEquals(historyDate.getTime() + i, jParser.getLongValue()); } else if ("history".equals(fieldname)) { jParser.nextToken(); Assert.assertEquals("history" + i, jParser.getText()); } } i++; } } topLevelPropCount++; } Assert.assertEquals(6, topLevelPropCount - 1); jParser.close(); }