FlavorRestApi extends ApiBase implements FlavorApi { @Override public void getFlavorAsync(final String flavorId, final FutureCallback<Flavor> responseCallback) throws IOException { final String path = String.format("%s/%s", getBasePath(), flavorId); getObjectByPathAsync(path, responseCallback, new TypeReference<Flavor>() { }); } FlavorRestApi(RestClient restClient); @Override String getBasePath(); @Override Task create(FlavorCreateSpec flavorCreateSpec); @Override void createAsync(final FlavorCreateSpec flavorCreateSpec, final FutureCallback<Task> responseCallback); @Override ResourceList<Flavor> listAll(); @Override ResourceList<Flavor> listAll(Map<String, String> queryParams); @Override void listAllAsync(final FutureCallback<ResourceList<Flavor>> responseCallback); @Override Flavor getFlavor(String flavorId); @Override void getFlavorAsync(final String flavorId, final FutureCallback<Flavor> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String flavorId, final FutureCallback<Task> responseCallback);  }
@Test public void testGetFlavorAsync() throws IOException, InterruptedException { final Flavor flavor1 = new Flavor(); flavor1.setId("flavor1"); flavor1.setKind("vm"); ObjectMapper mapper = new ObjectMapper(); String serializedResponse = mapper.writeValueAsString(flavor1); setupMocks(serializedResponse, HttpStatus.SC_OK); FlavorApi flavorApi = new FlavorRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); flavorApi.getFlavorAsync(flavor1.getId(), new FutureCallback<Flavor>() { @Override public void onSuccess(@Nullable Flavor result) { assertEquals(result, flavor1); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }