Search in sources :

Example 21 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class UpdateActionTest method update_only_scm_accounts_with_deprecated_scmAccounts_parameter.

@Test
public void update_only_scm_accounts_with_deprecated_scmAccounts_parameter() throws Exception {
    createUser();
    tester.newPostRequest("api/users", "update").setParam("login", "john").setParam("scmAccounts", "jon.snow").execute().assertJson(getClass(), "update_scm_accounts.json");
    UserDto user = dbClient.userDao().selectByLogin(session, "john");
    assertThat(user.getScmAccountsAsList()).containsOnly("jon.snow");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 22 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class RemoveUserActionTest method remove_user_by_group_name_in_specific_organization.

@Test
public void remove_user_by_group_name_in_specific_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "a_group");
    UserDto user = db.users().insertUser("a_user");
    db.users().insertMember(group, user);
    // keep an administrator
    db.users().insertAdminByUserPermission(org);
    loginAsAdmin(org);
    newRequest().setParam(PARAM_ORGANIZATION_KEY, org.getKey()).setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_LOGIN, user.getLogin()).execute().assertNoContent();
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 23 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class RemoveUserActionTest method remove_user_by_group_name_in_default_organization.

@Test
public void remove_user_by_group_name_in_default_organization() throws Exception {
    insertAnAdministratorInDefaultOrganization();
    GroupDto group = db.users().insertGroup(db.getDefaultOrganization(), "a_group");
    UserDto user = db.users().insertUser("a_user");
    db.users().insertMember(group, user);
    loginAsAdminOnDefaultOrganization();
    newRequest().setParam(PARAM_GROUP_NAME, group.getName()).setParam(PARAM_LOGIN, user.getLogin()).execute().assertNoContent();
    assertThat(db.users().selectGroupIdsOfUser(user)).isEmpty();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) Test(org.junit.Test)

Example 24 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class RemoveUserActionTest method throw_ForbiddenException_if_not_administrator_of_organization.

@Test
public void throw_ForbiddenException_if_not_administrator_of_organization() throws Exception {
    OrganizationDto org = db.organizations().insert();
    GroupDto group = db.users().insertGroup(org, "a-group");
    UserDto user = db.users().insertUser();
    db.users().insertMember(group, user);
    loginAsAdminOnDefaultOrganization();
    expectedException.expect(ForbiddenException.class);
    expectedException.expectMessage("Insufficient privileges");
    newRequest().setParam("id", group.getId().toString()).setParam("login", user.getLogin()).execute();
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) OrganizationDto(org.sonar.db.organization.OrganizationDto) Test(org.junit.Test)

Example 25 with UserDto

use of org.sonar.db.user.UserDto in project sonarqube by SonarSource.

the class SearchActionTest method insertGroup.

private void insertGroup(OrganizationDto org, String name, int numberOfMembers) {
    GroupDto group = newGroupDto().setName(name).setDescription(capitalize(name)).setOrganizationUuid(org.getUuid());
    db.users().insertGroup(group);
    for (int i = 0; i < numberOfMembers; i++) {
        UserDto user = db.users().insertUser();
        db.users().insertMember(group, user);
    }
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto)

Aggregations

UserDto (org.sonar.db.user.UserDto)1318 Test (org.junit.Test)1173 ComponentDto (org.sonar.db.component.ComponentDto)332 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)216 GroupDto (org.sonar.db.user.GroupDto)152 IssueDto (org.sonar.db.issue.IssueDto)131 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)108 TestRequest (org.sonar.server.ws.TestRequest)102 NotFoundException (org.sonar.server.exceptions.NotFoundException)84 DbSession (org.sonar.db.DbSession)82 RuleDefinitionDto (org.sonar.db.rule.RuleDefinitionDto)80 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)64 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)57 Rule (org.junit.Rule)57 DbTester (org.sonar.db.DbTester)54 ForbiddenException (org.sonar.server.exceptions.ForbiddenException)52 WebService (org.sonar.api.server.ws.WebService)44 BadRequestException (org.sonar.server.exceptions.BadRequestException)43 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)41 UserSessionRule (org.sonar.server.tester.UserSessionRule)41