DeploymentRestApi extends ApiBase implements DeploymentApi { @Override public ResourceList<Deployment> listAll() throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); ResourceList<Deployment> resourceList = getDeploymentResourceList(getBasePath()); deploymentResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getDeploymentResourceList(resourceList.getNextPageLink()); deploymentResourceList.getItems().addAll(resourceList.getItems()); } return deploymentResourceList; } DeploymentRestApi(RestClient restClient); @Override String getBasePath(); @Override ResourceList<Deployment> listAll(); @Override void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback); @Override Task pauseSystem(String deploymentId); @Override void pauseSystemAsync(final String deploymentId, final FutureCallback<Task> responseCallback); @Override Task resumeSystem(String deploymentId); @Override void resumeSystemAsync(final String deploymentId, final FutureCallback<Task> responseCallback); @Override ResourceList<Vm> getAllDeploymentVms(final String deploymentId); @Override void getAllDeploymentVmsAsync(String deploymentId, final FutureCallback<ResourceList<Vm>> responseCallback);  }
@Test public void testListAll() throws IOException { Deployment deployment = getNewDeployment(); ResourceList<Deployment> deploymentResourceList = new ResourceList<>(Arrays.asList(deployment)); ObjectMapper mapper = new ObjectMapper(); String serializedResponse = mapper.writeValueAsString(deploymentResourceList); setupMocks(serializedResponse, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentRestApi(restClient); ResourceList<Deployment> response = deploymentApi.listAll(); assertEquals(response.getItems().size(), deploymentResourceList.getItems().size()); assertTrue(response.getItems().containsAll(deploymentResourceList.getItems())); }
@Test public void testListAllForPagination() throws IOException { Deployment deployment = getNewDeployment(); Deployment deploymentNextPage = getNewDeployment(); String nextPageLink = "nextPageLink"; ResourceList<Deployment> deploymentResourceList = new ResourceList<>(Arrays.asList(deployment), nextPageLink, null); ResourceList<Deployment> deploymentResourceListNextPage = new ResourceList<>(Arrays.asList(deploymentNextPage)); ObjectMapper mapper = new ObjectMapper(); String serializedResponse = mapper.writeValueAsString(deploymentResourceList); String serializedResponseNextPage = mapper.writeValueAsString(deploymentResourceListNextPage); setupMocksForPagination(serializedResponse, serializedResponseNextPage, nextPageLink, HttpStatus.SC_OK); DeploymentApi deploymentApi = new DeploymentRestApi(restClient); ResourceList<Deployment> response = deploymentApi.listAll(); assertEquals(response.getItems().size(), deploymentResourceList.getItems().size() + deploymentResourceListNextPage.getItems().size()); assertTrue(response.getItems().containsAll(deploymentResourceList.getItems())); assertTrue(response.getItems().containsAll(deploymentResourceListNextPage.getItems())); }