Search in sources :

Example 91 with AccountInfo

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

the class ChangeReviewersByEmailIT method addByEmailAndById.

@Test
public void addByEmailAndById() throws Exception {
    AccountInfo byEmail = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    AccountInfo byId = new AccountInfo(user.id().get());
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput inputByEmail = new ReviewerInput();
        inputByEmail.reviewer = toRfcAddressString(byEmail);
        inputByEmail.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(inputByEmail);
        ReviewerInput inputById = new ReviewerInput();
        inputById.reviewer = user.email();
        inputById.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(inputById);
        ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
        assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(byId, byEmail)));
        // All reviewers (both by id and by email) should be removable
        assertThat(info.removableReviewers).containsExactly(byId, byEmail);
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 92 with AccountInfo

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

the class ChangeReviewersByEmailIT method addedReviewersGetNotified.

@Test
public void addedReviewersGetNotified() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput input = new ReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        List<Message> messages = sender.getMessages();
        assertThat(messages).hasSize(1);
        assertThat(messages.get(0).rcpt()).containsExactly(Address.parse(input.reviewer));
        sender.clear();
    }
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 93 with AccountInfo

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

the class ChangeReviewersByEmailIT method reviewersByEmailAreServedFromIndex.

@Test
public void reviewersByEmailAreServedFromIndex() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput input = new ReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        try (AutoCloseable ignored = disableNoteDb()) {
            ChangeInfo info = Iterables.getOnlyElement(gApi.changes().query(r.getChangeId()).withOption(DETAILED_LABELS).get());
            assertThat(info.reviewers).isEqualTo(ImmutableMap.of(state, ImmutableList.of(acc)));
        }
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 94 with AccountInfo

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

the class ChangeReviewersIT method moveCcToReviewer.

@Test
public void moveCcToReviewer() throws Exception {
    // Create a change and add 'user' as CC.
    String changeId = createChange().getChangeId();
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = user.email();
    reviewerInput.state = ReviewerState.CC;
    gApi.changes().id(changeId).addReviewer(reviewerInput);
    // Verify that 'user' is a CC on the change and that there are no reviewers.
    ChangeInfo c = gApi.changes().id(changeId).get();
    Collection<AccountInfo> ccs = c.reviewers.get(CC);
    assertThat(ccs).isNotNull();
    assertThat(ccs).hasSize(1);
    assertThat(ccs.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers.get(REVIEWER)).isNull();
    // Move 'user' from CC to reviewer.
    gApi.changes().id(changeId).addReviewer(user.id().toString());
    // Verify that 'user' is a reviewer on the change now and that there are no CCs.
    c = gApi.changes().id(changeId).get();
    Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
    assertThat(reviewers).isNotNull();
    assertThat(reviewers).hasSize(1);
    assertThat(reviewers.iterator().next()._accountId).isEqualTo(user.id().get());
    assertThat(c.reviewers.get(CC)).isNull();
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 95 with AccountInfo

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

the class ChangeReviewersByEmailIT method removeByEmail.

@Test
public void removeByEmail() throws Exception {
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        ReviewerInput addInput = new ReviewerInput();
        addInput.reviewer = toRfcAddressString(acc);
        addInput.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(addInput);
        gApi.changes().id(r.getChangeId()).reviewer(acc.email).remove();
        ChangeInfo info = gApi.changes().id(r.getChangeId()).get(DETAILED_LABELS);
        assertThat(info.reviewers).isEmpty();
    }
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

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