Search in sources :

Example 1 with FILE_NAME

use of com.google.gerrit.acceptance.PushOneCommit.FILE_NAME in project gerrit by GerritCodeReview.

the class AbstractPushForReview method publishCommentsOnPushPublishesDraftsOnAllRevisions.

@Test
public void publishCommentsOnPushPublishesDraftsOnAllRevisions() throws Exception {
    PushOneCommit.Result r = createChange();
    String rev1 = r.getCommit().name();
    CommentInfo c1 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment1"));
    CommentInfo c2 = addDraft(r.getChangeId(), rev1, newDraft(FILE_NAME, 1, "comment2"));
    r = amendChange(r.getChangeId());
    String rev2 = r.getCommit().name();
    CommentInfo c3 = addDraft(r.getChangeId(), rev2, newDraft(FILE_NAME, 1, "comment3"));
    assertThat(getPublishedComments(r.getChangeId())).isEmpty();
    gApi.changes().id(r.getChangeId()).addReviewer(user.email());
    sender.clear();
    amendChange(r.getChangeId(), "refs/for/master%publish-comments");
    Collection<CommentInfo> comments = getPublishedComments(r.getChangeId());
    assertThat(comments.stream().map(c -> c.id)).containsExactly(c1.id, c2.id, c3.id);
    assertThat(comments.stream().map(c -> c.message)).containsExactly("comment1", "comment2", "comment3");
    /* Assert the correctness of the API messages */
    List<ChangeMessageInfo> allMessages = getMessages(r.getChangeId());
    List<String> messagesText = allMessages.stream().map(m -> m.message).collect(toList());
    assertThat(messagesText).containsExactly("Uploaded patch set 1.", "Uploaded patch set 2.", "Uploaded patch set 3.", "Patch Set 3:\n\n(3 comments)").inOrder();
    /* Assert the tags - PS#2 comments do not have tags, PS#3 upload is autogenerated */
    List<String> messagesTags = allMessages.stream().map(m -> m.tag).collect(toList());
    assertThat(messagesTags.get(2)).isEqualTo("autogenerated:gerrit:newPatchSet");
    assertThat(messagesTags.get(3)).isNull();
    /* Assert the correctness of the emails sent */
    List<String> emailMessages = sender.getMessages().stream().map(Message::body).sorted(Comparator.comparingInt(m -> m.contains("reexamine") ? 0 : 1)).collect(toList());
    assertThat(emailMessages).hasSize(2);
    assertThat(emailMessages.get(0)).contains("Gerrit-MessageType: newpatchset");
    assertThat(emailMessages.get(0)).contains("I'd like you to reexamine a change");
    assertThat(emailMessages.get(0)).doesNotContain("Uploaded patch set 3");
    assertThat(emailMessages.get(1)).contains("Gerrit-MessageType: comment");
    assertThat(emailMessages.get(1)).contains("Patch Set 3:\n\n(3 comments)");
    assertThat(emailMessages.get(1)).contains("PS1, Line 1:");
    assertThat(emailMessages.get(1)).contains("PS2, Line 1:");
    /* Assert the correctness of the NoteDb change meta commits */
    List<RevCommit> commitMessages = getChangeMetaCommitsInReverseOrder(r.getChange().getId());
    assertThat(commitMessages).hasSize(5);
    assertThat(commitMessages.get(0).getShortMessage()).isEqualTo("Create change");
    assertThat(commitMessages.get(1).getShortMessage()).isEqualTo("Create patch set 2");
    assertThat(commitMessages.get(2).getShortMessage()).isEqualTo("Update patch set 2");
    assertThat(commitMessages.get(3).getShortMessage()).isEqualTo("Create patch set 3");
    assertThat(commitMessages.get(4).getFullMessage()).isEqualTo("Update patch set 3\n" + "\n" + "Patch Set 3:\n" + "\n" + "(3 comments)\n" + "\n" + "Patch-set: 3\n");
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) CommitReceivedEvent(com.google.gerrit.server.events.CommitReceivedEvent) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TopicEditedListener(com.google.gerrit.extensions.events.TopicEditedListener) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Map(java.util.Map) Side(com.google.gerrit.extensions.client.Side) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Result(org.eclipse.jgit.lib.RefUpdate.Result) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) RefSpec(org.eclipse.jgit.transport.RefSpec) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) RefUpdate(org.eclipse.jgit.lib.RefUpdate) TestLabels.label(com.google.gerrit.server.project.testing.TestLabels.label) TestLabels.value(com.google.gerrit.server.project.testing.TestLabels.value) Collectors.joining(java.util.stream.Collectors.joining) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) UseClockStep(com.google.gerrit.acceptance.UseClockStep) Stream(java.util.stream.Stream) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) PushResult(org.eclipse.jgit.transport.PushResult) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) DETAILED_ACCOUNTS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS) NoteDbPushOption(com.google.gerrit.server.git.receive.NoteDbPushOption) AttentionSetUpdateSubject(com.google.gerrit.extensions.restapi.testing.AttentionSetUpdateSubject) EditInfo(com.google.gerrit.extensions.common.EditInfo) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CHANGE_ID(com.google.gerrit.common.FooterConstants.CHANGE_ID) SkipProjectClone(com.google.gerrit.acceptance.SkipProjectClone) TestLabels(com.google.gerrit.server.project.testing.TestLabels) ArrayList(java.util.ArrayList) ChangeMessage(com.google.gerrit.entities.ChangeMessage) PatchSet(com.google.gerrit.entities.PatchSet) GitUtil(com.google.gerrit.acceptance.GitUtil) Address(com.google.gerrit.entities.Address) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) Before(org.junit.Before) AccountGroup(com.google.gerrit.entities.AccountGroup) TestRepository(org.eclipse.jgit.junit.TestRepository) GitUtil.assertPushRejected(com.google.gerrit.acceptance.GitUtil.assertPushRejected) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) PluginPushOption(com.google.gerrit.server.git.receive.PluginPushOption) CommitValidationListener(com.google.gerrit.server.git.validators.CommitValidationListener) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) GitUtil.assertPushOk(com.google.gerrit.acceptance.GitUtil.assertPushOk) Repository(org.eclipse.jgit.lib.Repository) GitUtil.pushOne(com.google.gerrit.acceptance.GitUtil.pushOne) PUSH_OPTION_SKIP_VALIDATION(com.google.gerrit.server.git.receive.ReceiveConstants.PUSH_OPTION_SKIP_VALIDATION) ALL_REVISIONS(com.google.gerrit.extensions.client.ListChangesOption.ALL_REVISIONS) Inject(com.google.inject.Inject) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LabelType(com.google.gerrit.entities.LabelType) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) After(org.junit.After) RefNames(com.google.gerrit.entities.RefNames) ImmutableSet(com.google.common.collect.ImmutableSet) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) ObjectIds(com.google.gerrit.git.ObjectIds) Streams(com.google.common.collect.Streams) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) ProjectWatchInfo(com.google.gerrit.extensions.client.ProjectWatchInfo) ReceiveConstants(com.google.gerrit.server.git.receive.ReceiveConstants) Optional(java.util.Optional) MoreObjects.firstNonNull(com.google.common.base.MoreObjects.firstNonNull) TestProjectUpdate.allowLabel(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowLabel) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) LabelId(com.google.gerrit.entities.LabelId) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) GeneralPreferencesInfo(com.google.gerrit.extensions.client.GeneralPreferencesInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) Comparator.comparing(java.util.Comparator.comparing) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) TestTimeUtil(com.google.gerrit.testing.TestTimeUtil) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) Permission(com.google.gerrit.entities.Permission) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RemoteRefUpdate(org.eclipse.jgit.transport.RemoteRefUpdate) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Comparator(java.util.Comparator) Collections(java.util.Collections) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ChangeMessage(com.google.gerrit.entities.ChangeMessage) CommitValidationMessage(com.google.gerrit.server.git.validators.CommitValidationMessage) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) Message(com.google.gerrit.testing.FakeEmailSender.Message) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with FILE_NAME

use of com.google.gerrit.acceptance.PushOneCommit.FILE_NAME in project gerrit by GerritCodeReview.

the class CommentsIT method deleteOneCommentMultipleTimes.

@Test
public void deleteOneCommentMultipleTimes() throws Exception {
    PushOneCommit.Result result = createChange();
    Change.Id id = result.getChange().getId();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput c1 = CommentsUtil.newComment(FILE_NAME, "comment 1");
    CommentInput c2 = CommentsUtil.newComment(FILE_NAME, "comment 2");
    CommentInput c3 = CommentsUtil.newComment(FILE_NAME, "comment 3");
    CommentsUtil.addComments(gApi, changeId, ps1, c1);
    CommentsUtil.addComments(gApi, changeId, ps1, c2);
    CommentsUtil.addComments(gApi, changeId, ps1, c3);
    List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(id.get());
    assertThat(commentsBeforeDelete).hasSize(3);
    Optional<CommentInfo> targetComment = commentsBeforeDelete.stream().filter(c -> c.message.equals("comment 2")).findFirst();
    assertThat(targetComment).isPresent();
    String uuid = targetComment.get().id;
    CommentInfo oldComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    List<RevCommit> commitsBeforeDelete = getChangeMetaCommitsInReverseOrder(id);
    requestScopeOperations.setApiUser(admin.id());
    for (int i = 0; i < 3; i++) {
        DeleteCommentInput input = new DeleteCommentInput("delete comment 2, iteration: " + i);
        gApi.changes().id(changeId).revision(ps1).comment(uuid).delete(input);
    }
    CommentInfo updatedComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName(), "delete comment 2, iteration: 2");
    assertThat(updatedComment.message).isEqualTo(expectedMsg);
    oldComment.message = expectedMsg;
    assertThat(updatedComment).isEqualTo(oldComment);
    assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
    assertThat(getChangeSortedComments(id.get())).hasSize(3);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Patch(com.google.gerrit.entities.Patch) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) HumanComment(com.google.gerrit.entities.HumanComment) TestHumanComment(com.google.gerrit.acceptance.testsuite.change.TestHumanComment) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Matcher(java.util.regex.Matcher) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) NoteMap(org.eclipse.jgit.notes.NoteMap) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) PostReview(com.google.gerrit.server.restapi.change.PostReview) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) Account(com.google.gerrit.entities.Account) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) Instant(java.time.Instant) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) NoHttpd(com.google.gerrit.acceptance.NoHttpd) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) List(java.util.List) ChangesCollection(com.google.gerrit.server.restapi.change.ChangesCollection) Ref(org.eclipse.jgit.lib.Ref) MapSubject.assertThatMap(com.google.gerrit.truth.MapSubject.assertThatMap) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Pattern(java.util.regex.Pattern) Iterables(com.google.common.collect.Iterables) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) IdString(com.google.gerrit.extensions.restapi.IdString) RawInputUtil(com.google.gerrit.common.RawInputUtil) HashMap(java.util.HashMap) AccountOperations(com.google.gerrit.acceptance.testsuite.account.AccountOperations) Function(java.util.function.Function) Comment(com.google.gerrit.extensions.client.Comment) ArrayList(java.util.ArrayList) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) FakeEmailSender(com.google.gerrit.testing.FakeEmailSender) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors.toList(java.util.stream.Collectors.toList) DeleteCommentRewriter(com.google.gerrit.server.notedb.DeleteCommentRewriter) Provider(com.google.inject.Provider) Message(com.google.gerrit.testing.FakeEmailSender.Message) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.entities.Change) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 Iterables (com.google.common.collect.Iterables)2 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)2 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)2 FILE_NAME (com.google.gerrit.acceptance.PushOneCommit.FILE_NAME)2 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)2 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)2 Change (com.google.gerrit.entities.Change)2 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)1 Lists (com.google.common.collect.Lists)1 MoreCollectors.onlyElement (com.google.common.collect.MoreCollectors.onlyElement)1 Streams (com.google.common.collect.Streams)1 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 ExtensionRegistry (com.google.gerrit.acceptance.ExtensionRegistry)1