Search in sources :

Example 36 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method addByEmailAndById.

@Test
public void addByEmailAndById() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    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();
        AddReviewerInput inputByEmail = new AddReviewerInput();
        inputByEmail.reviewer = toRfcAddressString(byEmail);
        inputByEmail.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(inputByEmail);
        AddReviewerInput inputById = new AddReviewerInput();
        inputById.reviewer = user.email;
        inputById.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(inputById);
        ChangeInfo info = gApi.changes().id(r.getChangeId()).get(EnumSet.of(ListChangesOption.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).isEqualTo(ImmutableList.of(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) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method reviewerAndCCReceiveSameEmail.

@Test
public void reviewerAndCCReceiveSameEmail() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    PushOneCommit.Result r = createChange();
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        for (int i = 0; i < 10; i++) {
            AddReviewerInput input = new AddReviewerInput();
            input.reviewer = String.format("%s-%s@gerritcodereview.com", state, i);
            input.state = state;
            gApi.changes().id(r.getChangeId()).addReviewer(input);
        }
    }
    // Also add user as a regular reviewer
    AddReviewerInput input = new AddReviewerInput();
    input.reviewer = user.email;
    input.state = ReviewerState.REVIEWER;
    gApi.changes().id(r.getChangeId()).addReviewer(input);
    sender.clear();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    // Assert that only one email was sent out to everyone
    assertThat(sender.getMessages()).hasSize(1);
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method removeByEmail.

@Test
public void removeByEmail() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        AddReviewerInput addInput = new AddReviewerInput();
        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(EnumSet.of(ListChangesOption.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) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 39 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method addedReviewersGetNotified.

@Test
public void addedReviewersGetNotified() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        AddReviewerInput input = new AddReviewerInput();
        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.testutil.FakeEmailSender.Message) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 40 with AddReviewerInput

use of com.google.gerrit.extensions.api.changes.AddReviewerInput in project gerrit by GerritCodeReview.

the class ChangeReviewersByEmailIT method reviewerAndCCReceiveRegularNotification.

@Test
public void reviewerAndCCReceiveRegularNotification() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    AccountInfo acc = new AccountInfo("Foo Bar", "foo.bar@gerritcodereview.com");
    for (ReviewerState state : ImmutableList.of(ReviewerState.CC, ReviewerState.REVIEWER)) {
        PushOneCommit.Result r = createChange();
        AddReviewerInput input = new AddReviewerInput();
        input.reviewer = toRfcAddressString(acc);
        input.state = state;
        gApi.changes().id(r.getChangeId()).addReviewer(input);
        sender.clear();
        gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
        if (state == ReviewerState.CC) {
            assertNotifyCc(Address.parse(input.reviewer));
        } else {
            assertNotifyTo(Address.parse(input.reviewer));
        }
    }
}
Also used : ReviewerState(com.google.gerrit.extensions.client.ReviewerState) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)45 Test (org.junit.Test)38 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)34 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)30 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)15 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)9 Message (com.google.gerrit.testutil.FakeEmailSender.Message)8 AddReviewerResult (com.google.gerrit.extensions.api.changes.AddReviewerResult)7 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)5 Change (com.google.gerrit.reviewdb.client.Change)5 TestAccount (com.google.gerrit.acceptance.TestAccount)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)4 Account (com.google.gerrit.reviewdb.client.Account)4 Project (com.google.gerrit.reviewdb.client.Project)4 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)4 OrmException (com.google.gwtorm.server.OrmException)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)3 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)3 UpdateException (com.google.gerrit.server.update.UpdateException)3