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);
}
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()));
}
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));
}
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");
}
Aggregations