@Test
  public void succeedsToListAll() throws Throwable {
    int virtualNetworkNumber = 2;
    List<VirtualSubnet> expectedVirtualSubnets = new ArrayList<>();
    for (int i = 0; i < virtualNetworkNumber; ++i) {
      VirtualSubnet expectedVirtualSubnet = new VirtualSubnet();
      expectedVirtualSubnet.setId(UUID.randomUUID().toString());
      expectedVirtualSubnet.setName("virtualNetwork" + i);

      expectedVirtualSubnets.add(expectedVirtualSubnet);
    }

    when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(1)))
        .thenReturn(new ResourceList<>(expectedVirtualSubnets));

    Response response = listNetworks(Optional.absent(), Optional.of(1), Optional.absent());
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));

    ResourceList<VirtualSubnet> virtualNetworks =
        response.readEntity(new GenericType<ResourceList<VirtualSubnet>>() {});
    assertThat(virtualNetworks.getItems().size(), is(virtualNetworkNumber));
    for (int i = 0; i < virtualNetworkNumber; ++i) {
      VirtualSubnet expectedVirtualSubnet = expectedVirtualSubnets.get(i);
      VirtualSubnet actualVirtualSubnet = virtualNetworks.getItems().get(i);
      assertThat(actualVirtualSubnet, is(expectedVirtualSubnet));

      String apiRoutePath =
          UriBuilder.fromPath(SubnetResourceRoutes.SUBNET_PATH)
              .build(expectedVirtualSubnet.getId())
              .toString();
      assertThat(actualVirtualSubnet.getSelfLink().endsWith(apiRoutePath), is(true));
      assertThat(new URI(actualVirtualSubnet.getSelfLink()).isAbsolute(), is(true));
    }
  }
  @Test
  public void succeedsToListAllWithPageLink() throws Throwable {
    String pageLink = "randomPageLink";
    VirtualSubnet expectedVirtualSubnet = new VirtualSubnet();
    expectedVirtualSubnet.setId(UUID.randomUUID().toString());
    expectedVirtualSubnet.setName("virtualNetwork");

    when(frontendClient.nextList(pageLink))
        .thenReturn(new ResourceList<>(ImmutableList.of(expectedVirtualSubnet)));

    Response response = listNetworks(Optional.absent(), Optional.absent(), Optional.of(pageLink));
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));

    ResourceList<VirtualSubnet> virtualNetworks =
        response.readEntity(new GenericType<ResourceList<VirtualSubnet>>() {});
    assertThat(virtualNetworks.getItems().size(), is(1));

    VirtualSubnet actualVirtualSubnet = virtualNetworks.getItems().get(0);
    assertThat(actualVirtualSubnet, is(expectedVirtualSubnet));

    String apiRoutePath =
        UriBuilder.fromPath(SubnetResourceRoutes.SUBNET_PATH)
            .build(expectedVirtualSubnet.getId())
            .toString();
    assertThat(actualVirtualSubnet.getSelfLink().endsWith(apiRoutePath), is(true));
    assertThat(new URI(actualVirtualSubnet.getSelfLink()).isAbsolute(), is(true));
  }
  @DataProvider(name = "listAllWithPageSize")
  private Object[][] getListAllWithPageSize() {
    int virtualNetworkNumber = 2;
    List<VirtualSubnet> expectedVirtualSubnets = new ArrayList<>();
    for (int i = 0; i < virtualNetworkNumber; ++i) {
      VirtualSubnet expectedVirtualSubnet = new VirtualSubnet();
      expectedVirtualSubnet.setId(UUID.randomUUID().toString());
      expectedVirtualSubnet.setName("virtualNetwork" + i);

      expectedVirtualSubnets.add(expectedVirtualSubnet);
    }

    return new Object[][] {
      {Optional.absent(), expectedVirtualSubnets},
      {Optional.of(1), ImmutableList.of(expectedVirtualSubnets.get(0))},
      {Optional.of(2), expectedVirtualSubnets},
      {Optional.of(3), Collections.emptyList()}
    };
  }
  @Test(dataProvider = "listAllWithPageSize")
  public void succeedsToListALlWithPageSize(
      Optional<Integer> pageSize, List<VirtualSubnet> expectedVirtualSubnets) throws Throwable {
    when(frontendClient.list(
            projectId,
            Project.KIND,
            Optional.absent(),
            Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE)))
        .thenReturn(new ResourceList<>(expectedVirtualSubnets, null, null));
    if (!expectedVirtualSubnets.isEmpty()) {
      when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(1)))
          .thenReturn(
              new ResourceList<>(
                  ImmutableList.of(expectedVirtualSubnets.get(0)),
                  UUID.randomUUID().toString(),
                  null));
    }
    when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(2)))
        .thenReturn(new ResourceList<>(expectedVirtualSubnets, null, null));
    when(frontendClient.list(projectId, Project.KIND, Optional.absent(), Optional.of(3)))
        .thenReturn(new ResourceList<>(Collections.emptyList(), null, null));

    Response response = listNetworks(Optional.absent(), pageSize, Optional.absent());
    assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));

    ResourceList<VirtualSubnet> virtualNetworks =
        response.readEntity(new GenericType<ResourceList<VirtualSubnet>>() {});
    assertThat(virtualNetworks.getItems().size(), is(expectedVirtualSubnets.size()));
    for (int i = 0; i < virtualNetworks.getItems().size(); ++i) {
      VirtualSubnet expectedVirtualSubnet = expectedVirtualSubnets.get(i);
      VirtualSubnet actualVirtualSubnet = virtualNetworks.getItems().get(i);
      assertThat(actualVirtualSubnet, is(expectedVirtualSubnet));

      String apiRoutePath =
          UriBuilder.fromPath(SubnetResourceRoutes.SUBNET_PATH)
              .build(expectedVirtualSubnet.getId())
              .toString();
      assertThat(actualVirtualSubnet.getSelfLink().endsWith(apiRoutePath), is(true));
      assertThat(new URI(actualVirtualSubnet.getSelfLink()).isAbsolute(), is(true));
    }
  }