@Test
  public void permission_web_services() {
    permissionsWsClient.addUser(new AddUserWsRequest().setPermission("admin").setLogin(LOGIN));
    permissionsWsClient.addGroup(
        new AddGroupWsRequest().setPermission("admin").setGroupName(GROUP_NAME));

    WsPermissions.WsSearchGlobalPermissionsResponse searchGlobalPermissionsWsResponse =
        permissionsWsClient.searchGlobalPermissions();
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getKey())
        .isEqualTo("admin");
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getUsersCount())
        .isEqualTo(1);
    // by default, a group has the global admin permission
    assertThat(searchGlobalPermissionsWsResponse.getPermissionsList().get(0).getGroupsCount())
        .isEqualTo(2);

    WsPermissions.UsersWsResponse users =
        permissionsWsClient.users(new UsersWsRequest().setPermission("admin"));
    assertThat(users.getUsersList()).extracting("login").contains(LOGIN);

    WsPermissions.WsGroupsResponse groupsResponse =
        permissionsWsClient.groups(new GroupsWsRequest().setPermission("admin"));
    assertThat(groupsResponse.getGroupsList()).extracting("name").contains(GROUP_NAME);
  }
  @Test
  public void template_permission_web_services() {
    WsPermissions.CreateTemplateWsResponse createTemplateWsResponse =
        permissionsWsClient.createTemplate(
            new CreateTemplateWsRequest()
                .setName("my-new-template")
                .setDescription("template-used-in-tests"));
    assertThat(createTemplateWsResponse.getPermissionTemplate().getName())
        .isEqualTo("my-new-template");

    permissionsWsClient.addUserToTemplate(
        new AddUserToTemplateWsRequest()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .setLogin(LOGIN));

    permissionsWsClient.addGroupToTemplate(
        new AddGroupToTemplateWsRequest()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .setGroupName(GROUP_NAME));

    permissionsWsClient.addProjectCreatorToTemplate(
        AddProjectCreatorToTemplateWsRequest.builder()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .build());

    SearchTemplatesWsResponse searchTemplatesWsResponse =
        permissionsWsClient.searchTemplates(
            new SearchTemplatesWsRequest().setQuery("my-new-template"));
    assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getName())
        .isEqualTo("my-new-template");
    assertThat(searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getKey())
        .isEqualTo("admin");
    assertThat(
            searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getUsersCount())
        .isEqualTo(1);
    assertThat(
            searchTemplatesWsResponse.getPermissionTemplates(0).getPermissions(0).getGroupsCount())
        .isEqualTo(1);
    assertThat(
            searchTemplatesWsResponse
                .getPermissionTemplates(0)
                .getPermissions(0)
                .getWithProjectCreator())
        .isTrue();

    permissionsWsClient.removeGroupFromTemplate(
        new RemoveGroupFromTemplateWsRequest()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .setGroupName(GROUP_NAME));

    permissionsWsClient.removeUserFromTemplate(
        new RemoveUserFromTemplateWsRequest()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .setLogin(LOGIN));

    permissionsWsClient.removeProjectCreatorFromTemplate(
        RemoveProjectCreatorFromTemplateWsRequest.builder()
            .setPermission("admin")
            .setTemplateName("my-new-template")
            .build());

    SearchTemplatesWsResponse clearedSearchTemplatesWsResponse =
        permissionsWsClient.searchTemplates(
            new SearchTemplatesWsRequest().setQuery("my-new-template"));
    assertThat(clearedSearchTemplatesWsResponse.getPermissionTemplates(0).getPermissionsList())
        .extracting(
            Permission::getUsersCount,
            Permission::getGroupsCount,
            Permission::getWithProjectCreator)
        .hasSize(5)
        .containsOnly(tuple(0, 0, false));
  }