コード例 #1
0
  /**
   * This method extracts the error strings associated with one or more failed task steps from a
   * Task object.
   *
   * @param task Supplies a task in the ERROR state.
   * @return A list of task step errors in a form suitable for use in creating an exception.
   */
  public static String getErrors(Task task) {
    if (!task.getState().toUpperCase().equals("ERROR")) {
      throw new IllegalArgumentException("task");
    }

    List<String> errorList = new ArrayList<>();
    for (Step step : task.getSteps()) {
      if (step.getState().toUpperCase().equals("ERROR")) {
        for (ApiError apiError : step.getErrors()) {
          errorList.add(
              String.format(
                  "Task \"%s\": step \"%s\" failed with error code \"%s\", message \"%s\"",
                  task.getOperation(),
                  step.getOperation(),
                  apiError.getCode(),
                  apiError.getMessage()));
        }
      }
    }

    if (0 == errorList.size()) {
      throw new RuntimeException("Task in error state contains no failed steps");
    }

    return errorList.toString();
  }
コード例 #2
0
  @Test
  public void testInvalidPageSize() {
    Response response = getTasks(Optional.of(200));
    assertThat(response.getStatus(), is(400));

    ApiError errors = response.readEntity(ApiError.class);
    assertThat(errors.getCode(), is("InvalidPageSize"));
    assertThat(errors.getMessage(), is("The page size '200' is not between '1' and '100'"));
  }
  @Test
  public void testSetAdminGroupsFailWithInvalidSecurityGroup() throws Exception {
    ResourceList<String> adminGroups =
        new ResourceList<>(Arrays.asList(new String[] {"adminGroup1", "adminGroup2"}));
    when(deploymentFeClient.setSecurityGroups(eq(deploymentId), anyListOf(String.class)))
        .thenThrow(
            new InvalidAuthConfigException(
                "Auth is not enabled, and security groups cannot be set."));

    Response response =
        client()
            .target(deploymentRoutePath)
            .request()
            .post(Entity.entity(adminGroups, 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"));
  }