@Test public void testGetPersistentDisksForPagination() throws IOException { PersistentDisk persistentDisk1 = new PersistentDisk(); persistentDisk1.setId("persistentDisk1"); PersistentDisk persistentDisk2 = new PersistentDisk(); persistentDisk2.setId("persistentDisk2"); PersistentDisk persistentDisk3 = new PersistentDisk(); persistentDisk3.setId("persistentDisk3"); String nextPageLink = "nextPageLink"; ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(Arrays.asList(persistentDisk1, persistentDisk2), nextPageLink, null); ResourceList<PersistentDisk> persistentDiskResourceListNextPage = new ResourceList<>(Arrays.asList(persistentDisk3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(persistentDiskResourceList); String serializedTaskNextPage = mapper.writeValueAsString(persistentDiskResourceListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); ProjectApi projectApi = new ProjectRestApi(restClient); ResourceList<PersistentDisk> response = projectApi.getDisksInProject("foo"); assertEquals(response.getItems().size(), persistentDiskResourceList.getItems().size() + persistentDiskResourceListNextPage.getItems().size()); assertTrue(response.getItems().containsAll(persistentDiskResourceList.getItems())); assertTrue(response.getItems().containsAll(persistentDiskResourceListNextPage.getItems())); }
@Override public ResourceList<PersistentDisk> getDisksInProject(String projectId) throws IOException { String path = String.format("%s/%s/disks", getBasePath(), projectId); ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(); ResourceList<PersistentDisk> resourceList = getPersistentDiskResourceList(path); persistentDiskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getPersistentDiskResourceList(resourceList.getNextPageLink()); persistentDiskResourceList.getItems().addAll(resourceList.getItems()); } return persistentDiskResourceList; }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<PersistentDisk> getDisksInProject(String projectId) throws IOException { String path = String.format("%s/%s/disks", getBasePath(), projectId); ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(); ResourceList<PersistentDisk> resourceList = getPersistentDiskResourceList(path); persistentDiskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getPersistentDiskResourceList(resourceList.getNextPageLink()); persistentDiskResourceList.getItems().addAll(resourceList.getItems()); } return persistentDiskResourceList; } }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<PersistentDisk> getDisksInProject(String projectId) throws IOException { String path = String.format("%s/%s/disks", getBasePath(), projectId); ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(); ResourceList<PersistentDisk> resourceList = getPersistentDiskResourceList(path); persistentDiskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getPersistentDiskResourceList(resourceList.getNextPageLink()); persistentDiskResourceList.getItems().addAll(resourceList.getItems()); } return persistentDiskResourceList; } ProjectRestApi(RestClient restClient); }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<PersistentDisk> getDisksInProject(String projectId) throws IOException { String path = String.format("%s/%s/disks", getBasePath(), projectId); ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(); ResourceList<PersistentDisk> resourceList = getPersistentDiskResourceList(path); persistentDiskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getPersistentDiskResourceList(resourceList.getNextPageLink()); persistentDiskResourceList.getItems().addAll(resourceList.getItems()); } return persistentDiskResourceList; } ProjectRestApi(RestClient restClient); @Override String getBasePath(); @Override Project getProject(String projectId); @Override void getProjectAsync(final String projectId, final FutureCallback<Project> responseCallback); @Override ResourceList<Task> getTasksForProject(String projectId); @Override void getTasksForProjectAsync(final String projectId, final FutureCallback<ResourceList<Task>>
      responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback); @Override Task createDisk(String projectId, DiskCreateSpec diskCreateSpec); @Override void createDiskAsync(final String projectId, final DiskCreateSpec diskCreateSpec, final FutureCallback<Task>
      responseCallback); @Override ResourceList<PersistentDisk> getDisksInProject(String projectId); @Override void getDisksInProjectAsync(final String projectId,
                                     final FutureCallback<ResourceList<PersistentDisk>> responseCallback); @Override Task createVm(String projectId, VmCreateSpec vmCreateSpec); @Override void createVmAsync(final String projectId, final VmCreateSpec vmCreateSpec, final FutureCallback<Task>
      responseCallback); @Override ResourceList<FlavoredCompact> getVmsInProject(String projectId); @Override ResourceList<Vm> getVmDetailsInProject(String projectId); @Override void getVmsInProjectAsync(final String projectId, final FutureCallback<ResourceList<FlavoredCompact>>
      responseCallback); @Override Task createCluster(String projectId, ClusterCreateSpec clusterCreateSpec); @Override void createClusterAsync(final String projectId, final ClusterCreateSpec clusterCreateSpec,
                                 final FutureCallback<Task> responseCallback); @Override ResourceList<Cluster> getClustersInProject(String projectId); @Override void getClustersInProjectAsync(final String projectId, final FutureCallback<ResourceList<Cluster>>
      responseCallback); }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<PersistentDisk> getDisksInProject(String projectId) throws IOException { String path = String.format("%s/%s/disks", getBasePath(), projectId); ResourceList<PersistentDisk> persistentDiskResourceList = new ResourceList<>(); ResourceList<PersistentDisk> resourceList = getPersistentDiskResourceList(path); persistentDiskResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getPersistentDiskResourceList(resourceList.getNextPageLink()); persistentDiskResourceList.getItems().addAll(resourceList.getItems()); } return persistentDiskResourceList; } ProjectRestApi(RestClient restClient); @Override String getBasePath(); @Override Project getProject(String projectId); @Override void getProjectAsync(final String projectId, final FutureCallback<Project> responseCallback); @Override ResourceList<Task> getTasksForProject(String projectId); @Override void getTasksForProjectAsync(final String projectId, final FutureCallback<ResourceList<Task>>
      responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback); @Override Task createDisk(String projectId, DiskCreateSpec diskCreateSpec); @Override void createDiskAsync(final String projectId, final DiskCreateSpec diskCreateSpec, final FutureCallback<Task>
      responseCallback); @Override ResourceList<PersistentDisk> getDisksInProject(String projectId); @Override void getDisksInProjectAsync(final String projectId,
                                     final FutureCallback<ResourceList<PersistentDisk>> responseCallback); @Override Task createVm(String projectId, VmCreateSpec vmCreateSpec); @Override void createVmAsync(final String projectId, final VmCreateSpec vmCreateSpec, final FutureCallback<Task>
      responseCallback); @Override ResourceList<FlavoredCompact> getVmsInProject(String projectId); @Override ResourceList<Vm> getVmDetailsInProject(String projectId); @Override void getVmsInProjectAsync(final String projectId, final FutureCallback<ResourceList<FlavoredCompact>>
      responseCallback); @Override Task createCluster(String projectId, ClusterCreateSpec clusterCreateSpec); @Override void createClusterAsync(final String projectId, final ClusterCreateSpec clusterCreateSpec,
                                 final FutureCallback<Task> responseCallback); @Override ResourceList<Cluster> getClustersInProject(String projectId); @Override void getClustersInProjectAsync(final String projectId, final FutureCallback<ResourceList<Cluster>>
      responseCallback);  }