Search in sources :

Example 46 with AccountInfo

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

the class ChangeIT method addReviewerThatIsInactiveByEmail.

@Test
public void addReviewerThatIsInactiveByEmail() throws Exception {
    ConfigInput conf = new ConfigInput();
    conf.enableReviewerByEmail = InheritableBoolean.TRUE;
    gApi.projects().name(project.get()).config(conf);
    PushOneCommit.Result result = createChange();
    String username = "user@domain.com";
    Account.Id id = accountOperations.newAccount().username(username).inactive().create();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = username;
    in.state = ReviewerState.CC;
    ReviewerResult r = gApi.changes().id(result.getChangeId()).addReviewer(in);
    assertThat(r.input).isEqualTo(username);
    assertThat(r.error).isNull();
    assertThat(r.ccs).hasSize(1);
    AccountInfo reviewer = r.ccs.get(0);
    assertThat(reviewer._accountId).isEqualTo(id.get());
    assertThat(reviewer.username).isEqualTo(username);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 47 with AccountInfo

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

the class ChangeIT method testAddReviewerViaPostReview.

private void testAddReviewerViaPostReview(AddReviewerCaller addReviewer) throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    addReviewer.call(r.getChangeId(), user.email());
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    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());
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    // Adding a reviewer records that user as reviewer.
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    // Nobody was added as CC.
    assertThat(c.reviewers.get(CC)).isNull();
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
    // Change status of reviewer and ensure ETag is updated.
    oldETag = rsrc.getETag();
    accountOperations.account(user.id()).forUpdate().status("new status").update();
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
}
Also used : ChangeResource(com.google.gerrit.server.change.ChangeResource) Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Instant(java.time.Instant) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 48 with AccountInfo

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

the class ChangeIT method addReviewerToClosedChange.

@Test
public void addReviewerToClosedChange() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(admin.id().get());
    assertThat(c.reviewers).doesNotContainKey(CC);
    ReviewerInput in = new ReviewerInput();
    in.reviewer = user.email();
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    c = gApi.changes().id(r.getChangeId()).get();
    reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(2);
    Iterator<AccountInfo> reviewerIt = reviewers.iterator();
    assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
    assertThat(reviewerIt.next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers).doesNotContainKey(CC);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 49 with AccountInfo

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

the class ChangeIT method pushCommitOfOtherUser.

@Test
public void pushCommitOfOtherUser() throws Exception {
    // admin pushes commit of user
    PushOneCommit push = pushFactory.create(user.newIdent(), testRepo);
    PushOneCommit.Result result = push.to("refs/for/master");
    result.assertOkStatus();
    ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
    assertThat(change.owner._accountId).isEqualTo(admin.id().get());
    CommitInfo commit = change.revisions.get(change.currentRevision).commit;
    assertThat(commit.author.email).isEqualTo(user.email());
    assertThat(commit.committer.email).isEqualTo(user.email());
    // check that the author/committer was added as cc
    Collection<AccountInfo> reviewers = change.reviewers.get(CC);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(change.reviewers.get(REVIEWER)).isNull();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.from().name()).isEqualTo("Administrator (Code Review)");
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains("has uploaded this change for 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.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) RelatedChangeAndCommitInfo(com.google.gerrit.extensions.api.changes.RelatedChangeAndCommitInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 50 with AccountInfo

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

the class AbstractQueryAccountsTest method byNameWithoutModifyAccountCapability.

@Test
public void byNameWithoutModifyAccountCapability() throws Exception {
    AccountInfo user1 = newAccountWithFullName("jdoe", "John Doe");
    AccountInfo user2 = newAccountWithFullName("jroe", "Jane Roe");
    AccountInfo user3 = newAccount("user");
    requestContext.setContext(newRequestContext(Account.id(user3._accountId)));
    assertQuery("notexisting");
    assertQuery("Not Existing");
    // by full name works with any index version
    assertQuery(quote(user1.name), user1);
    assertQuery("name:" + quote(user1.name), user1);
    assertQuery(quote(user2.name), user2);
    assertQuery("name:" + quote(user2.name), user2);
    // by self/me works with any index version
    assertQuery("self", user3);
    assertQuery("me", user3);
    if (getSchemaVersion() < 8) {
        assertMissingField(AccountField.NAME_PART_NO_SECONDARY_EMAIL);
        // prefix queries only work if the NAME_PART_NO_SECONDARY_EMAIL field is available
        assertQuery("john");
        return;
    }
    assertQuery("John", user1);
    assertQuery("john", user1);
    assertQuery("Doe", user1);
    assertQuery("doe", user1);
    assertQuery("DOE", user1);
    assertQuery("Jo Do", user1);
    assertQuery("jo do", user1);
    assertQuery("name:John", user1);
    assertQuery("name:john", user1);
    assertQuery("name:Doe", user1);
    assertQuery("name:doe", user1);
    assertQuery("name:DOE", user1);
}
Also used : AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Test(org.junit.Test)

Aggregations

AccountInfo (com.google.gerrit.extensions.common.AccountInfo)112 Test (org.junit.Test)74 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)51 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)39 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)29 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)23 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)20 Account (com.google.gerrit.entities.Account)19 ArrayList (java.util.ArrayList)18 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)17 TestAccount (com.google.gerrit.acceptance.TestAccount)16 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)15 Message (com.google.gerrit.testing.FakeEmailSender.Message)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)14 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)13 Collection (java.util.Collection)12 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)10 HashMap (java.util.HashMap)10