Search in sources :

Example 36 with TestAccount

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");
}
Also used : InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Message(com.google.gerrit.testing.FakeEmailSender.Message) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 37 with TestAccount

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();
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 38 with TestAccount

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());
}
Also used : TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors(java.util.stream.Collectors) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) EmailFormat(com.google.gerrit.extensions.client.GeneralPreferencesInfo.EmailFormat) ArrayList(java.util.ArrayList) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) List(java.util.List) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) ArrayList(java.util.ArrayList) TestAccount(com.google.gerrit.acceptance.TestAccount) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 39 with TestAccount

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);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) TestAccount(com.google.gerrit.acceptance.TestAccount) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 40 with TestAccount

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();
}
Also used : Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) 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)

Aggregations

TestAccount (com.google.gerrit.acceptance.TestAccount)137 Test (org.junit.Test)122 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)106 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)54 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)19 AbstractNotificationTest (com.google.gerrit.acceptance.AbstractNotificationTest)15 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)14 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)13 ArrayList (java.util.ArrayList)13 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)12 AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)10 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)10 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)10 Message (com.google.gerrit.testing.FakeEmailSender.Message)10 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)9 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)9 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)9 AuthException (com.google.gerrit.extensions.restapi.AuthException)9 AttentionSetUpdate (com.google.gerrit.entities.AttentionSetUpdate)8 Change (com.google.gerrit.entities.Change)8