Search in sources :

Example 16 with UserDto

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

the class UserUpdaterTest method update_only_user_password.

@Test
public void update_only_user_password() {
    db.users().insertUser(newLocalUser(DEFAULT_LOGIN, "Marius", "marius@lesbronzes.fr").setScmAccounts(asList("ma", "marius33")).setSalt("salt").setCryptedPassword("crypted password").setCreatedAt(PAST).setUpdatedAt(PAST));
    createDefaultGroup();
    underTest.update(session, UpdateUser.create(DEFAULT_LOGIN).setPassword("password2"));
    session.commit();
    UserDto dto = dbClient.userDao().selectByLogin(session, DEFAULT_LOGIN);
    assertThat(dto.getSalt()).isNotEqualTo("salt");
    assertThat(dto.getCryptedPassword()).isNotEqualTo("crypted password");
    // Following fields has not changed
    assertThat(dto.getName()).isEqualTo("Marius");
    assertThat(dto.getScmAccountsAsList()).containsOnly("ma", "marius33");
    assertThat(dto.getEmail()).isEqualTo("marius@lesbronzes.fr");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 17 with UserDto

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

the class DeactivateActionTest method cannot_deactivate_self.

@Test
public void cannot_deactivate_self() throws Exception {
    UserDto user = createUser();
    userSession.logIn(user.getLogin()).setSystemAdministrator();
    expectedException.expect(BadRequestException.class);
    expectedException.expectMessage("Self-deactivation is not possible");
    deactivate(user.getLogin());
    verifyThatUserExists(user.getLogin());
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) Test(org.junit.Test)

Example 18 with UserDto

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

the class GroupsActionTest method selected_groups.

@Test
public void selected_groups() throws Exception {
    UserDto user = createUser();
    GroupDto usersGroup = createGroup("sonar-users", "Sonar Users");
    createGroup("sonar-admins", "Sonar Admins");
    addUserToGroup(user, usersGroup);
    session.commit();
    tester.newGetRequest("api/users", "groups").setParam("login", "john").execute().assertJson(getClass(), "selected.json");
    tester.newGetRequest("api/users", "groups").setParam("login", "john").setParam(Param.SELECTED, SelectionMode.SELECTED.value()).execute().assertJson(getClass(), "selected.json");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Example 19 with UserDto

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

the class GroupsActionTest method all_groups.

@Test
public void all_groups() throws Exception {
    UserDto user = createUser();
    GroupDto usersGroup = createGroup("sonar-users", "Sonar Users");
    createGroup("sonar-admins", "Sonar Admins");
    addUserToGroup(user, usersGroup);
    session.commit();
    tester.newGetRequest("api/users", "groups").setParam("login", "john").setParam(Param.SELECTED, SelectionMode.ALL.value()).execute().assertJson(getClass(), "all.json");
}
Also used : UserDto(org.sonar.db.user.UserDto) GroupDto(org.sonar.db.user.GroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) Test(org.junit.Test)

Example 20 with UserDto

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

the class SearchActionTest method search_with_groups.

@Test
public void search_with_groups() throws Exception {
    loginAsSystemAdministrator();
    List<UserDto> users = injectUsers(1);
    GroupDto group1 = dbClient.groupDao().insert(dbSession, newGroupDto().setName("sonar-users"));
    GroupDto group2 = dbClient.groupDao().insert(dbSession, newGroupDto().setName("sonar-admins"));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(group1.getId()).setUserId(users.get(0).getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setGroupId(group2.getId()).setUserId(users.get(0).getId()));
    dbSession.commit();
    ws.newGetRequest("api/users", "search").execute().assertJson(getClass(), "user_with_groups.json");
}
Also used : UserDto(org.sonar.db.user.UserDto) UserTesting.newUserDto(org.sonar.db.user.UserTesting.newUserDto) UserGroupDto(org.sonar.db.user.UserGroupDto) GroupDto(org.sonar.db.user.GroupDto) GroupTesting.newGroupDto(org.sonar.db.user.GroupTesting.newGroupDto) UserGroupDto(org.sonar.db.user.UserGroupDto) Test(org.junit.Test)

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