use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class ChangeRebuilderIT method rebuildEntitiesCreatedByImpersonation.
@Test
public void rebuildEntitiesCreatedByImpersonation() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
PatchSet.Id psId = new PatchSet.Id(id, 1);
String prefix = "/changes/" + id + "/revisions/current/";
// For each of the entities that have a real user field, create one entity
// without impersonation and one with.
CommentInput ci = new CommentInput();
ci.path = Patch.COMMIT_MSG;
ci.side = Side.REVISION;
ci.line = 1;
ci.message = "comment without impersonation";
ReviewInput ri = new ReviewInput();
ri.label("Code-Review", -1);
ri.message = "message without impersonation";
ri.drafts = DraftHandling.KEEP;
ri.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
userRestSession.post(prefix + "review", ri).assertOK();
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "draft without impersonation";
userRestSession.put(prefix + "drafts", di).assertCreated();
allowRunAs();
try {
Header runAs = new BasicHeader("X-Gerrit-RunAs", user.id.toString());
ci.message = "comment with impersonation";
ri.message = "message with impersonation";
ri.label("Code-Review", 1);
adminRestSession.postWithHeader(prefix + "review", ri, runAs).assertOK();
di.message = "draft with impersonation";
adminRestSession.putWithHeader(prefix + "drafts", runAs, di).assertCreated();
} finally {
removeRunAs();
}
List<ChangeMessage> msgs = Ordering.natural().onResultOf(ChangeMessage::getWrittenOn).sortedCopy(db.changeMessages().byChange(id));
assertThat(msgs).hasSize(3);
assertThat(msgs.get(1).getMessage()).endsWith("message without impersonation");
assertThat(msgs.get(1).getAuthor()).isEqualTo(user.id);
assertThat(msgs.get(1).getRealAuthor()).isEqualTo(user.id);
assertThat(msgs.get(2).getMessage()).endsWith("message with impersonation");
assertThat(msgs.get(2).getAuthor()).isEqualTo(user.id);
assertThat(msgs.get(2).getRealAuthor()).isEqualTo(admin.id);
List<PatchSetApproval> psas = db.patchSetApprovals().byChange(id).toList();
assertThat(psas).hasSize(1);
assertThat(psas.get(0).getLabel()).isEqualTo("Code-Review");
assertThat(psas.get(0).getValue()).isEqualTo(1);
assertThat(psas.get(0).getAccountId()).isEqualTo(user.id);
assertThat(psas.get(0).getRealAccountId()).isEqualTo(admin.id);
Ordering<PatchLineComment> commentOrder = Ordering.natural().onResultOf(PatchLineComment::getWrittenOn);
List<PatchLineComment> drafts = commentOrder.sortedCopy(db.patchComments().draftByPatchSetAuthor(psId, user.id));
assertThat(drafts).hasSize(2);
assertThat(drafts.get(0).getMessage()).isEqualTo("draft without impersonation");
assertThat(drafts.get(0).getAuthor()).isEqualTo(user.id);
assertThat(drafts.get(0).getRealAuthor()).isEqualTo(user.id);
assertThat(drafts.get(1).getMessage()).isEqualTo("draft with impersonation");
assertThat(drafts.get(1).getAuthor()).isEqualTo(user.id);
assertThat(drafts.get(1).getRealAuthor()).isEqualTo(admin.id);
List<PatchLineComment> pub = commentOrder.sortedCopy(db.patchComments().publishedByPatchSet(psId));
assertThat(pub).hasSize(2);
assertThat(pub.get(0).getMessage()).isEqualTo("comment without impersonation");
assertThat(pub.get(0).getAuthor()).isEqualTo(user.id);
assertThat(pub.get(0).getRealAuthor()).isEqualTo(user.id);
assertThat(pub.get(1).getMessage()).isEqualTo("comment with impersonation");
assertThat(pub.get(1).getAuthor()).isEqualTo(user.id);
assertThat(pub.get(1).getRealAuthor()).isEqualTo(admin.id);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method commentTags.
@Test
public void commentTags() throws Exception {
PushOneCommit.Result r = createChange();
CommentInput pub = new CommentInput();
pub.line = 1;
pub.message = "published comment";
pub.path = FILE_NAME;
ReviewInput rin = CommentsUtil.newInput(pub);
rin.tag = "tag1";
gApi.changes().id(r.getChangeId()).current().review(rin);
List<CommentInfo> comments = gApi.changes().id(r.getChangeId()).current().commentsAsList();
assertThat(comments).hasSize(1);
assertThat(comments.get(0).tag).isEqualTo("tag1");
DraftInput draft = new DraftInput();
draft.line = 2;
draft.message = "draft comment";
draft.path = FILE_NAME;
draft.tag = "tag2";
addDraft(r.getChangeId(), r.getCommit().name(), draft);
List<CommentInfo> drafts = gApi.changes().id(r.getChangeId()).current().draftsAsList();
assertThat(drafts).hasSize(1);
assertThat(drafts.get(0).tag).isEqualTo("tag2");
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method postCommentsReplacingDrafts.
@Test
public void postCommentsReplacingDrafts() throws Exception {
String file = "file";
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "first subject", file, "contents");
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
DraftInput draft = CommentsUtil.newDraft(file, Side.REVISION, 0, "comment");
addDraft(changeId, revId, draft);
Map<String, List<CommentInfo>> drafts = getDraftComments(changeId, revId);
CommentInfo draftInfo = Iterables.getOnlyElement(drafts.get(draft.path));
ReviewInput reviewInput = new ReviewInput();
reviewInput.drafts = DraftHandling.KEEP;
reviewInput.message = "foo";
CommentInput comment = CommentsUtil.newComment(file, Side.REVISION, 0, "comment", false);
// Replace the existing draft.
comment.id = draftInfo.id;
reviewInput.comments = new HashMap<>();
reviewInput.comments.put(comment.path, ImmutableList.of(comment));
revision(r).review(reviewInput);
// DraftHandling.KEEP is ignored on publishing a comment.
drafts = getDraftComments(changeId, revId);
assertThat(drafts).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method listComments.
@Test
public void listComments() throws Exception {
String file = "file";
PushOneCommit push = pushFactory.create(admin.newIdent(), testRepo, "first subject", file, "contents");
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
assertThat(getPublishedComments(changeId, revId)).isEmpty();
assertThat(getPublishedCommentsAsList(changeId)).isEmpty();
List<CommentInput> expectedComments = new ArrayList<>();
for (Integer line : lines) {
ReviewInput input = new ReviewInput();
CommentInput comment = CommentsUtil.newComment(file, Side.REVISION, line, "comment " + line, false);
expectedComments.add(comment);
input.comments = new HashMap<>();
input.comments.put(comment.path, Lists.newArrayList(comment));
revision(r).review(input);
}
Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
assertThat(result).isNotEmpty();
List<CommentInfo> actualComments = result.get(file);
assertThat(actualComments.stream().map(infoToInput(file))).containsExactlyElementsIn(expectedComments);
List<CommentInfo> list = getPublishedCommentsAsList(changeId);
assertThat(list.stream().map(infoToInput(file))).containsExactlyElementsIn(expectedComments);
}
use of com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput in project gerrit by GerritCodeReview.
the class CommentsIT method patchsetLevelCommentCantHaveLine.
@Test
public void patchsetLevelCommentCantHaveLine() throws Exception {
PushOneCommit.Result result = createChange();
String changeId = result.getChangeId();
String ps1 = result.getCommit().name();
CommentInput input = CommentsUtil.newCommentWithOnlyMandatoryFields(PATCHSET_LEVEL, "comment");
input.line = 1;
BadRequestException ex = assertThrows(BadRequestException.class, () -> CommentsUtil.addComments(gApi, changeId, ps1, input));
assertThat(ex.getMessage()).contains("line");
}
Aggregations