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();
}
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()));
}
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());
}
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);
}
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);
}
Aggregations