use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method reviewAndAddReviewers.
@Test
public void reviewAndAddReviewers() throws Exception {
TestAccount observer = accounts.user2();
PushOneCommit.Result r = createChange();
ReviewInput input = ReviewInput.approve().reviewer(user.email).reviewer(observer.email, CC, false);
ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
assertThat(result.labels).isNotNull();
assertThat(result.reviewers).isNotNull();
assertThat(result.reviewers).hasSize(2);
// Verify reviewer and CC were added. If not in NoteDb read mode, both
// parties will be returned as CCed.
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
if (notesMigration.readChanges()) {
assertReviewers(c, REVIEWER, admin, user);
assertReviewers(c, CC, observer);
} else {
// In legacy mode, everyone should be a reviewer.
assertReviewers(c, REVIEWER, admin, user, observer);
assertReviewers(c, CC);
}
// Verify emails were sent to added reviewers.
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(2);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.emailAddress, observer.emailAddress);
assertThat(m.body()).contains(admin.fullName + " has posted comments on this change.");
assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
assertThat(m.body()).contains("Patch Set 1: Code-Review+2");
m = messages.get(1);
assertThat(m.rcpt()).containsExactly(user.emailAddress, observer.emailAddress);
assertThat(m.body()).contains("Hello " + user.fullName + ",\n");
assertThat(m.body()).contains("I'd like you to do a code review.");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ChangeReviewersIT method assertReviewers.
private static void assertReviewers(ChangeInfo c, ReviewerState reviewerState, TestAccount... accounts) throws Exception {
List<TestAccount> accountList = new ArrayList<>(accounts.length);
for (TestAccount a : accounts) {
accountList.add(a);
}
assertReviewers(c, reviewerState, accountList);
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method defaultReviewerSuggestion.
@Test
public void defaultReviewerSuggestion() throws Exception {
TestAccount user1 = user("customuser1", "User1");
TestAccount reviewer1 = user("customuser2", "User2");
TestAccount reviewer2 = user("customuser3", "User3");
setApiUser(user1);
String changeId1 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId1);
setApiUser(user1);
String changeId2 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId2);
setApiUser(reviewer2);
reviewChange(changeId2);
setApiUser(user1);
String changeId3 = createChangeFromApi();
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId3, null, 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get()).inOrder();
// check that existing reviewers are filtered out
gApi.changes().id(changeId3).addReviewer(reviewer1.email);
reviewers = suggestReviewers(changeId3, null, 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer2.id.get()).inOrder();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method reviewerRankingProjectIsolation.
@Test
public void reviewerRankingProjectIsolation() throws Exception {
// Create new project
Project.NameKey newProject = createProject("test");
// Create users who review changes in both the default and the new project
String fullName = "Primum Finalis";
TestAccount userWhoOwns = user("customuser1", fullName);
TestAccount reviewer1 = user("customuser2", fullName);
TestAccount reviewer2 = user("customuser3", fullName);
setApiUser(userWhoOwns);
String changeId1 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId1);
setApiUser(userWhoOwns);
String changeId2 = createChangeFromApi(newProject);
setApiUser(reviewer2);
reviewChange(changeId2);
setApiUser(userWhoOwns);
String changeId3 = createChangeFromApi(newProject);
setApiUser(reviewer2);
reviewChange(changeId3);
setApiUser(userWhoOwns);
List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Prim", 4);
// Assert that reviewer1 is on top, even though reviewer2 has more reviews
// in other projects
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get()).inOrder();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchProjectNotifyOnPrivateChange.
@Test
public void watchProjectNotifyOnPrivateChange() throws Exception {
String watchedProject = createProject("watchedProject").get();
// create group that can view all private changes
GroupInfo groupThatCanViewPrivateChanges = gApi.groups().create("groupThatCanViewPrivateChanges").get();
grant(new Project.NameKey(watchedProject), "refs/*", Permission.VIEW_PRIVATE_CHANGES, false, new AccountGroup.UUID(groupThatCanViewPrivateChanges.id));
// watch project as user that can't view private changes
setApiUser(user);
watch(watchedProject, null);
// watch project as user that can view all private change
TestAccount userThatCanViewPrivateChanges = accounts.create("user2", "user2@test.com", "User2", groupThatCanViewPrivateChanges.name);
setApiUser(userThatCanViewPrivateChanges);
watch(watchedProject, null);
// push a private change to watched project -> should trigger email notification for
// userThatCanViewPrivateChanges, but not for user
setApiUser(admin);
TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER", "a", "a1").to("refs/for/master%private");
r.assertOkStatus();
// assert email notification
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(userThatCanViewPrivateChanges.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
Aggregations