Search in sources :

Example 1 with DeleteChangeMessageInput

use of com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput 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 2 with DeleteChangeMessageInput

use of com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput in project gerrit by GerritCodeReview.

the class ChangeMessagesIT method getChangeMessagesWithTemplate.

@Test
public void getChangeMessagesWithTemplate() throws Exception {
    String changeId = createChange().getChangeId();
    String messageTemplate = "Review by " + AccountTemplateUtil.getAccountTemplate(admin.id());
    postMessage(changeId, messageTemplate);
    assertMessage(messageTemplate, Iterables.getLast(gApi.changes().id(changeId).get(MESSAGES).messages).message);
    Collection<ChangeMessageInfo> listMessages = gApi.changes().id(changeId).messages();
    assertThat(listMessages).hasSize(2);
    ChangeMessageInfo changeMessageApi = Iterables.getLast(gApi.changes().id(changeId).messages());
    assertMessage("Review by " + admin.getNameEmail(), changeMessageApi.message);
    assertMessage("Review by " + admin.getNameEmail(), gApi.changes().id(changeId).message(changeMessageApi.id).get().message);
    DeleteChangeMessageInput input = new DeleteChangeMessageInput("message deleted");
    assertThat(gApi.changes().id(changeId).message(changeMessageApi.id).delete(input).message).isEqualTo(String.format("Change message removed by: %s\nReason: message deleted", admin.getNameEmail()));
}
Also used : ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 3 with DeleteChangeMessageInput

use of com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput in project gerrit by GerritCodeReview.

the class ChangeMessagesIT method deleteCannotBeAppliedWithNonExistingChangeMessageUuid.

@Test
public void deleteCannotBeAppliedWithNonExistingChangeMessageUuid() throws Exception {
    String changeId = createChange().getChangeId();
    DeleteChangeMessageInput input = new DeleteChangeMessageInput();
    String id = "8473b95934b5732ac55d26311a706c9c2bde9941";
    input.reason = "spam";
    ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).message(id).delete(input));
    assertThat(thrown).hasMessageThat().isEqualTo(String.format("change message %s not found", id));
}
Also used : DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 4 with DeleteChangeMessageInput

use of com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput in project gerrit by GerritCodeReview.

the class ChangeMessagesIT method deleteCannotBeAppliedWithEmptyChangeMessageUuid.

@Test
public void deleteCannotBeAppliedWithEmptyChangeMessageUuid() throws Exception {
    String changeId = createChange().getChangeId();
    ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.changes().id(changeId).message("").delete(new DeleteChangeMessageInput("spam")));
    assertThat(thrown).hasMessageThat().isEqualTo("change message  not found");
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) DeleteChangeMessageInput(com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 DeleteChangeMessageInput (com.google.gerrit.extensions.api.changes.DeleteChangeMessageInput)4 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)3 Test (org.junit.Test)3 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)2 Strings (com.google.common.base.Strings)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)1 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)1 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 FILE_NAME (com.google.gerrit.acceptance.PushOneCommit.FILE_NAME)1 TestAccount (com.google.gerrit.acceptance.TestAccount)1 UseClockStep (com.google.gerrit.acceptance.UseClockStep)1 UseTimezone (com.google.gerrit.acceptance.UseTimezone)1 ProjectOperations (com.google.gerrit.acceptance.testsuite.project.ProjectOperations)1 TestProjectUpdate.allowCapability (com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allowCapability)1 RequestScopeOperations (com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations)1