@Test public void testGetResourceTicketsAsync() throws IOException, InterruptedException { ResourceTicket resourceTicket1 = new ResourceTicket(); resourceTicket1.setId("resourceTicket1"); ResourceTicket resourceTicket2 = new ResourceTicket(); resourceTicket2.setId("resourceTicket2"); final ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>( Arrays.asList(resourceTicket1, resourceTicket2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(resourceTicketResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); tenantsApi.getResourceTicketsAsync("foo", new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { assertEquals(result.getItems(), resourceTicketResourceList.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 getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException { String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId); ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(); FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { if (resourceTicketResourceList.getItems() == null) { resourceTicketResourceList.setItems(result.getItems()); } else { resourceTicketResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<ResourceTicket>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(resourceTicketResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {}); }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException { String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId); ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(); FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { if (resourceTicketResourceList.getItems() == null) { resourceTicketResourceList.setItems(result.getItems()); } else { resourceTicketResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<ResourceTicket>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(resourceTicketResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {}); } }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException { String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId); ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(); FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { if (resourceTicketResourceList.getItems() == null) { resourceTicketResourceList.setItems(result.getItems()); } else { resourceTicketResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<ResourceTicket>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(resourceTicketResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {}); } TenantsRestApi(RestClient restClient); }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException { String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId); ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(); FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { if (resourceTicketResourceList.getItems() == null) { resourceTicketResourceList.setItems(result.getItems()); } else { resourceTicketResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<ResourceTicket>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(resourceTicketResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {}); } TenantsRestApi(RestClient restClient); @Override String getBasePath(); @Override Task create(String name); @Override void createAsync(final String name, final FutureCallback<Task> responseCallback); @Override ResourceList<Tenant> listAll(); @Override void listAllAsync(final FutureCallback<ResourceList<Tenant>> responseCallback); @Override ResourceList<Tenant> listByName(String name); @Override Tenant getTenant(String tenantId); @Override void listByNameAsync(final String name, final FutureCallback<ResourceList<Tenant>> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback); @Override Task createResourceTicket(String tenantId, ResourceTicketCreateSpec resourceTicketCreateSpec); @Override void createResourceTicketAsync(String tenantId, ResourceTicketCreateSpec resourceTicketCreateSpec,
                                        final FutureCallback<Task> responseCallback); @Override ResourceList<ResourceTicket> getResourceTickets(String tenantId); @Override void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>>
      responseCallback); @Override Task createProject(String tenantId, ProjectCreateSpec projectCreateSpec); @Override void createProjectAsync(String tenantId, ProjectCreateSpec projectCreateSpec,
                                 final FutureCallback<Task> responseCallback); @Override ResourceList<Project> getProjects(String tenantId); @Override void getProjectsAsync(final String tenantId, final FutureCallback<ResourceList<Project>>
      responseCallback); }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>> responseCallback) throws IOException { String path = String.format("%s/%s/resource-tickets", getBasePath(), tenantId); ResourceList<ResourceTicket> resourceTicketResourceList = new ResourceList<>(); FutureCallback<ResourceList<ResourceTicket>> callback = new FutureCallback<ResourceList<ResourceTicket>>() { @Override public void onSuccess(@Nullable ResourceList<ResourceTicket> result) { if (resourceTicketResourceList.getItems() == null) { resourceTicketResourceList.setItems(result.getItems()); } else { resourceTicketResourceList.getItems().addAll(result.getItems()); } if (result.getNextPageLink() != null && !result.getNextPageLink().isEmpty()) { try { getObjectByPathAsync(result.getNextPageLink(), this, new TypeReference<ResourceList<ResourceTicket>>() {}); } catch (IOException e) { e.printStackTrace(); } } else { responseCallback.onSuccess(resourceTicketResourceList); } } @Override public void onFailure(Throwable t) { responseCallback.onFailure(t); } }; getObjectByPathAsync(path, callback, new TypeReference<ResourceList<ResourceTicket>>() {}); } TenantsRestApi(RestClient restClient); @Override String getBasePath(); @Override Task create(String name); @Override void createAsync(final String name, final FutureCallback<Task> responseCallback); @Override ResourceList<Tenant> listAll(); @Override void listAllAsync(final FutureCallback<ResourceList<Tenant>> responseCallback); @Override ResourceList<Tenant> listByName(String name); @Override Tenant getTenant(String tenantId); @Override void listByNameAsync(final String name, final FutureCallback<ResourceList<Tenant>> responseCallback); @Override Task delete(String id); @Override void deleteAsync(final String id, final FutureCallback<Task> responseCallback); @Override Task createResourceTicket(String tenantId, ResourceTicketCreateSpec resourceTicketCreateSpec); @Override void createResourceTicketAsync(String tenantId, ResourceTicketCreateSpec resourceTicketCreateSpec,
                                        final FutureCallback<Task> responseCallback); @Override ResourceList<ResourceTicket> getResourceTickets(String tenantId); @Override void getResourceTicketsAsync(final String tenantId, final FutureCallback<ResourceList<ResourceTicket>>
      responseCallback); @Override Task createProject(String tenantId, ProjectCreateSpec projectCreateSpec); @Override void createProjectAsync(String tenantId, ProjectCreateSpec projectCreateSpec,
                                 final FutureCallback<Task> responseCallback); @Override ResourceList<Project> getProjects(String tenantId); @Override void getProjectsAsync(final String tenantId, final FutureCallback<ResourceList<Project>>
      responseCallback);  }