@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"));
  }
  @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"));
  }
  @Test
  public void testSetSecurityGroupsSuccess() throws Exception {
    Task task = new Task();
    task.setId(taskId);

    List<String> securityGroups =
        Arrays.asList(new String[] {"tenant\\adminGroup1", "tenant\\adminGroup2"});
    when(projectFeClient.setSecurityGroups(projectId, securityGroups)).thenReturn(task);

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

    Task responseTask = response.readEntity(Task.class);
    assertThat(responseTask, is(task));
    assertThat(new URI(responseTask.getSelfLink()).isAbsolute(), is(true));
    assertThat(responseTask.getSelfLink().endsWith(taskRoutePath), is(true));
  }