@Test public void testGetAllImagesAsync() throws IOException, InterruptedException { Image image1 = new Image(); image1.setId("image1"); Image image2 = new Image(); image2.setId("image2"); final ResourceList<Image> imageResourceList = new ResourceList<>(Arrays.asList(image1, image2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(imageResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); ImagesApi imagesApi = new ImagesRestApi(this.restClient); final CountDownLatch latch = new CountDownLatch(1); imagesApi.getImagesAsync(new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { assertEquals(result.getItems(), imageResourceList.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 getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback) throws IOException { ResourceList<Image> imageResourceList = new ResourceList<>(); FutureCallback<ResourceList<Image>> callback = new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { if (imageResourceList.getItems() == null) { imageResourceList.setItems(result.getItems()); } else { imageResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Image>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(imageResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Image>>() {}); }
ImagesRestApi extends ApiBase implements ImagesApi { @Override public void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback) throws IOException { ResourceList<Image> imageResourceList = new ResourceList<>(); FutureCallback<ResourceList<Image>> callback = new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { if (imageResourceList.getItems() == null) { imageResourceList.setItems(result.getItems()); } else { imageResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Image>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(imageResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Image>>() {}); } }
ImagesRestApi extends ApiBase implements ImagesApi { @Override public void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback) throws IOException { ResourceList<Image> imageResourceList = new ResourceList<>(); FutureCallback<ResourceList<Image>> callback = new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { if (imageResourceList.getItems() == null) { imageResourceList.setItems(result.getItems()); } else { imageResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Image>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(imageResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Image>>() {}); } ImagesRestApi(RestClient restClient); }
ImagesRestApi extends ApiBase implements ImagesApi { @Override public void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback) throws IOException { ResourceList<Image> imageResourceList = new ResourceList<>(); FutureCallback<ResourceList<Image>> callback = new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { if (imageResourceList.getItems() == null) { imageResourceList.setItems(result.getItems()); } else { imageResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Image>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(imageResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Image>>() {}); } ImagesRestApi(RestClient restClient); @Override String getBasePath(); @Override Task uploadImage(String inputFileName); @Override Task uploadImage(String inputFileName, String replicationType); @Override Task uploadImage(FileBody fileBody, String replicationType); @Override Image getImage(String imageId); @Override void getImageAsync(final String imageId, final FutureCallback<Image> responseCallback); @Override ResourceList<Image> getImages(); @Override void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback); }
ImagesRestApi extends ApiBase implements ImagesApi { @Override public void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback) throws IOException { ResourceList<Image> imageResourceList = new ResourceList<>(); FutureCallback<ResourceList<Image>> callback = new FutureCallback<ResourceList<Image>>() { @Override public void onSuccess(@Nullable ResourceList<Image> result) { if (imageResourceList.getItems() == null) { imageResourceList.setItems(result.getItems()); } else { imageResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<Image>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(imageResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(getBasePath(), callback, new TypeReference<ResourceList<Image>>() {}); } ImagesRestApi(RestClient restClient); @Override String getBasePath(); @Override Task uploadImage(String inputFileName); @Override Task uploadImage(String inputFileName, String replicationType); @Override Task uploadImage(FileBody fileBody, String replicationType); @Override Image getImage(String imageId); @Override void getImageAsync(final String imageId, final FutureCallback<Image> responseCallback); @Override ResourceList<Image> getImages(); @Override void getImagesAsync(final FutureCallback<ResourceList<Image>> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback);  }