use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class SuggestReviewersIT method reviewerRanking.
@Test
@GerritConfig(name = "suggest.maxSuggestedReviewers", value = "10")
public void reviewerRanking() throws Exception {
// Assert that user are ranked by the number of times they have applied a
// a label to a change (highest), added comments (medium) or owned a
// change (low).
String fullName = "Primum Finalis";
TestAccount userWhoOwns = user("customuser1", fullName);
TestAccount reviewer1 = user("customuser2", fullName);
TestAccount reviewer2 = user("customuser3", fullName);
TestAccount userWhoComments = user("customuser4", fullName);
TestAccount userWhoLooksForSuggestions = user("customuser5", fullName);
// Create a change as userWhoOwns and add some reviews
setApiUser(userWhoOwns);
String changeId1 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId1);
setApiUser(user1);
String changeId2 = createChangeFromApi();
setApiUser(reviewer1);
reviewChange(changeId2);
setApiUser(reviewer2);
reviewChange(changeId2);
// Create a comment as a different user
setApiUser(userWhoComments);
ReviewInput ri = new ReviewInput();
ri.message = "Test";
gApi.changes().id(changeId1).revision(1).review(ri);
// Create a change as a new user to assert that we receive the correct
// ranking
setApiUser(userWhoLooksForSuggestions);
List<SuggestedReviewerInfo> reviewers = suggestReviewers(createChangeFromApi(), "Pri", 4);
assertThat(reviewers.stream().map(r -> r.account._accountId).collect(toList())).containsExactly(reviewer1.id.get(), reviewer2.id.get(), userWhoOwns.id.get(), userWhoComments.id.get()).inOrder();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchFileAllProjects.
@Test
public void watchFileAllProjects() throws Exception {
String anyProject = createProject("anyProject").get();
setApiUser(user);
// watch file in All-Projects project as user to watch the file in all
// projects
watch(allProjects.get(), "file:a.txt");
// push a change to watched file in any project -> should trigger email
// notification for user
setApiUser(admin);
TestRepository<InMemoryRepository> anyRepo = cloneProject(new Project.NameKey(anyProject), admin);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), anyRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// watch project as user2
TestAccount user2 = accounts.create("user2", "user2@test.com", "User2");
setApiUser(user2);
watch(anyProject, null);
// push a change to non-watched file in any project -> should not trigger
// email notification for user, only for user2
r = pushFactory.create(db, admin.getIdent(), anyRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user2.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchFile.
@Test
public void watchFile() throws Exception {
String watchedProject = createProject("watchedProject").get();
String otherWatchedProject = createProject("otherWatchedProject").get();
setApiUser(user);
// watch file in project as user
watch(watchedProject, "file:a.txt");
// watch other project as user
watch(otherWatchedProject, null);
// push a change to watched file -> should trigger email notification for
// user
setApiUser(admin);
TestRepository<InMemoryRepository> watchedRepo = cloneProject(new Project.NameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER", "a.txt", "a1").to("refs/for/master");
r.assertOkStatus();
// assert email notification for user
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// watch project as user2
TestAccount user2 = accounts.create("user2", "user2@test.com", "User2");
setApiUser(user2);
watch(watchedProject, null);
// push a change to non-watched file -> should not trigger email
// notification for user, only for user2
r = pushFactory.create(db, admin.getIdent(), watchedRepo, "TRIGGER_USER2", "b.txt", "b1").to("refs/for/master");
r.assertOkStatus();
// assert email notification
messages = sender.getMessages();
assertThat(messages).hasSize(1);
m = messages.get(0);
assertThat(m.rcpt()).containsExactly(user2.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER_USER2\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ProjectWatchIT method watchProjectNotifyOnDraftChange.
@Test
public void watchProjectNotifyOnDraftChange() throws Exception {
String watchedProject = createProject("watchedProject").get();
// create group that can view all drafts
GroupInfo groupThatCanViewDrafts = gApi.groups().create("groupThatCanViewDrafts").get();
grant(new Project.NameKey(watchedProject), "refs/*", Permission.VIEW_DRAFTS, false, new AccountGroup.UUID(groupThatCanViewDrafts.id));
// watch project as user that can't view drafts
setApiUser(user);
watch(watchedProject, null);
// watch project as user that can view all drafts
TestAccount userThatCanViewDrafts = accounts.create("user2", "user2@test.com", "User2", groupThatCanViewDrafts.name);
setApiUser(userThatCanViewDrafts);
watch(watchedProject, null);
// push a draft change to watched project -> should trigger email notification for
// userThatCanViewDrafts, 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%draft");
r.assertOkStatus();
// assert email notification
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(userThatCanViewDrafts.emailAddress);
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class ConsistencyCheckerIT method missingOwner.
@Test
public void missingOwner() throws Exception {
TestAccount owner = accounts.create("missing");
ChangeControl ctl = insertChange(owner);
accountsUpdate.create().deleteByKey(db, owner.getId());
assertProblems(ctl, null, problem("Missing change owner: " + owner.getId()));
}
Aggregations