GetSnapshotContentsTaskRunner extends AbstractSnapshotTaskRunner { protected String buildBridgeURL(GetSnapshotContentsTaskParameters taskParams) { int pageNumber = taskParams.getPageNumber(); if (pageNumber < SnapshotConstants.DEFAULT_CONTENT_PAGE_NUMBER) { pageNumber = SnapshotConstants.DEFAULT_CONTENT_PAGE_NUMBER; } int pageSize = taskParams.getPageSize(); if (pageSize < SnapshotConstants.MIN_CONTENT_PAGE_SIZE || pageSize > SnapshotConstants.MAX_CONTENT_PAGE_SIZE) { pageSize = SnapshotConstants.MAX_CONTENT_PAGE_SIZE; } String snapshotId = taskParams.getSnapshotId(); String prefix = taskParams.getPrefix(); String prefixParam = "&prefix=" + (prefix != null ? prefix : ""); return MessageFormat.format( "{0}/snapshot/{1}/content?page={2}&pageSize={3}{4}", buildBridgeBaseURL(), snapshotId, String.valueOf(pageNumber), String.valueOf(pageSize), prefixParam); } GetSnapshotContentsTaskRunner(String bridgeAppHost,
                                         String bridgeAppPort,
                                         String bridgeAppUser,
                                         String bridgeAppPass); @Override String getName(); @Override String performTask(String taskParameters);  }
@Test public void testBuildSnapshotURL() { replayMocks(); GetSnapshotContentsTaskParameters taskParams = new GetSnapshotContentsTaskParameters(); taskParams.setSnapshotId(snapshotId); taskParams.setPageNumber(pageNumber); taskParams.setPageSize(pageSize); taskParams.setPrefix(prefix); String url = taskRunner.buildBridgeURL(taskParams); String expectedUrl = "http: "/bridge/snapshot/" + snapshotId + "/content?page=" + pageNumber + "&pageSize=" + pageSize + "&prefix=" + prefix; assertEquals(expectedUrl, url); taskParams = new GetSnapshotContentsTaskParameters(); taskParams.setSnapshotId(snapshotId); taskParams.setPageNumber(-500); taskParams.setPageSize(100000000); taskParams.setPrefix(null); url = taskRunner.buildBridgeURL(taskParams); expectedUrl = "http: "/bridge/snapshot/" + snapshotId + "/content?page=0&pageSize=1000&prefix="; assertEquals(expectedUrl, url); }