@Test public void testDiskTasksForPagination() throws IOException { Task task1 = new Task(); task1.setId("task1"); Task task2 = new Task(); task2.setId("task2"); Task task3 = new Task(); task3.setId("task3"); Task task4 = new Task(); task4.setId("task4"); String nextPageLink = "nextPageLink"; ResourceList<Task> taskResourceList = new ResourceList<>(Arrays.asList(task1, task2), nextPageLink, null); ResourceList<Task> taskResourceListNextPage = new ResourceList<>(Arrays.asList(task3, task4)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(taskResourceList); String serializedTaskNextPage = mapper.writeValueAsString(taskResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); DisksApi disksApi = new DisksRestApi(restClient); ResourceList<Task> response = disksApi.getTasksForDisk("foo"); assertEquals(response.getItems().size(), taskResourceList.getItems().size() + taskResourceListNextPage.getItems() .size()); assertTrue(response.getItems().containsAll(taskResourceList.getItems())); assertTrue(response.getItems().containsAll(taskResourceListNextPage.getItems())); }
@Override public ResourceList<Task> getTasksForDisk(String diskId) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); ResourceList<Task> resourceList = getTaskResourceList(path); taskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTaskResourceList(resourceList.getNextPageLink()); taskResourceList.getItems().addAll(resourceList.getItems()); } return taskResourceList; }
DisksRestApi extends ApiBase implements DisksApi { @Override public ResourceList<Task> getTasksForDisk(String diskId) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); ResourceList<Task> resourceList = getTaskResourceList(path); taskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTaskResourceList(resourceList.getNextPageLink()); taskResourceList.getItems().addAll(resourceList.getItems()); } return taskResourceList; } }
DisksRestApi extends ApiBase implements DisksApi { @Override public ResourceList<Task> getTasksForDisk(String diskId) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); ResourceList<Task> resourceList = getTaskResourceList(path); taskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTaskResourceList(resourceList.getNextPageLink()); taskResourceList.getItems().addAll(resourceList.getItems()); } return taskResourceList; } DisksRestApi(RestClient restClient); }
DisksRestApi extends ApiBase implements DisksApi { @Override public ResourceList<Task> getTasksForDisk(String diskId) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); ResourceList<Task> resourceList = getTaskResourceList(path); taskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTaskResourceList(resourceList.getNextPageLink()); taskResourceList.getItems().addAll(resourceList.getItems()); } return taskResourceList; } DisksRestApi(RestClient restClient); @Override String getBasePath(); @Override PersistentDisk getDisk(String diskId); @Override void getDiskAsync(final String diskId, final FutureCallback<PersistentDisk> responseCallback); @Override ResourceList<Task> getTasksForDisk(String diskId); @Override void getTasksForDiskAsync(final String diskId, final FutureCallback<ResourceList<Task>> responseCallback); @Override Task delete(String diskId); @Override void deleteAsync(final String diskId, final FutureCallback<Task> responseCallback); }
DisksRestApi extends ApiBase implements DisksApi { @Override public ResourceList<Task> getTasksForDisk(String diskId) throws IOException { String path = String.format("%s/%s/tasks", getBasePath(), diskId); ResourceList<Task> taskResourceList = new ResourceList<>(); ResourceList<Task> resourceList = getTaskResourceList(path); taskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTaskResourceList(resourceList.getNextPageLink()); taskResourceList.getItems().addAll(resourceList.getItems()); } return taskResourceList; } DisksRestApi(RestClient restClient); @Override String getBasePath(); @Override PersistentDisk getDisk(String diskId); @Override void getDiskAsync(final String diskId, final FutureCallback<PersistentDisk> responseCallback); @Override ResourceList<Task> getTasksForDisk(String diskId); @Override void getTasksForDiskAsync(final String diskId, final FutureCallback<ResourceList<Task>> responseCallback); @Override Task delete(String diskId); @Override void deleteAsync(final String diskId, final FutureCallback<Task> responseCallback);  }