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 = projectOperations.newProject().create().get();
String otherWatchedProject = projectOperations.newProject().create().get();
requestScopeOperations.setApiUser(user.id());
// watch file in project as user
watch(watchedProject, "file:a.txt");
// watch other project as user
watch(otherWatchedProject);
// push a change to watched file -> should trigger email notification for
// user
requestScopeOperations.setApiUser(admin.id());
TestRepository<InMemoryRepository> watchedRepo = cloneProject(Project.nameKey(watchedProject), admin);
PushOneCommit.Result r = pushFactory.create(admin.newIdent(), 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.getNameEmail());
assertThat(m.body()).contains("Change subject: TRIGGER\n");
assertThat(m.body()).contains("Gerrit-PatchSet: 1\n");
sender.clear();
// watch project as user2
TestAccount user2 = accountCreator.create("user2", "user2@example.com", "User2", null);
requestScopeOperations.setApiUser(user2.id());
watch(watchedProject);
// push a change to non-watched file -> should not trigger email
// notification for user, only for user2
r = pushFactory.create(admin.newIdent(), 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.getNameEmail());
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 SetAccountIT method setAccount_deleteExternalId_multiple.
@Test
public void setAccount_deleteExternalId_multiple() throws Exception {
TestAccount testAccount = accountCreator.create("user3", "user3@example.com", null, null);
List<String> extIdKeys = getExternalIdKeys(testAccount);
assertThat(extIdKeys.contains("username:user3")).isTrue();
assertThat(extIdKeys.contains("mailto:user3@example.com")).isTrue();
adminSshSession.exec("gerrit set-account --delete-external-id username:user3 --delete-external-id mailto:user3@example.com user3");
adminSshSession.assertSuccess();
extIdKeys = getExternalIdKeys(testAccount);
assertThat(extIdKeys.contains("username:user3")).isFalse();
assertThat(extIdKeys.contains("mailto:user3@example.com")).isFalse();
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class NotificationMailFormatIT method bccUserIsNotAddedToReplyTo.
@Test
public void bccUserIsNotAddedToReplyTo() throws Exception {
TestAccount bccUser = accountCreator.user2();
List<ProjectWatchInfo> projectsToWatch = new ArrayList<>();
ProjectWatchInfo pwi = new ProjectWatchInfo();
pwi.project = project.get();
pwi.notifyAllComments = true;
projectsToWatch.add(pwi);
gApi.accounts().id(bccUser.id().get()).setWatchedProjects(projectsToWatch);
PushOneCommit.Result r = createChange();
requestScopeOperations.setApiUser(user.id());
gApi.changes().id(r.getChangeId()).current().review(ReviewInput.recommend());
assertThat(sender.getMessages()).hasSize(1);
FakeEmailSender.Message m = sender.getMessages().get(0);
assertMailReplyTo(m, admin.email());
assertMailReplyTo(m, user.email());
assertMailNotReplyTo(m, bccUser.email());
assertThat(m.rcpt().stream().map(a -> a.email()).collect(Collectors.toSet())).contains(bccUser.email());
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class SubmitRequirementsEvaluatorIT method byAuthorEmail.
@Test
public void byAuthorEmail() throws Exception {
TestAccount user2 = accountCreator.create("Foo", "user@example.com", "User", /* displayName = */
null);
requestScopeOperations.setApiUser(user2.id());
ChangeInfo info = gApi.changes().create(new ChangeInput(project.get(), "master", "Test Change")).get();
ChangeData cd = changeQueryProvider.get().byLegacyChangeId(Change.Id.tryParse(Integer.toString(info._number)).get()).get(0);
// Match by email works
checkSubmitRequirementResult(cd, /* submittabilityExpr= */
"authoremail:\"^.*@example\\.com\"", SubmitRequirementResult.Status.SATISFIED);
checkSubmitRequirementResult(cd, /* submittabilityExpr= */
"authoremail:\"^user@.*\\.com\"", SubmitRequirementResult.Status.SATISFIED);
// Match by name does not work
checkSubmitRequirementResult(cd, /* submittabilityExpr= */
"authoremail:\"^Foo$\"", SubmitRequirementResult.Status.UNSATISFIED);
checkSubmitRequirementResult(cd, /* submittabilityExpr= */
"authoremail:\"^User$\"", SubmitRequirementResult.Status.UNSATISFIED);
}
use of com.google.gerrit.acceptance.TestAccount in project gerrit by GerritCodeReview.
the class AccountIT method addExistingReviewersUsingAddReviewer.
@Test
public void addExistingReviewersUsingAddReviewer() throws Exception {
PushOneCommit.Result r = createChange();
// First reviewer added to the change
ReviewerInput reviewerInput = new ReviewerInput();
reviewerInput.reviewer = user.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput);
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 added to the change
TestAccount user2 = accountCreator.user2();
ReviewerInput reviewerInput2 = new ReviewerInput();
reviewerInput2.reviewer = user2.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput2);
List<Message> messages2 = sender.getMessages();
assertThat(messages2).hasSize(1);
Message message2 = messages2.get(0);
assertThat(message2.rcpt()).containsExactly(user.getNameEmail(), user2.getNameEmail());
assertMailReplyTo(message2, admin.email());
sender.clear();
// Exiting reviewer re-added to the change: no notifications
ReviewerInput reviewerInput3 = new ReviewerInput();
reviewerInput3.reviewer = user2.email();
gApi.changes().id(r.getChangeId()).addReviewer(reviewerInput3);
List<Message> messages3 = sender.getMessages();
assertThat(messages3).isEmpty();
}
Aggregations