Search in sources :

Example 16 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method byId.

@Test
public void byId() throws Exception {
    AccountInfo user = newAccount("user");
    assertQuery("9999999");
    assertQuery(currentUserInfo._accountId, currentUserInfo);
    assertQuery(user._accountId, user);
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test)

Example 17 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method byEmail.

@Test
public void byEmail() throws Exception {
    AccountInfo user1 = newAccountWithEmail("user1", name("user1@example.com"));
    String domain = name("test.com");
    AccountInfo user2 = newAccountWithEmail("user2", "user2@" + domain);
    AccountInfo user3 = newAccountWithEmail("user3", "user3@" + domain);
    String prefix = name("prefix");
    AccountInfo user4 = newAccountWithEmail("user4", prefix + "user4@example.com");
    AccountInfo user5 = newAccountWithEmail("user5", name("user5MixedCase@example.com"));
    assertQuery("notexisting@test.com");
    assertQuery(currentUserInfo.email, currentUserInfo);
    assertQuery("email:" + currentUserInfo.email, currentUserInfo);
    assertQuery(user1.email, user1);
    assertQuery("email:" + user1.email, user1);
    assertQuery(domain, user2, user3);
    assertQuery("email:" + prefix, user4);
    assertQuery(user5.email, user5);
    assertQuery("email:" + user5.email, user5);
    assertQuery("email:" + user5.email.toUpperCase(), user5);
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test)

Example 18 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AbstractQueryAccountsTest method byUsername.

@Test
public void byUsername() throws Exception {
    AccountInfo user1 = newAccount("myuser");
    assertQuery("notexisting");
    assertQuery("Not Existing");
    assertQuery(user1.username, user1);
    assertQuery("username:" + user1.username, user1);
    assertQuery("username:" + user1.username.toUpperCase(), user1);
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test)

Example 19 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class ChangeIT method pushCommitWithFooterOfOtherUser.

@Test
public void pushCommitWithFooterOfOtherUser() throws Exception {
    // admin pushes commit that references 'user' in a footer
    PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT + "\n\n" + FooterConstants.REVIEWED_BY.getName() + ": " + user.getIdent().toExternalString(), PushOneCommit.FILE_NAME, PushOneCommit.FILE_CONTENT);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    // check that 'user' was added as reviewer
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    Collection<AccountInfo> reviewers = change.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.getId().get());
    assertThat(change.reviewers.get(CC)).isNull();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.emailAddress);
    assertThat(m.body()).contains("Hello " + user.fullName + ",\n");
    assertThat(m.body()).contains("I'd like you to do a code review.");
    assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
    assertMailReplyTo(m, admin.email);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testutil.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with AccountInfo

use of com.google.gerrit.extensions.common.AccountInfo in project gerrit by GerritCodeReview.

the class AccountsImpl method create.

@Override
public AccountApi create(AccountInput in) throws RestApiException {
    if (checkNotNull(in, "AccountInput").username == null) {
        throw new BadRequestException("AccountInput must specify username");
    }
    try {
        CreateAccount impl = createAccount.create(in.username);
        permissionBackend.user(self).checkAny(GlobalPermission.fromAnnotation(impl.getClass()));
        AccountInfo info = impl.apply(TopLevelResource.INSTANCE, in).value();
        return id(info._accountId);
    } catch (Exception e) {
        throw asRestApiException("Cannot create account " + in.username, e);
    }
}
Also used : CreateAccount(com.google.gerrit.server.account.CreateAccount) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ApiUtil.asRestApiException(com.google.gerrit.server.api.ApiUtil.asRestApiException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) AuthException(com.google.gerrit.extensions.restapi.AuthException) RestApiException(com.google.gerrit.extensions.restapi.RestApiException)

Aggregations

AccountInfo (com.google.gerrit.extensions.common.AccountInfo)58 Test (org.junit.Test)36 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)24 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)18 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)14 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)13 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)9 Account (com.google.gerrit.reviewdb.client.Account)8 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 AccountLoader (com.google.gerrit.server.account.AccountLoader)5 ArrayList (java.util.ArrayList)5 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)3 AccountGroup (com.google.gerrit.reviewdb.client.AccountGroup)3 Change (com.google.gerrit.reviewdb.client.Change)3 TestAccount (com.google.gerrit.acceptance.TestAccount)2 LabelType (com.google.gerrit.common.data.LabelType)2 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)2 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 ProblemInfo (com.google.gerrit.extensions.common.ProblemInfo)2