コード例 #1
0
  @Test
  public void failsToListAllWithInvalidPageLink() throws Throwable {
    String pageLink = "randomPageLink";
    doThrow(new PageExpiredException(pageLink)).when(frontendClient).nextList(pageLink);

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

    String expectedErrorMessage = "Page " + pageLink + " has expired";

    ApiError errors = response.readEntity(ApiError.class);
    assertThat(errors.getCode(), is(ErrorCode.PAGE_EXPIRED.getCode()));
    assertThat(errors.getMessage(), is(expectedErrorMessage));
  }
コード例 #2
0
  @Test
  public void failsToListAllWithInvalidPageSize() throws Throwable {
    int pageSize = paginationConfig.getMaxPageSize() + 1;
    Response response = listNetworks(Optional.absent(), Optional.of(pageSize), Optional.absent());
    assertThat(response.getStatus(), is(Response.Status.BAD_REQUEST.getStatusCode()));

    String expectedErrorMsg =
        String.format(
            "The page size '%d' is not between '1' and '%d'",
            pageSize, PaginationConfig.DEFAULT_MAX_PAGE_SIZE);

    ApiError errors = response.readEntity(ApiError.class);
    assertThat(errors.getCode(), is(ErrorCode.INVALID_PAGE_SIZE.getCode()));
    assertThat(errors.getMessage(), is(expectedErrorMsg));
  }
コード例 #3
0
  @Test
  public void testSetSecurityGroupsFail() throws Exception {
    List<String> securityGroups =
        Arrays.asList(new String[] {"tenant\\adminGroup1", "tenant\\adminGroup2"});
    when(projectFeClient.setSecurityGroups(projectId, securityGroups))
        .thenThrow(new ExternalException("Failed to change security groups"));

    Response response =
        client()
            .target(projectRoutePath)
            .request()
            .post(
                Entity.entity(new ResourceList<>(securityGroups), MediaType.APPLICATION_JSON_TYPE));
    assertThat(response.getStatus(), is(500));

    ApiError errors = response.readEntity(ApiError.class);
    assertThat(errors.getCode(), is("InternalError"));
    assertThat(errors.getMessage(), is("Failed to change security groups"));
  }
コード例 #4
0
  @Test
  public void testSetSecurityGroupsFailWithInvalidSecurityGroup() throws Exception {
    List<String> securityGroups = Arrays.asList(new String[] {"adminGroup1", "adminGroup2"});
    when(projectFeClient.setSecurityGroups(projectId, securityGroups))
        .thenThrow(new ExternalException("Failed to change security groups"));

    Response response =
        client()
            .target(projectRoutePath)
            .request()
            .post(
                Entity.entity(new ResourceList<>(securityGroups), MediaType.APPLICATION_JSON_TYPE));
    assertThat(response.getStatus(), is(400));

    ApiError errors = response.readEntity(ApiError.class);
    assertThat(errors.getCode(), is("InvalidSecurityGroupFormat"));
    assertThat(
        errors.getMessage(),
        containsString("The security group format should match domain\\group"));
  }