@Test public void testGetVmDetailsForPagination() throws IOException { Vm vm1 = new Vm(); vm1.setId("vm1-testId"); vm1.setName("vm1"); Vm vm2 = new Vm(); vm2.setId("vm2-testId"); vm2.setName("vm2"); Vm vm3 = new Vm(); vm2.setId("vm3-testId"); vm2.setName("vm3"); String nextPageLink = "nextPageLink"; ResourceList<Vm> vmSummaryList = new ResourceList<>(Arrays.asList(vm1, vm2), nextPageLink, null); ResourceList<Vm> vmSummaryListNextPage = new ResourceList<>(Arrays.asList(vm3)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(vmSummaryList); String serializedTaskNextPage = mapper.writeValueAsString(vmSummaryListNextPage); setupMocksForPagination(serializedTask, serializedTaskNextPage, nextPageLink, HttpStatus.SC_OK); ProjectApi projectApi = new ProjectRestApi(restClient); ResourceList<Vm> response = projectApi.getVmDetailsInProject("foo"); assertEquals(response.getItems().size(), vmSummaryList.getItems().size() + vmSummaryListNextPage.getItems().size()); assertTrue(response.getItems().containsAll(vmSummaryList.getItems())); assertTrue(response.getItems().containsAll(vmSummaryListNextPage.getItems())); }
@Override public ResourceList<Vm> getVmDetailsInProject(String projectId) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), projectId); ResourceList<Vm> vmResourceList = new ResourceList<>(); ResourceList<Vm> resourceList = getVmResourceList(path); vmResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getVmResourceList(resourceList.getNextPageLink()); vmResourceList.getItems().addAll(resourceList.getItems()); } return vmResourceList; }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Vm> getVmDetailsInProject(String projectId) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), projectId); ResourceList<Vm> vmResourceList = new ResourceList<>(); ResourceList<Vm> resourceList = getVmResourceList(path); vmResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getVmResourceList(resourceList.getNextPageLink()); vmResourceList.getItems().addAll(resourceList.getItems()); } return vmResourceList; } }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Vm> getVmDetailsInProject(String projectId) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), projectId); ResourceList<Vm> vmResourceList = new ResourceList<>(); ResourceList<Vm> resourceList = getVmResourceList(path); vmResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getVmResourceList(resourceList.getNextPageLink()); vmResourceList.getItems().addAll(resourceList.getItems()); } return vmResourceList; } ProjectRestApi(RestClient restClient); }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Vm> getVmDetailsInProject(String projectId) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), projectId); ResourceList<Vm> vmResourceList = new ResourceList<>(); ResourceList<Vm> resourceList = getVmResourceList(path); vmResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getVmResourceList(resourceList.getNextPageLink()); vmResourceList.getItems().addAll(resourceList.getItems()); } return vmResourceList; } 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<Vm> getVmDetailsInProject(String projectId) throws IOException { String path = String.format("%s/%s/vms", getBasePath(), projectId); ResourceList<Vm> vmResourceList = new ResourceList<>(); ResourceList<Vm> resourceList = getVmResourceList(path); vmResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getVmResourceList(resourceList.getNextPageLink()); vmResourceList.getItems().addAll(resourceList.getItems()); } return vmResourceList; } 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);  }