Search in sources :

Example 41 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class AccountIT method addExistingReviewersUsingPostReview.

@Test
public void addExistingReviewersUsingPostReview() throws Exception {
    PushOneCommit.Result r = createChange();
    // First reviewer added to the change
    ReviewInput input = new ReviewInput();
    input.reviewers = new ArrayList<>(1);
    ReviewerInput reviewerInput = new ReviewerInput();
    reviewerInput.reviewer = user.email();
    input.reviewers.add(reviewerInput);
    gApi.changes().id(r.getChangeId()).current().review(input);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message message = messages.get(0);
    assertThat(message.rcpt()).containsExactly(user.getNameEmail());
    assertMailReplyTo(message, admin.email());
    sender.clear();
    // Second reviewer and existing reviewer added to the change
    ReviewInput input2 = new ReviewInput();
    input2.reviewers = new ArrayList<>(2);
    ReviewerInput reviewerInput2 = new ReviewerInput();
    reviewerInput2.reviewer = user.email();
    input2.reviewers.add(reviewerInput2);
    ReviewerInput reviewerInput3 = new ReviewerInput();
    TestAccount user2 = accountCreator.user2();
    reviewerInput3.reviewer = user2.email();
    input2.reviewers.add(reviewerInput3);
    gApi.changes().id(r.getChangeId()).current().review(input2);
    List<Message> messages2 = sender.getMessages();
    assertThat(messages2).hasSize(1);
    Message message2 = messages2.get(0);
    assertThat(message2.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail());
    assertMailReplyTo(message, admin.email());
    sender.clear();
    // Existing reviewers re-added to the change: no notifications
    ReviewInput input3 = new ReviewInput();
    input3.reviewers = new ArrayList<>(2);
    ReviewerInput reviewerInput4 = new ReviewerInput();
    reviewerInput4.reviewer = user.email();
    input3.reviewers.add(reviewerInput4);
    ReviewerInput reviewerInput5 = new ReviewerInput();
    reviewerInput5.reviewer = user2.email();
    input3.reviewers.add(reviewerInput5);
    gApi.changes().id(r.getChangeId()).current().review(input3);
    List<Message> messages3 = sender.getMessages();
    assertThat(messages3).isEmpty();
}
Also used : Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 42 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method deleteVote.

@Test
public void deleteVote() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    requestScopeOperations.setApiUser(user.id());
    recommend(r.getChangeId());
    requestScopeOperations.setApiUser(admin.id());
    sender.clear();
    gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).deleteVote(LabelId.CODE_REVIEW);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message msg = messages.get(0);
    assertThat(msg.rcpt()).containsExactly(user.getNameEmail());
    assertThat(msg.body()).contains(admin.fullName() + " has removed a vote from this change.");
    assertThat(msg.body()).contains("Removed Code-Review+1 by " + user.fullName() + " <" + user.email() + ">\n");
    Map<String, Short> m = gApi.changes().id(r.getChangeId()).reviewer(user.id().toString()).votes();
    // Dummy 0 approval on the change to block vote copying to this patch set.
    assertThat(m).containsExactly(LabelId.CODE_REVIEW, Short.valueOf((short) 0));
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    ChangeMessageInfo message = Iterables.getLast(c.messages);
    assertThat(message.author._accountId).isEqualTo(admin.id().get());
    assertThat(message.message).isEqualTo("Removed Code-Review+1 by " + AccountTemplateUtil.getAccountTemplate(user.id()) + "\n");
    assertThat(message.accountsInMessage).containsExactly(getAccountInfo(user.id()));
    assertThat(gApi.changes().id(r.getChangeId()).message(message.id).get().message).isEqualTo("Removed Code-Review+1 by User1 <user1@example.com>\n");
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.id(), user.id()));
}
Also used : 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) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 43 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method testRemoveReviewer.

private void testRemoveReviewer(boolean notify) throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.approve());
    requestScopeOperations.setApiUser(user.id());
    gApi.changes().id(changeId).revision(r.getCommit().name()).review(ReviewInput.recommend());
    Collection<AccountInfo> reviewers = gApi.changes().id(changeId).get().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());
    sender.clear();
    requestScopeOperations.setApiUser(admin.id());
    DeleteReviewerInput input = new DeleteReviewerInput();
    if (!notify) {
        input.notify = NotifyHandling.NONE;
    }
    gApi.changes().id(changeId).reviewer(user.id().toString()).remove(input);
    if (notify) {
        assertThat(sender.getMessages()).hasSize(1);
        Message message = sender.getMessages().get(0);
        assertThat(message.body()).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
        assertThat(message.body()).contains("* Code-Review+1 by " + user.getNameEmail());
        ChangeMessageInfo changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).messages());
        assertThat(changeMessageInfo.message).contains("Removed reviewer " + user.getNameEmail() + " with the following votes");
        assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + user.getNameEmail());
        changeMessageInfo = Iterables.getLast(gApi.changes().id(changeId).get().messages);
        assertThat(changeMessageInfo.message).contains("Removed reviewer " + AccountTemplateUtil.getAccountTemplate(user.id()) + " with the following votes");
        assertThat(changeMessageInfo.message).contains("* Code-Review+1 by " + AccountTemplateUtil.getAccountTemplate(user.id()));
        assertThat(changeMessageInfo.accountsInMessage).containsExactly(getAccountInfo(user.id()));
    } else {
        assertThat(sender.getMessages()).isEmpty();
    }
    reviewers = gApi.changes().id(changeId).get().reviewers.get(REVIEWER);
    assertThat(reviewers).hasSize(1);
    reviewerIt = reviewers.iterator();
    assertThat(reviewerIt.next()._accountId).isEqualTo(admin.id().get());
    eventRecorder.assertReviewerDeletedEvents(changeId, user.email());
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AccountInfo(com.google.gerrit.extensions.common.AccountInfo)

Example 44 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method addGroupAsReviewersWhenANotPerfectMatchedUserExists.

@Test
@UseClockStep
public void addGroupAsReviewersWhenANotPerfectMatchedUserExists() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    // create a group named "kobe" with one user: lee
    String testUserFullname = "kobebryant";
    accountOperations.newAccount().username("kobebryant").preferredEmail("kobebryant@example.com").fullname(testUserFullname).create();
    String myGroupUserEmail = "lee@example.com";
    String myGroupUserFullname = "lee";
    Account.Id accountIdOfGroupUser = accountOperations.newAccount().username("lee").preferredEmail(myGroupUserEmail).fullname(myGroupUserFullname).create();
    String testGroup = groupOperations.newGroup().name("kobe").create().get();
    GroupApi groupApi = gApi.groups().id(testGroup);
    groupApi.description("test group");
    groupApi.addMembers(myGroupUserFullname);
    // ensure that user "user" is not in the group
    groupApi.removeMembers(testUserFullname);
    ReviewerInput in = new ReviewerInput();
    in.reviewer = testGroup;
    gApi.changes().id(r.getChangeId()).addReviewer(in.reviewer);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(Address.create(myGroupUserFullname, myGroupUserEmail));
    assertThat(m.body()).contains("Hello " + myGroupUserFullname + ",\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, myGroupUserEmail);
    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(accountIdOfGroupUser.get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) 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) ChangeResource(com.google.gerrit.server.change.ChangeResource) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) 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) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 45 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeIT method addReviewerThatIsNotPerfectMatch.

@Test
@UseClockStep
public void addReviewerThatIsNotPerfectMatch() throws Exception {
    PushOneCommit.Result r = createChange();
    ChangeResource rsrc = parseResource(r);
    String oldETag = rsrc.getETag();
    Instant oldTs = rsrc.getChange().getLastUpdatedOn();
    // create a group named "ab" with one user: testUser
    String email = "abcd@example.com";
    String fullname = "abcd";
    Account.Id accountIdOfTestUser = accountOperations.newAccount().username("abcd").preferredEmail(email).fullname(fullname).create();
    String testGroup = groupOperations.newGroup().name("ab").create().get();
    GroupApi groupApi = gApi.groups().id(testGroup);
    groupApi.description("test group");
    groupApi.addMembers(user.fullName());
    ReviewerInput in = new ReviewerInput();
    in.reviewer = "abc";
    gApi.changes().id(r.getChangeId()).addReviewer(in.reviewer);
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(Address.create(fullname, email));
    assertThat(m.body()).contains("Hello " + 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, 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(accountIdOfTestUser.get());
    // Ensure ETag and lastUpdatedOn are updated.
    rsrc = parseResource(r);
    assertThat(rsrc.getETag()).isNotEqualTo(oldETag);
    assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Account(com.google.gerrit.entities.Account) 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) ChangeResource(com.google.gerrit.server.change.ChangeResource) GroupApi(com.google.gerrit.extensions.api.groups.GroupApi) 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) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Aggregations

Message (com.google.gerrit.testing.FakeEmailSender.Message)56 Test (org.junit.Test)49 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)39 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)35 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)24 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)24 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)15 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)15 TestAccount (com.google.gerrit.acceptance.TestAccount)13 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)12 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 MailMessage (com.google.gerrit.mail.MailMessage)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)9 Address (com.google.gerrit.entities.Address)7 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)7 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)7 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)5