Search in sources :

Example 1 with MESSAGES

use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES 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 MESSAGES

use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.

the class ChangeEditIT method assertChangeMessages.

private void assertChangeMessages(String changeId, List<String> expectedMessages) throws Exception {
    ChangeInfo ci = get(changeId, MESSAGES);
    assertThat(ci.messages).isNotNull();
    assertThat(ci.messages).hasSize(expectedMessages.size());
    List<String> actualMessages = ci.messages.stream().map(message -> message.message).collect(toList());
    assertThat(actualMessages).containsExactlyElementsIn(expectedMessages).inOrder();
}
Also used : Patch(com.google.gerrit.entities.Patch) TypeToken(com.google.gson.reflect.TypeToken) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) FileContentInput(com.google.gerrit.extensions.api.changes.FileContentInput) RevWalk(org.eclipse.jgit.revwalk.RevWalk) LabelType(com.google.gerrit.entities.LabelType) ChangeEditDetailOption(com.google.gerrit.extensions.client.ChangeEditDetailOption) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) Post(com.google.gerrit.server.restapi.change.ChangeEdits.Post) RawInput(com.google.gerrit.extensions.restapi.RawInput) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) 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) List(java.util.List) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) EditInfo(com.google.gerrit.extensions.common.EditInfo) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) Iterables(com.google.common.collect.Iterables) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) RawInputUtil(com.google.gerrit.common.RawInputUtil) EditMessage(com.google.gerrit.server.restapi.change.ChangeEdits.EditMessage) BinaryResultSubject.assertThat(com.google.gerrit.extensions.restapi.testing.BinaryResultSubject.assertThat) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) TestLabels(com.google.gerrit.server.project.testing.TestLabels) JsonReader(com.google.gson.stream.JsonReader) CURRENT_COMMIT(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_COMMIT) ReviewerInput(com.google.gerrit.extensions.api.changes.ReviewerInput) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) FileInfo(com.google.gerrit.extensions.common.FileInfo) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) Before(org.junit.Before) TestRepository(org.eclipse.jgit.junit.TestRepository) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Permission(com.google.gerrit.entities.Permission) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) Collectors.toList(java.util.stream.Collectors.toList) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Project(com.google.gerrit.entities.Project) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) Repository(org.eclipse.jgit.lib.Repository) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo)

Example 3 with MESSAGES

use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.

the class RobotCommentsIT method addedRobotCommentsAreLinkedToChangeMessages.

@UseClockStep
@Test
public void addedRobotCommentsAreLinkedToChangeMessages() throws Exception {
    // Advancing the time after creating the change so that the first robot comment is not in the
    // same timestamp as with the change creation.
    TestTimeUtil.incrementClock(10, TimeUnit.SECONDS);
    RobotCommentInput c1 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    RobotCommentInput c2 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    RobotCommentInput c3 = TestCommentHelper.createRobotCommentInput(FILE_NAME);
    // Give the robot comments identifiable names for testing
    c1.message = "robot comment 1";
    c2.message = "robot comment 2";
    c3.message = "robot comment 3";
    testCommentHelper.addRobotComment(changeId, c1, "robot message 1");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    testCommentHelper.addRobotComment(changeId, c2, "robot message 2");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    testCommentHelper.addRobotComment(changeId, c3, "robot message 3");
    TestTimeUtil.incrementClock(5, TimeUnit.SECONDS);
    Map<String, List<RobotCommentInfo>> robotComments = gApi.changes().id(changeId).robotComments();
    List<RobotCommentInfo> robotCommentsList = robotComments.values().stream().flatMap(List::stream).collect(toList());
    List<ChangeMessageInfo> allMessages = gApi.changes().id(changeId).get(MESSAGES).messages.stream().collect(toList());
    assertThat(allMessages.stream().map(cm -> cm.message).collect(toList())).containsExactly("Uploaded patch set 1.", "Patch Set 1:\n\n(1 comment)\n\nrobot message 1", "Patch Set 1:\n\n(1 comment)\n\nrobot message 2", "Patch Set 1:\n\n(1 comment)\n\nrobot message 3");
    assertThat(robotCommentsList.stream().map(c -> c.message).collect(toList())).containsExactly("robot comment 1", "robot comment 2", "robot comment 3");
    String message1ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 1")).collect(onlyElement()).id;
    String message2ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 2")).collect(onlyElement()).id;
    String message3ChangeId = allMessages.stream().filter(c -> c.message.contains("robot message 3")).collect(onlyElement()).id;
    String comment1MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 1")).collect(onlyElement()).changeMessageId;
    String comment2MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 2")).collect(onlyElement()).changeMessageId;
    String comment3MessageId = robotCommentsList.stream().filter(c -> c.message.equals("robot comment 3")).collect(onlyElement()).changeMessageId;
    /**
     * All change messages have the auto-generated tag. Robot comments can be linked to
     * auto-generated messages where each comment is linked to the next nearest change message in
     * timestamp
     */
    assertThat(message1ChangeId).isEqualTo(comment1MessageId);
    assertThat(message2ChangeId).isEqualTo(comment2MessageId);
    assertThat(message3ChangeId).isEqualTo(comment3MessageId);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Patch(com.google.gerrit.entities.Patch) Arrays(java.util.Arrays) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) MoreCollectors.onlyElement(com.google.common.collect.MoreCollectors.onlyElement) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Map(java.util.Map) Side(com.google.gerrit.extensions.client.Side) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) ChangeOperations(com.google.gerrit.acceptance.testsuite.change.ChangeOperations) ImmutableMap(com.google.common.collect.ImmutableMap) IntraLineStatus(com.google.gerrit.extensions.common.DiffInfo.IntraLineStatus) COMMIT_MSG(com.google.gerrit.entities.Patch.COMMIT_MSG) Objects(java.util.Objects) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) BinaryResultSubject(com.google.gerrit.extensions.restapi.testing.BinaryResultSubject) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) FixSuggestionInfo(com.google.gerrit.extensions.common.FixSuggestionInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) EditInfo(com.google.gerrit.extensions.common.EditInfo) Iterables(com.google.common.collect.Iterables) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) Comment(com.google.gerrit.extensions.client.Comment) PATCHSET_LEVEL(com.google.gerrit.entities.Patch.PATCHSET_LEVEL) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) DiffInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.DiffInfoSubject.assertThat) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) TestCommentHelper(com.google.gerrit.testing.TestCommentHelper) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) TestTimeUtil(com.google.gerrit.testing.TestTimeUtil) Before(org.junit.Before) FixReplacementInfo(com.google.gerrit.extensions.common.FixReplacementInfo) PublishChangeEditInput(com.google.gerrit.extensions.api.changes.PublishChangeEditInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) TimeUnit(java.util.concurrent.TimeUnit) ChangeType(com.google.gerrit.extensions.common.ChangeType) Collectors.toList(java.util.stream.Collectors.toList) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Collections(java.util.Collections) EditInfoSubject.assertThat(com.google.gerrit.extensions.common.testing.EditInfoSubject.assertThat) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) RobotCommentInfoSubject.assertThatList(com.google.gerrit.extensions.common.testing.RobotCommentInfoSubject.assertThatList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toList(java.util.stream.Collectors.toList) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RobotCommentInfo(com.google.gerrit.extensions.common.RobotCommentInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test) UseClockStep(com.google.gerrit.acceptance.UseClockStep)

Example 4 with MESSAGES

use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.

the class ChangeMessagesIT method deleteOneChangeMessage.

private void deleteOneChangeMessage(int changeNum, int deletedMessageIndex, TestAccount deletedBy, String reason) throws Exception {
    List<ChangeMessageInfo> messagesBeforeDeletion = gApi.changes().id(changeNum).messages();
    List<CommentInfo> commentsBefore = getChangeSortedComments(changeNum);
    List<RevCommit> commitsBefore = getChangeMetaCommitsInReverseOrder(Change.id(changeNum));
    String id = messagesBeforeDeletion.get(deletedMessageIndex).id;
    DeleteChangeMessageInput input = new DeleteChangeMessageInput(reason);
    ChangeMessageInfo info = gApi.changes().id(changeNum).message(id).delete(input);
    // Verify the return change message info is as expect.
    String expectedMessage = "Change message removed by: " + deletedBy.getNameEmail();
    if (!Strings.isNullOrEmpty(reason)) {
        expectedMessage = expectedMessage + "\nReason: " + reason;
    }
    assertThat(info.message).isEqualTo(expectedMessage);
    List<ChangeMessageInfo> messagesAfterDeletion = gApi.changes().id(changeNum).messages();
    assertMessagesAfterDeletion(messagesBeforeDeletion, messagesAfterDeletion, deletedMessageIndex, expectedMessage);
    assertCommentsAfterDeletion(changeNum, commentsBefore);
    // Verify change index is updated after deletion.
    List<ChangeInfo> changes = gApi.changes().query("message removed").get();
    assertThat(changes.stream().map(c -> c._number).collect(toSet())).contains(changeNum);
    // Verifies states of commits.
    assertMetaCommitsAfterDeletion(commitsBefore, changeNum, id, deletedBy, reason);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) UseTimezone(com.google.gerrit.acceptance.UseTimezone) ChangeNoteUtil.parseCommitMessageRange(com.google.gerrit.server.notedb.ChangeNoteUtil.parseCommitMessageRange) Lists(com.google.common.collect.Lists) Charset(java.nio.charset.Charset) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) AuthException(com.google.gerrit.extensions.restapi.AuthException) Change(com.google.gerrit.entities.Change) RawParseUtils.decode(org.eclipse.jgit.util.RawParseUtils.decode) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Collectors.toSet(java.util.stream.Collectors.toSet) TestProjectUpdate.allowCapability(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Iterator(java.util.Iterator) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) RawParseUtils(org.eclipse.jgit.util.RawParseUtils) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) UseClockStep(com.google.gerrit.acceptance.UseClockStep) List(java.util.List) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) DETAILED_ACCOUNTS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_ACCOUNTS) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 5 with MESSAGES

use of com.google.gerrit.extensions.client.ListChangesOption.MESSAGES in project gerrit by GerritCodeReview.

the class NoteDbOnlyIT method retryOnLockFailureWithAtomicUpdates.

@Test
public void retryOnLockFailureWithAtomicUpdates() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    String master = "refs/heads/master";
    ObjectId initial;
    try (Repository repo = repoManager.openRepository(project)) {
        ensureAtomicTransactions(repo);
        initial = repo.exactRef(master).getObjectId();
    }
    AtomicInteger updateRepoCalledCount = new AtomicInteger();
    AtomicInteger updateChangeCalledCount = new AtomicInteger();
    AtomicInteger afterUpdateReposCalledCount = new AtomicInteger();
    String result = retryHelper.changeUpdate("testUpdateRefAndAddMessageOp", batchUpdateFactory -> {
        try (BatchUpdate bu = newBatchUpdate(batchUpdateFactory)) {
            bu.addOp(id, new UpdateRefAndAddMessageOp(updateRepoCalledCount, updateChangeCalledCount));
            bu.execute(new ConcurrentWritingListener(afterUpdateReposCalledCount));
        }
        return "Done";
    }).call();
    assertThat(result).isEqualTo("Done");
    assertThat(updateRepoCalledCount.get()).isEqualTo(2);
    assertThat(afterUpdateReposCalledCount.get()).isEqualTo(2);
    assertThat(updateChangeCalledCount.get()).isEqualTo(2);
    List<String> messages = getMessages(id);
    assertThat(Iterables.getLast(messages)).isEqualTo(UpdateRefAndAddMessageOp.CHANGE_MESSAGE);
    assertThat(Collections.frequency(messages, UpdateRefAndAddMessageOp.CHANGE_MESSAGE)).isEqualTo(1);
    try (Repository repo = repoManager.openRepository(project)) {
        // Op lost the race, so the other writer's commit happened first. Then op retried and wrote
        // its commit with the other writer's commit as parent.
        assertThat(commitMessages(repo, initial, repo.exactRef(master).getObjectId())).containsExactly(ConcurrentWritingListener.MSG_PREFIX + "1", UpdateRefAndAddMessageOp.COMMIT_MESSAGE).inOrder();
    }
}
Also used : Iterables(com.google.common.collect.Iterables) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Inject(com.google.inject.Inject) RepoContext(com.google.gerrit.server.update.RepoContext) Callable(java.util.concurrent.Callable) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ConfigSuite(com.google.gerrit.testing.ConfigSuite) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) NoSuchChangeException(com.google.gerrit.server.project.NoSuchChangeException) RetryHelper(com.google.gerrit.server.update.RetryHelper) Change(com.google.gerrit.entities.Change) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeContext(com.google.gerrit.server.update.ChangeContext) BatchUpdateListener(com.google.gerrit.server.update.BatchUpdateListener) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) RefUpdate(org.eclipse.jgit.lib.RefUpdate) RevSort(org.eclipse.jgit.revwalk.RevSort) IOException(java.io.IOException) Constants(org.eclipse.jgit.lib.Constants) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Streams(com.google.common.collect.Streams) ObjectId(org.eclipse.jgit.lib.ObjectId) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Ref(org.eclipse.jgit.lib.Ref) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.entities.Change) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) Repository(org.eclipse.jgit.lib.Repository) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ImmutableMap (com.google.common.collect.ImmutableMap)5 Iterables (com.google.common.collect.Iterables)5 Truth.assertThat (com.google.common.truth.Truth.assertThat)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)5 Change (com.google.gerrit.entities.Change)5 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)5 MESSAGES (com.google.gerrit.extensions.client.ListChangesOption.MESSAGES)5 Inject (com.google.inject.Inject)5 List (java.util.List)5 Optional (java.util.Optional)5 Test (org.junit.Test)5 ImmutableList (com.google.common.collect.ImmutableList)4 UseClockStep (com.google.gerrit.acceptance.UseClockStep)4 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)4 GerritJUnit.assertThrows (com.google.gerrit.testing.GerritJUnit.assertThrows)4 Collectors.toList (java.util.stream.Collectors.toList)4 RevCommit (org.eclipse.jgit.revwalk.RevCommit)4 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)3 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)3