Merge "Populate comment parentUuid field"

This commit is contained in:
ekempin
2017-01-26 07:34:31 +00:00
committed by Gerrit Code Review
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 @Test
public void postCommentWithUnresolved() throws Exception { public void postCommentWithUnresolved() throws Exception {
for (Integer line : lines) { for (Integer line : lines) {
@@ -786,5 +820,6 @@ public class CommentsIT extends AbstractDaemonTest {
to.message = from.message; to.message = from.message;
to.range = from.range; to.range = from.range;
to.unresolved = from.unresolved; to.unresolved = from.unresolved;
to.inReplyTo = from.inReplyTo;
} }
} }

View File

@@ -208,7 +208,18 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
public void publishedComment() throws Exception { public void publishedComment() throws Exception {
PushOneCommit.Result r = createChange(); PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey(); 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); checker.rebuildAndCheckChanges(id);
} }
@@ -242,7 +253,7 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
PushOneCommit.Result r = createChange(); PushOneCommit.Result r = createChange();
Change.Id id = r.getPatchSetId().getParentKey(); Change.Id id = r.getPatchSetId().getParentKey();
putDraft(user, id, 1, "draft comment", null); putDraft(user, id, 1, "draft comment", null);
putComment(user, id, 1, "published comment"); putComment(user, id, 1, "published comment", null);
checker.rebuildAndCheckChanges(id); checker.rebuildAndCheckChanges(id);
} }
@@ -1283,11 +1294,12 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
} }
} }
private void putComment(TestAccount account, Change.Id id, int line, String msg) private void putComment(TestAccount account, Change.Id id, int line,
throws Exception { String msg, String inReplyTo) throws Exception {
CommentInput in = new CommentInput(); CommentInput in = new CommentInput();
in.line = line; in.line = line;
in.message = msg; in.message = msg;
in.inReplyTo = inReplyTo;
ReviewInput rin = new ReviewInput(); ReviewInput rin = new ReviewInput();
rin.comments = new HashMap<>(); rin.comments = new HashMap<>();
rin.comments.put(PushOneCommit.FILE_NAME, ImmutableList.of(in)); rin.comments.put(PushOneCommit.FILE_NAME, ImmutableList.of(in));
@@ -1348,4 +1360,8 @@ public class ChangeRebuilderIT extends AbstractDaemonTest {
saveProjectConfig(allProjects, cfg); 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()), new Comment.Key(ChangeUtil.messageUuid(), path, psId.get()),
ctx.getUser().getAccountId(), ctx.getWhen(), side, message, serverId, ctx.getUser().getAccountId(), ctx.getWhen(), side, message, serverId,
unresolved); unresolved);
c.parentUuid = parentUuid;
ctx.getUser().updateRealAccountId(c::setRealAuthor); ctx.getUser().updateRealAccountId(c::setRealAuthor);
return c; return c;
} }