Search in sources :

Example 6 with UserDoc

use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.

the class UsersActionTest method return_minimal_fields.

@Test
public void return_minimal_fields() throws Exception {
    es.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), new UserDoc().setLogin("ada.lovelace").setName("Ada Lovelace").setActive(false), new UserDoc().setLogin("grace.hopper").setName("Grace Hopper").setActive(true));
    userSessionRule.logIn("sonarqtech");
    WsTester.TestRequest request = tester.newGetRequest("batch", "users").setParam("logins", "ada.lovelace,grace.hopper");
    ByteArrayInputStream input = new ByteArrayInputStream(request.execute().output());
    User user1 = User.parseDelimitedFrom(input);
    User user2 = User.parseDelimitedFrom(input);
    assertThat(User.parseDelimitedFrom(input)).isNull();
    List<User> users = Arrays.asList(user1, user2);
    assertThat(users).extracting("login").containsOnly("ada.lovelace", "grace.hopper");
    assertThat(users).extracting("name").containsOnly("Ada Lovelace", "Grace Hopper");
}
Also used : User(org.sonar.scanner.protocol.input.ScannerInput.User) WsTester(org.sonar.server.ws.WsTester) ByteArrayInputStream(java.io.ByteArrayInputStream) UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Example 7 with UserDoc

use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.

the class DefaultAssigneeTest method default_assignee.

@Test
public void default_assignee() {
    settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
    when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(true));
    assertThat(underTest.getLogin()).isEqualTo("erik");
}
Also used : UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Example 8 with UserDoc

use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.

the class DefaultAssigneeTest method configured_login_is_disabled.

@Test
public void configured_login_is_disabled() {
    settings.setProperty(CoreProperties.DEFAULT_ISSUE_ASSIGNEE, "erik");
    when(userIndex.getNullableByLogin("erik")).thenReturn(new UserDoc().setLogin("erik").setActive(false));
    assertThat(underTest.getLogin()).isNull();
}
Also used : UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Example 9 with UserDoc

use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.

the class ScmAccountToUserLoaderTest method load_login_for_scm_account.

@Test
public void load_login_for_scm_account() throws Exception {
    UserDoc user = new UserDoc().setLogin("charlie").setName("Charlie").setEmail("charlie@hebdo.com").setActive(true).setScmAccounts(asList("charlie", "jesuis@charlie.com"));
    esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), user);
    UserIndex index = new UserIndex(esTester.client());
    ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
    assertThat(underTest.load("missing")).isNull();
    assertThat(underTest.load("jesuis@charlie.com")).isEqualTo("charlie");
}
Also used : UserIndex(org.sonar.server.user.index.UserIndex) UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Example 10 with UserDoc

use of org.sonar.server.user.index.UserDoc in project sonarqube by SonarSource.

the class ScmAccountToUserLoaderTest method warn_if_multiple_users_share_the_same_scm_account.

@Test
public void warn_if_multiple_users_share_the_same_scm_account() throws Exception {
    UserDoc user1 = new UserDoc().setLogin("charlie").setName("Charlie").setEmail("charlie@hebdo.com").setActive(true).setScmAccounts(asList("charlie", "jesuis@charlie.com"));
    esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), user1);
    UserDoc user2 = new UserDoc().setLogin("another.charlie").setName("Another Charlie").setActive(true).setScmAccounts(asList("charlie"));
    esTester.putDocuments(UserIndexDefinition.INDEX_TYPE_USER.getIndex(), UserIndexDefinition.INDEX_TYPE_USER.getType(), user2);
    UserIndex index = new UserIndex(esTester.client());
    ScmAccountToUserLoader underTest = new ScmAccountToUserLoader(index);
    assertThat(underTest.load("charlie")).isNull();
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Multiple users share the SCM account 'charlie': another.charlie, charlie");
}
Also used : UserIndex(org.sonar.server.user.index.UserIndex) UserDoc(org.sonar.server.user.index.UserDoc) Test(org.junit.Test)

Aggregations

UserDoc (org.sonar.server.user.index.UserDoc)13 Test (org.junit.Test)7 UserIndex (org.sonar.server.user.index.UserIndex)4 Before (org.junit.Before)3 UserDto (org.sonar.db.user.UserDto)3 Locale (java.util.Locale)2 Matchers.anyString (org.mockito.Matchers.anyString)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 EmailSettings (org.sonar.api.config.EmailSettings)2 DefaultI18n (org.sonar.core.i18n.DefaultI18n)2 UserTesting.newUserDto (org.sonar.db.user.UserTesting.newUserDto)2 WsTester (org.sonar.server.ws.WsTester)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 OutputStream (java.io.OutputStream)1 Date (java.util.Date)1 JsonWriter (org.sonar.api.utils.text.JsonWriter)1 DbSession (org.sonar.db.DbSession)1 User (org.sonar.scanner.protocol.input.ScannerInput.User)1 ComponentFinder (org.sonar.server.component.ComponentFinder)1 SearchOptions (org.sonar.server.es.SearchOptions)1