use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentNotesFormatWeirdUser.
@Test
public void patchLineCommentNotesFormatWeirdUser() throws Exception {
Account.Builder account = Account.builder(Account.id(3), TimeUtil.now());
account.setFullName("Weird\n\u0002<User>\n");
account.setPreferredEmail(" we\r\nird@ex>ample<.com");
accountCache.put(account.build());
IdentifiedUser user = userFactory.create(Account.id(3));
Change c = newChange();
ChangeUpdate update = newUpdate(c, user);
String uuid = "uuid";
CommentRange range = new CommentRange(1, 1, 2, 1);
Instant time = TimeUtil.now();
PatchSet.Id psId = c.currentPatchSetId();
HumanComment comment = newComment(psId, "file1", uuid, range, range.getEndLine(), user, null, time, "comment", (short) 1, ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234"), false);
update.setPatchSetId(psId);
update.putComment(HumanComment.Status.PUBLISHED, comment);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(comment.getCommitId(), comment));
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentNotesFormatMultiplePatchSetsSameCommitId.
@Test
public void patchLineCommentNotesFormatMultiplePatchSetsSameCommitId() throws Exception {
Change c = newChange();
PatchSet.Id psId1 = c.currentPatchSetId();
incrementPatchSet(c);
PatchSet.Id psId2 = c.currentPatchSetId();
String uuid1 = "uuid1";
String uuid2 = "uuid2";
String uuid3 = "uuid3";
String message1 = "comment 1";
String message2 = "comment 2";
String message3 = "comment 3";
CommentRange range1 = new CommentRange(1, 1, 2, 1);
CommentRange range2 = new CommentRange(2, 1, 3, 1);
Instant time = TimeUtil.now();
ObjectId commitId = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
HumanComment comment1 = newComment(psId1, "file1", uuid1, range1, range1.getEndLine(), otherUser, null, time, message1, (short) 0, commitId, false);
HumanComment comment2 = newComment(psId1, "file1", uuid2, range2, range2.getEndLine(), otherUser, null, time, message2, (short) 0, commitId, false);
HumanComment comment3 = newComment(psId2, "file1", uuid3, range1, range1.getEndLine(), otherUser, null, time, message3, (short) 0, commitId, false);
ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId2);
update.putComment(HumanComment.Status.PUBLISHED, comment3);
update.putComment(HumanComment.Status.PUBLISHED, comment2);
update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getHumanComments()).isEqualTo(ImmutableListMultimap.of(commitId, comment1, commitId, comment2, commitId, comment3));
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class CommentTimestampAdapterTest method newAdapterRoundTripOfWholeComment.
@Test
public void newAdapterRoundTripOfWholeComment() {
Comment c = new HumanComment(new Comment.Key("uuid", "filename", 1), Account.id(100), NON_DST_TS.toInstant(), (short) 0, "message", "serverId", false);
c.lineNbr = 1;
c.setCommitId(ObjectId.fromString("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
String json = gson.toJson(c);
assertThat(json).contains("\"writtenOn\": \"" + NON_DST_STR_TRUNC + "\",");
Comment result = gson.fromJson(json, HumanComment.class);
// Round-trip lossily truncates ms, but that's ok.
assertThat(result.writtenOn).isEqualTo(NON_DST_TS_TRUNC);
result.writtenOn = NON_DST_TS;
assertThat(result).isEqualTo(c);
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentMultipleDraftsSameSidePublishOne.
@Test
public void patchLineCommentMultipleDraftsSameSidePublishOne() throws Exception {
Change c = newChange();
String uuid1 = "uuid1";
String uuid2 = "uuid2";
ObjectId commitId = ObjectId.fromString("abcd4567abcd4567abcd4567abcd4567abcd4567");
CommentRange range1 = new CommentRange(1, 1, 2, 2);
CommentRange range2 = new CommentRange(2, 2, 3, 3);
String filename = "filename1";
short side = (short) 1;
Instant now = TimeUtil.now();
PatchSet.Id psId = c.currentPatchSetId();
// Write two drafts on the same side of one patch set.
ChangeUpdate update = newUpdate(c, otherUser);
update.setPatchSetId(psId);
HumanComment comment1 = newComment(psId, filename, uuid1, range1, range1.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId, false);
HumanComment comment2 = newComment(psId, filename, uuid2, range2, range2.getEndLine(), otherUser, null, now, "other on ps1", side, commitId, false);
update.putComment(HumanComment.Status.DRAFT, comment1);
update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1, commitId, comment2)).inOrder();
assertThat(notes.getHumanComments()).isEmpty();
// Publish first draft.
update = newUpdate(c, otherUser);
update.setPatchSetId(psId);
update.putComment(HumanComment.Status.PUBLISHED, comment1);
update.commit();
notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment2));
assertThat(notes.getHumanComments()).containsExactlyEntriesIn(ImmutableListMultimap.of(commitId, comment1));
}
use of com.google.gerrit.entities.HumanComment in project gerrit by GerritCodeReview.
the class ChangeNotesTest method patchLineCommentsDeleteAllDraftsForOneRevision.
@Test
public void patchLineCommentsDeleteAllDraftsForOneRevision() throws Exception {
Change c = newChange();
String uuid = "uuid";
ObjectId commitId1 = ObjectId.fromString("abcd1234abcd1234abcd1234abcd1234abcd1234");
ObjectId commitId2 = ObjectId.fromString("abcd4567abcd4567abcd4567abcd4567abcd4567");
CommentRange range = new CommentRange(1, 1, 2, 1);
PatchSet.Id ps1 = c.currentPatchSetId();
String filename = "filename1";
short side = (short) 1;
ChangeUpdate update = newUpdate(c, otherUser);
Instant now = TimeUtil.now();
HumanComment comment1 = newComment(ps1, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps1", side, commitId1, false);
update.setPatchSetId(ps1);
update.putComment(HumanComment.Status.DRAFT, comment1);
update.commit();
incrementPatchSet(c);
PatchSet.Id ps2 = c.currentPatchSetId();
update = newUpdate(c, otherUser);
now = TimeUtil.now();
HumanComment comment2 = newComment(ps2, filename, uuid, range, range.getEndLine(), otherUser, null, now, "comment on ps2", side, commitId2, false);
update.setPatchSetId(ps2);
update.putComment(HumanComment.Status.DRAFT, comment2);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).hasSize(2);
update = newUpdate(c, otherUser);
update.setPatchSetId(ps2);
update.deleteComment(comment2);
update.commit();
notes = newNotes(c);
assertThat(notes.getDraftComments(otherUserId)).hasSize(1);
NoteMap noteMap = notes.getDraftCommentNotes().getNoteMap();
assertThat(noteMap.contains(commitId1)).isTrue();
assertThat(noteMap.contains(commitId2)).isFalse();
}
Aggregations