Search in sources :

Example 6 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class CommentsIT method publishCommentsAllRevisions.

@Test
public void publishCommentsAllRevisions() throws Exception {
    PushOneCommit.Result result = createChange();
    String changeId = result.getChangeId();
    pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "initial content\n", changeId).to("refs/heads/master");
    PushOneCommit.Result r1 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "old boring content\n").to("refs/for/master");
    PushOneCommit.Result r2 = pushFactory.create(admin.newIdent(), testRepo, SUBJECT, FILE_NAME, "new interesting\ncntent\n", r1.getChangeId()).to("refs/for/master");
    addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 10), "Is it that bad?"));
    addDraft(r1.getChangeId(), r1.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, createLineRange(0, 7), "what happened to this?"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, createLineRange(4, 15), "better now"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "typo: content"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 1, "comment 1 on base"));
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.PARENT, 2, "comment 2 on base"));
    PushOneCommit.Result other = createChange();
    // Drafts on other changes aren't returned.
    addDraft(other.getChangeId(), other.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 1, "unrelated comment"));
    requestScopeOperations.setApiUser(admin.id());
    // Drafts by other users aren't returned.
    addDraft(r2.getChangeId(), r2.getCommit().getName(), CommentsUtil.newDraft(FILE_NAME, Side.REVISION, 2, "oops"));
    requestScopeOperations.setApiUser(user.id());
    ReviewInput reviewInput = new ReviewInput();
    reviewInput.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    reviewInput.message = "comments";
    gApi.changes().id(r2.getChangeId()).current().review(reviewInput);
    assertThat(gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).drafts()).isEmpty();
    Map<String, List<CommentInfo>> ps1Map = gApi.changes().id(r1.getChangeId()).revision(r1.getCommit().name()).comments();
    assertThat(ps1Map.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> ps1List = ps1Map.get(FILE_NAME);
    assertThat(ps1List).hasSize(2);
    assertThat(ps1List.get(0).message).isEqualTo("what happened to this?");
    assertThat(ps1List.get(0).side).isEqualTo(Side.PARENT);
    assertThat(ps1List.get(1).message).isEqualTo("Is it that bad?");
    assertThat(ps1List.get(1).side).isNull();
    assertThat(gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).drafts()).isEmpty();
    Map<String, List<CommentInfo>> ps2Map = gApi.changes().id(r2.getChangeId()).revision(r2.getCommit().name()).comments();
    assertThat(ps2Map.keySet()).containsExactly(FILE_NAME);
    List<CommentInfo> ps2List = ps2Map.get(FILE_NAME);
    assertThat(ps2List).hasSize(4);
    assertThat(ps2List.get(0).message).isEqualTo("comment 1 on base");
    assertThat(ps2List.get(1).message).isEqualTo("comment 2 on base");
    assertThat(ps2List.get(2).message).isEqualTo("better now");
    assertThat(ps2List.get(3).message).isEqualTo("typo: content");
    List<Message> messages = email.getMessages(r2.getChangeId(), "comment");
    assertThat(messages).hasSize(1);
    String url = canonicalWebUrl.get();
    int c = r1.getChange().getId().get();
    assertThat(extractComments(messages.get(0).body())).isEqualTo("Patch Set 2:\n" + "\n" + "(6 comments)\n" + "\n" + "comments\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(0).id + " \n" + "PS1, Line 1: initial\n" + "what happened to this?\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps1List.get(1).id + " \n" + "PS1, Line 1: boring\n" + "Is it that bad?\n" + "\n" + "\n" + "File a.txt:\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(0).id + " \n" + "PS2, Line 1: initial content\n" + "comment 1 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(1).id + " \n" + "PS2, Line 2: \n" + "comment 2 on base\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(2).id + " \n" + "PS2, Line 1: interesting\n" + "better now\n" + "\n" + "\n" + url + "c/" + project.get() + "/+/" + c + "/comment/" + ps2List.get(3).id + " \n" + "PS2, Line 2: cntent\n" + "typo: content\n" + "\n" + "\n");
}
Also used : Message(com.google.gerrit.testing.FakeEmailSender.Message) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class RevertIT method revertSubmissionPreservesReviewersAndCcs.

@Test
public void revertSubmissionPreservesReviewersAndCcs() throws Exception {
    String change = createChange("first change", "a.txt", "message").getChangeId();
    ReviewInput in = ReviewInput.approve();
    in.reviewer(user.email());
    in.reviewer(accountCreator.user2().email(), ReviewerState.CC, true);
    // Add user as reviewer that will create the revert
    in.reviewer(accountCreator.admin2().email());
    gApi.changes().id(change).current().review(in);
    gApi.changes().id(change).current().submit();
    // expect both the original reviewers and CCs to be preserved
    // original owner should be added as reviewer, user requesting the revert (new owner) removed
    requestScopeOperations.setApiUser(accountCreator.admin2().id());
    Map<ReviewerState, Collection<AccountInfo>> result = getChangeApis(gApi.changes().id(change).revertSubmission()).get(0).get().reviewers;
    assertThat(result).containsKey(ReviewerState.REVIEWER);
    List<Integer> reviewers = result.get(ReviewerState.REVIEWER).stream().map(a -> a._accountId).collect(toList());
    assertThat(result).containsKey(ReviewerState.CC);
    List<Integer> ccs = result.get(ReviewerState.CC).stream().map(a -> a._accountId).collect(toList());
    assertThat(ccs).containsExactly(accountCreator.user2().id().get());
    assertThat(reviewers).containsExactly(user.id().get(), admin.id().get());
}
Also used : TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) PureRevertInfo(com.google.gerrit.extensions.common.PureRevertInfo) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) ChangeUtil(com.google.gerrit.server.ChangeUtil) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) TestRepository(org.eclipse.jgit.junit.TestRepository) RevertInput(com.google.gerrit.extensions.api.changes.RevertInput) RevertSubmissionInfo(com.google.gerrit.extensions.common.RevertSubmissionInfo) RefSpec(org.eclipse.jgit.transport.RefSpec) Collection(java.util.Collection) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) PermissionDeniedException(com.google.gerrit.server.permissions.PermissionDeniedException) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Collection(java.util.Collection) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 8 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class RevertIT method revertNotifications.

@Test
public void revertNotifications() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).addReviewer(user.email());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).submit();
    sender.clear();
    ChangeInfo revertChange = gApi.changes().id(r.getChangeId()).revert().get();
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(2);
    assertThat(sender.getMessages(revertChange.changeId, "newchange")).hasSize(1);
    assertThat(sender.getMessages(r.getChangeId(), "revert")).hasSize(1);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 9 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class ChangeReviewersIT method addCcGroup.

@Test
public void addCcGroup() throws Exception {
    List<TestAccount> users = createAccounts(6, "addCcGroup");
    List<String> usernames = new ArrayList<>(6);
    for (TestAccount u : users) {
        usernames.add(u.username());
    }
    List<TestAccount> firstUsers = users.subList(0, 3);
    List<String> firstUsernames = usernames.subList(0, 3);
    PushOneCommit.Result r = createChange();
    String changeId = r.getChangeId();
    ReviewerInput in = new ReviewerInput();
    in.reviewer = groupOperations.newGroup().name("cc1").create().get();
    in.state = CC;
    gApi.groups().id(in.reviewer).addMembers(firstUsernames.toArray(new String[firstUsernames.size()]));
    ReviewerResult result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    assertThat(result.reviewers).isNull();
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, CC, firstUsers);
    // Verify emails were sent to each of the group's accounts.
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    List<Address> expectedAddresses = new ArrayList<>(firstUsers.size());
    for (TestAccount u : firstUsers) {
        expectedAddresses.add(u.getNameEmail());
    }
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
    // CC a group that overlaps with some existing reviewers and CCed accounts.
    TestAccount reviewer = accountCreator.create(name("reviewer"), "addCcGroup-reviewer@example.com", "Reviewer", null);
    result = addReviewer(changeId, reviewer.username());
    assertThat(result.error).isNull();
    sender.clear();
    in.reviewer = groupOperations.newGroup().name("cc2").create().get();
    gApi.groups().id(in.reviewer).addMembers(usernames.toArray(new String[usernames.size()]));
    gApi.groups().id(in.reviewer).addMembers(reviewer.username());
    result = addReviewer(changeId, in);
    assertThat(result.input).isEqualTo(in.reviewer);
    assertThat(result.confirm).isNull();
    assertThat(result.error).isNull();
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(result.ccs).hasSize(3);
    assertThat(result.reviewers).isNull();
    assertReviewers(c, REVIEWER, reviewer);
    assertReviewers(c, CC, users);
    messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    m = messages.get(0);
    expectedAddresses = new ArrayList<>(4);
    for (int i = 0; i < 3; i++) {
        expectedAddresses.add(users.get(users.size() - i - 1).getNameEmail());
    }
    expectedAddresses.add(reviewer.getNameEmail());
    assertThat(m.rcpt()).containsExactlyElementsIn(expectedAddresses);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Message(com.google.gerrit.testing.FakeEmailSender.Message) Address(com.google.gerrit.entities.Address) ReviewerResult(com.google.gerrit.extensions.api.changes.ReviewerResult) ArrayList(java.util.ArrayList) 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)

Example 10 with Message

use of com.google.gerrit.testing.FakeEmailSender.Message in project gerrit by GerritCodeReview.

the class CreateChangeIT method notificationsOnChangeCreation.

@Test
public void notificationsOnChangeCreation() throws Exception {
    requestScopeOperations.setApiUser(user.id());
    watch(project.get());
    // check that watcher is notified
    requestScopeOperations.setApiUser(admin.id());
    assertCreateSucceeds(newChangeInput(ChangeStatus.NEW));
    List<Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    Message m = messages.get(0);
    assertThat(m.rcpt()).containsExactly(user.getNameEmail());
    assertThat(m.body()).contains(admin.fullName() + " has uploaded this change for review.");
    // check that watcher is not notified if notify=NONE
    sender.clear();
    ChangeInput input = newChangeInput(ChangeStatus.NEW);
    input.notify = NotifyHandling.NONE;
    assertCreateSucceeds(input);
    assertThat(sender.getMessages()).isEmpty();
}
Also used : CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Message (com.google.gerrit.testing.FakeEmailSender.Message)56 Test (org.junit.Test)49 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)39 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)35 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)24 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)24 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)15 CommitValidationMessage (com.google.gerrit.server.git.validators.CommitValidationMessage)15 TestAccount (com.google.gerrit.acceptance.TestAccount)13 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)12 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 MailMessage (com.google.gerrit.mail.MailMessage)10 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)9 Address (com.google.gerrit.entities.Address)7 DeleteReviewerInput (com.google.gerrit.extensions.api.changes.DeleteReviewerInput)7 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)7 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)6 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)5 ReviewerState (com.google.gerrit.extensions.client.ReviewerState)5