@GET
  @ApiOperation(
      value =
          "Find tasks associated with AvailabilityZone. If pageLink is provided, "
              + "then get the tasks on that specific page",
      response = Task.class,
      responseContainer = ResourceList.CLASS_NAME)
  @ApiResponses(
      value = {@ApiResponse(code = 200, message = "List of tasks for an availabilityZone")})
  public Response get(
      @Context Request request,
      @PathParam("id") String id,
      @QueryParam("state") Optional<String> state,
      @QueryParam("pageSize") Optional<Integer> pageSize,
      @QueryParam("pageLink") Optional<String> pageLink)
      throws ExternalException {

    ResourceList<Task> resourceList;
    if (pageLink.isPresent()) {
      resourceList = taskFeClient.getPage(pageLink.get());
    } else {
      Optional<Integer> adjustedPageSize =
          PaginationUtils.determinePageSize(paginationConfig, pageSize);
      resourceList = taskFeClient.getAvailabilityZoneTasks(id, state, adjustedPageSize);
    }

    return generateResourceListResponse(
        Response.Status.OK,
        PaginationUtils.formalizePageLinks(resourceList, TaskResourceRoutes.API),
        (ContainerRequest) request,
        TaskResourceRoutes.TASK_PATH);
  }
  @Test
  public void testGetResourceTicketTasksPage() throws Exception {
    ResourceList<Task> expectedTasksPage =
        new ResourceList<Task>(
            ImmutableList.of(task1, task2),
            UUID.randomUUID().toString(),
            UUID.randomUUID().toString());
    when(client.getPage(anyString())).thenReturn(expectedTasksPage);

    List<String> expectedSelfLinks = ImmutableList.of(taskRoutePath1, taskRoutePath2);

    Response response = getTasks(UUID.randomUUID().toString());
    assertThat(response.getStatus(), is(200));

    ResourceList<Task> tasks = response.readEntity(new GenericType<ResourceList<Task>>() {});

    assertThat(tasks.getItems().size(), is(expectedTasksPage.getItems().size()));

    for (int i = 0; i < tasks.getItems().size(); i++) {
      assertThat(new URI(tasks.getItems().get(i).getSelfLink()).isAbsolute(), is(true));
      assertThat(tasks.getItems().get(i), is(expectedTasksPage.getItems().get(i)));
      assertThat(
          tasks.getItems().get(i).getSelfLink().endsWith(expectedSelfLinks.get(i)), is(true));
    }

    verifyPageLinks(tasks);
  }
  @Test(dataProvider = "pageSizes")
  public void testGetResourceTicketTasks(
      Optional<Integer> pageSize, List<Task> expectedTasks, List<String> expectedTaskRoutes)
      throws Exception {
    task1.setId(taskId1);
    task2.setId(taskId2);

    when(client.getResourceTicketTasks(
            ticketId,
            Optional.<String>absent(),
            Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)))
        .thenReturn(new ResourceList<>(ImmutableList.of(task1, task2), null, null));
    when(client.getResourceTicketTasks(ticketId, Optional.<String>absent(), Optional.of(1)))
        .thenReturn(
            new ResourceList<>(ImmutableList.of(task1), UUID.randomUUID().toString(), null));
    when(client.getResourceTicketTasks(ticketId, Optional.<String>absent(), Optional.of(2)))
        .thenReturn(new ResourceList<>(ImmutableList.of(task1, task2), null, null));
    when(client.getResourceTicketTasks(ticketId, Optional.<String>absent(), Optional.of(3)))
        .thenReturn(new ResourceList<>(Collections.emptyList(), null, null));

    Response response = getTasks(pageSize);
    assertThat(response.getStatus(), is(200));

    ResourceList<Task> tasks = response.readEntity(new GenericType<ResourceList<Task>>() {});

    assertThat(tasks.getItems().size(), is(expectedTasks.size()));

    for (int i = 0; i < tasks.getItems().size(); i++) {
      assertThat(tasks.getItems().get(i), is(expectedTasks.get(i)));
      assertThat(
          new URI(tasks.getItems().get(i).getSelfLink()).isAbsolute(), CoreMatchers.is(true));
      assertThat(
          tasks.getItems().get(i).getSelfLink().endsWith(expectedTaskRoutes.get(i)),
          CoreMatchers.is(true));
    }

    verifyPageLinks(tasks);
  }
 @GET
 @ApiOperation(
     value = "Find tasks, filtering by entityId and entityKind",
     response = Task.class,
     responseContainer = ResourceList.CLASS_NAME)
 @ApiResponses(value = {@ApiResponse(code = 200, message = "List of tasks")})
 public Response find(
     @Context Request request,
     @QueryParam("entityId") Optional<String> entityId,
     @QueryParam("entityKind") Optional<String> entityKind,
     @QueryParam("state") Optional<String> state,
     @QueryParam("pageSize") Optional<Integer> pageSize)
     throws ExternalException {
   return generateResourceListResponse(
       Response.Status.OK,
       taskFeClient.find(entityId, entityKind, state, pageSize),
       (ContainerRequest) request,
       TaskResourceRoutes.TASK_PATH);
 }