@Test public void testList() throws IOException { Tenant tenant1 = new Tenant(); tenant1.setId("tenant1"); tenant1.setName("tenant1"); Tenant tenant2 = new Tenant(); tenant2.setId("tenant2"); tenant2.setName("tenant2"); ResourceList<Tenant> tenantResourceList = new ResourceList<>(Arrays.asList(tenant1, tenant2)); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(tenantResourceList); setupMocks(serializedTask, HttpStatus.SC_OK); TenantsApi tenantsApi = new TenantsRestApi(restClient); ResourceList<Tenant> response = tenantsApi.listByName("foo"); assertEquals(response.getItems().size(), tenantResourceList.getItems().size()); assertTrue(response.getItems().containsAll(tenantResourceList.getItems())); }
@Override public ResourceList<Tenant> listByName(String name) throws IOException { String path = getBasePath(); if (name != null) { path += "?name=" + name; } ResourceList<Tenant> tenantResourceList = new ResourceList<>(); ResourceList<Tenant> resourceList = getTenantResourceList(path); tenantResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTenantResourceList(resourceList.getNextPageLink()); tenantResourceList.getItems().addAll(resourceList.getItems()); } return tenantResourceList; }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public ResourceList<Tenant> listByName(String name) throws IOException { String path = getBasePath(); if (name != null) { path += "?name=" + name; } ResourceList<Tenant> tenantResourceList = new ResourceList<>(); ResourceList<Tenant> resourceList = getTenantResourceList(path); tenantResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTenantResourceList(resourceList.getNextPageLink()); tenantResourceList.getItems().addAll(resourceList.getItems()); } return tenantResourceList; } }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public ResourceList<Tenant> listByName(String name) throws IOException { String path = getBasePath(); if (name != null) { path += "?name=" + name; } ResourceList<Tenant> tenantResourceList = new ResourceList<>(); ResourceList<Tenant> resourceList = getTenantResourceList(path); tenantResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTenantResourceList(resourceList.getNextPageLink()); tenantResourceList.getItems().addAll(resourceList.getItems()); } return tenantResourceList; } TenantsRestApi(RestClient restClient); }
TenantsRestApi extends ApiBase implements TenantsApi { @Override public ResourceList<Tenant> listByName(String name) throws IOException { String path = getBasePath(); if (name != null) { path += "?name=" + name; } ResourceList<Tenant> tenantResourceList = new ResourceList<>(); ResourceList<Tenant> resourceList = getTenantResourceList(path); tenantResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTenantResourceList(resourceList.getNextPageLink()); tenantResourceList.getItems().addAll(resourceList.getItems()); } return tenantResourceList; } 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 ResourceList<Tenant> listByName(String name) throws IOException { String path = getBasePath(); if (name != null) { path += "?name=" + name; } ResourceList<Tenant> tenantResourceList = new ResourceList<>(); ResourceList<Tenant> resourceList = getTenantResourceList(path); tenantResourceList.setItems(resourceList.getItems()); while (resourceList.getNextPageLink() != null && !resourceList.getNextPageLink().isEmpty()) { resourceList = getTenantResourceList(resourceList.getNextPageLink()); tenantResourceList.getItems().addAll(resourceList.getItems()); } return tenantResourceList; } 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);  }