Populate comment parentUuid field

Also adds regression tests to ensure the inReplyTo field of comments is
respected.

Bug: Issue 5330
Change-Id: I908ceff31315ea963d0c63098a952fb1e613090a
This commit is contained in:
Kasper Nilsson
2017-01-24 11:26:34 -08:00
parent de5dd7a2ef
commit 794e21b8ea
3 changed files with 56 additions and 4 deletions

View File

@@ -149,6 +149,40 @@ public class CommentsIT extends AbstractDaemonTest {
}
}
@Test
public void postCommentWithReply() throws Exception {
for (Integer line : lines) {
String file = "file";
String contents = "contents " + line;
PushOneCommit push = pushFactory.create(db, admin.getIdent(), testRepo,
"first subject", file, contents);
PushOneCommit.Result r = push.to("refs/for/master");
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
ReviewInput input = new ReviewInput();
CommentInput comment =
newComment(file, Side.REVISION, line, "comment 1", false);
input.comments = new HashMap<>();
input.comments.put(comment.path, Lists.newArrayList(comment));
revision(r).review(input);
Map<String, List<CommentInfo>> result =
getPublishedComments(changeId, revId);
CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
input = new ReviewInput();
comment = newComment(file, Side.REVISION, line, "comment 1 reply", false);
comment.inReplyTo = actual.id;
input.comments = new HashMap<>();
input.comments.put(comment.path, Lists.newArrayList(comment));
revision(r).review(input);
result = getPublishedComments(changeId, revId);
actual = result.get(comment.path).get(1);
assertThat(comment).isEqualTo(infoToInput(file).apply(actual));
assertThat(comment).isEqualTo(infoToInput(file).apply(
getPublishedComment(changeId, revId, actual.id)));
}
}
@Test
public void postCommentWithUnresolved() throws Exception {
for (Integer line : lines) {
@@ -786,5 +820,6 @@ public class CommentsIT extends AbstractDaemonTest {
to.message = from.message;
to.range = from.range;
to.unresolved = from.unresolved;
to.inReplyTo = from.inReplyTo;
}
}

View File

@@ -208,7 +208,18 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
public void publishedComment() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
putComment(user, id, 1, "comment");
putComment(user, id, 1, "comment", null);
checker.rebuildAndCheckChanges(id);
}
@Test
public void publishedCommentAndReply() throws Exception {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
putComment(user, id, 1, "comment", null);
Map<String, List<CommentInfo>> comments = getPublishedComments(id);
String parentUuid = comments.get("a.txt").get(0).id;
putComment(user, id, 1, "comment", parentUuid);
checker.rebuildAndCheckChanges(id);
}
@@ -242,7 +253,7 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey();
putDraft(user, id, 1, "draft comment", null);
putComment(user, id, 1, "published comment");
putComment(user, id, 1, "published comment", null);
checker.rebuildAndCheckChanges(id);
}
@@ -1283,11 +1294,12 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
}
}
private void putComment(TestAccount account, Change.Id id, int line, String msg)
throws Exception {
private void putComment(TestAccount account, Change.Id id, int line,
String msg, String inReplyTo) throws Exception {
CommentInput in = new CommentInput();
in.line = line;
in.message = msg;
in.inReplyTo = inReplyTo;
ReviewInput rin = new ReviewInput();
rin.comments = new HashMap<>();
rin.comments.put(PushOneCommit.FILE_NAME, ImmutableList.of(in));
@@ -1348,4 +1360,8 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
saveProjectConfig(allProjects, cfg);
}
private Map<String, List<CommentInfo>> getPublishedComments(Change.Id id)
throws Exception {
return gApi.changes().id(id.get()).current().comments();
}
}

View File

@@ -169,6 +169,7 @@ public class CommentsUtil {
new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()),
ctx.getUser().getAccountId(), ctx.getWhen(), side, message, serverId,
unresolved);
c.parentUuid = parentUuid;
ctx.getUser().updateRealAccountId(c::setRealAuthor);
return c;
}