@Test public void testGetClusters() throws IOException { Cluster cluster1 = new Cluster(); cluster1.setId("cluster1"); cluster1.setName("cluster1Name"); Cluster cluster2 = new Cluster(); cluster2.setId("cluster2"); cluster2.setName("cluster2Name"); ResourceList<Cluster> clusterList = new ResourceList<>(Arrays.asList(cluster1, cluster2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(clusterList); setupMocks(serializedTask, HttpStatus.SC_OK); ProjectApi projectApi = new ProjectRestApi(restClient); ResourceList<Cluster> response = projectApi.getClustersInProject("foo"); assertEquals(response.getItems().size(), clusterList.getItems().size()); assertTrue(response.getItems().containsAll(clusterList.getItems())); }
@Override public ResourceList<Cluster> getClustersInProject(String projectId) throws IOException { String path = String.format("%s/%s/clusters", getBasePath(), projectId); ResourceList<Cluster> clusterResourceList = new ResourceList<>(); ResourceList<Cluster> resourceList = getClusterResourceList(path); clusterResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getClusterResourceList(resourceList.getNextPageLink()); clusterResourceList.getItems().addAll(resourceList.getItems()); } return clusterResourceList; }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Cluster> getClustersInProject(String projectId) throws IOException { String path = String.format("%s/%s/clusters", getBasePath(), projectId); ResourceList<Cluster> clusterResourceList = new ResourceList<>(); ResourceList<Cluster> resourceList = getClusterResourceList(path); clusterResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getClusterResourceList(resourceList.getNextPageLink()); clusterResourceList.getItems().addAll(resourceList.getItems()); } return clusterResourceList; } }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Cluster> getClustersInProject(String projectId) throws IOException { String path = String.format("%s/%s/clusters", getBasePath(), projectId); ResourceList<Cluster> clusterResourceList = new ResourceList<>(); ResourceList<Cluster> resourceList = getClusterResourceList(path); clusterResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getClusterResourceList(resourceList.getNextPageLink()); clusterResourceList.getItems().addAll(resourceList.getItems()); } return clusterResourceList; } ProjectRestApi(RestClient restClient); }
ProjectRestApi extends ApiBase implements ProjectApi { @Override public ResourceList<Cluster> getClustersInProject(String projectId) throws IOException { String path = String.format("%s/%s/clusters", getBasePath(), projectId); ResourceList<Cluster> clusterResourceList = new ResourceList<>(); ResourceList<Cluster> resourceList = getClusterResourceList(path); clusterResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getClusterResourceList(resourceList.getNextPageLink()); clusterResourceList.getItems().addAll(resourceList.getItems()); } return clusterResourceList; } 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<Cluster> getClustersInProject(String projectId) throws IOException { String path = String.format("%s/%s/clusters", getBasePath(), projectId); ResourceList<Cluster> clusterResourceList = new ResourceList<>(); ResourceList<Cluster> resourceList = getClusterResourceList(path); clusterResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getClusterResourceList(resourceList.getNextPageLink()); clusterResourceList.getItems().addAll(resourceList.getItems()); } return clusterResourceList; } 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);  }