コード例 #1
0
  @Test
  public void succeedsToListByName() throws Throwable {
    VirtualSubnet expectedVirtualSubnet = new VirtualSubnet();
    expectedVirtualSubnet.setId(UUID.randomUUID().toString());
    expectedVirtualSubnet.setName("virtualNetwork");

    when(frontendClient.list(
            projectId, Project.KIND, Optional.of("virtualNetwork"), Optional.of(1)))
        .thenReturn(new ResourceList<>(ImmutableList.of(expectedVirtualSubnet)));

    Response response =
        listNetworks(Optional.of("virtualNetwork"), 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(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));
  }
コード例 #2
0
  @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));
    }
  }