@Test public void testListAllAsync() throws Exception { 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); final CountDownLatch latch = new CountDownLatch(1); deploymentApi.listAllAsync(new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { assertEquals(result.getItems(), deploymentResourceList.getItems()); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
@Override public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() {}); }
DeploymentRestApi extends ApiBase implements DeploymentApi { @Override public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() {}); } }
DeploymentRestApi extends ApiBase implements DeploymentApi { @Override public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() {}); } DeploymentRestApi(RestClient restClient); }
DeploymentRestApi extends ApiBase implements DeploymentApi { @Override public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() {}); } 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); }
DeploymentRestApi extends ApiBase implements DeploymentApi { @Override public void listAllAsync(final FutureCallback<ResourceList<Deployment>> responseCallback) throws IOException { ResourceList<Deployment> deploymentResourceList = new ResourceList<>(); FutureCallback<ResourceList<Deployment>> callback = new FutureCallback<ResourceList<Deployment>>() { @Override public void onSuccess(@Nullable ResourceList<Deployment> result) { if (deploymentResourceList.getItems() == null) { deploymentResourceList.setItems(result.getItems()); } else { deploymentResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Deployment>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(deploymentResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Deployment>>() {}); } 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);  }