Search in sources :

Example 6 with UserGroupDto

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

the class SearchActionTest method search_json_example.

@Test
public void search_json_example() throws Exception {
    UserDto fmallet = db.users().insertUser(newUserDto("fmallet", "Freddy Mallet", "f@m.com").setActive(true).setLocal(true).setScmAccounts(emptyList()));
    UserDto simon = db.users().insertUser(newUserDto("sbrandhof", "Simon", "s.brandhof@company.tld").setActive(true).setLocal(false).setExternalIdentity("sbrandhof@ldap.com").setExternalIdentityProvider("LDAP").setScmAccounts(newArrayList("simon.brandhof", "s.brandhof@company.tld")));
    GroupDto sonarUsers = db.users().insertGroup(newGroupDto().setName("sonar-users"));
    GroupDto sonarAdministrators = db.users().insertGroup(newGroupDto().setName("sonar-administrators"));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(simon.getId()).setGroupId(sonarUsers.getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(fmallet.getId()).setGroupId(sonarUsers.getId()));
    dbClient.userGroupDao().insert(dbSession, new UserGroupDto().setUserId(fmallet.getId()).setGroupId(sonarAdministrators.getId()));
    for (int i = 0; i < 3; i++) {
        dbClient.userTokenDao().insert(dbSession, newUserToken().setLogin(simon.getLogin()));
    }
    dbClient.userTokenDao().insert(dbSession, newUserToken().setLogin(fmallet.getLogin()));
    db.commit();
    userIndexer.indexOnStartup(null);
    loginAsSystemAdministrator();
    String response = ws.newGetRequest("api/users", "search").execute().outputAsString();
    assertJson(response).isSimilarTo(getClass().getResource("search-example.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

UserGroupDto (org.sonar.db.user.UserGroupDto)6 UserDto (org.sonar.db.user.UserDto)5 GroupDto (org.sonar.db.user.GroupDto)4 Test (org.junit.Test)3 GroupTesting.newGroupDto (org.sonar.db.user.GroupTesting.newGroupDto)3 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)3 DbSession (org.sonar.db.DbSession)2 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Strings (com.google.common.base.Strings)1 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Lists.newArrayList (com.google.common.collect.Lists.newArrayList)1 String.format (java.lang.String.format)1 HttpURLConnection (java.net.HttpURLConnection)1 SecureRandom (java.security.SecureRandom)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Random (java.util.Random)1