use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class ImpersonationIT method voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf.
@Test
public void voteUsingRunAsAvoidsRestrictionsOfOnBehalfOf() throws Exception {
allowRunAs();
PushOneCommit.Result r = createChange();
setApiUser(user);
DraftInput di = new DraftInput();
di.path = Patch.COMMIT_MSG;
di.side = Side.REVISION;
di.line = 1;
di.message = "inline comment";
gApi.changes().id(r.getChangeId()).current().createDraft(di);
setApiUser(admin);
// Things that aren't allowed with on_behalf_of:
// - no labels.
// - publish other user's drafts.
ReviewInput in = new ReviewInput();
in.message = "message";
in.drafts = DraftHandling.PUBLISH;
RestResponse res = adminRestSession.postWithHeader("/changes/" + r.getChangeId() + "/revisions/current/review", in, runAsHeader(user.id));
res.assertOK();
ChangeMessageInfo m = Iterables.getLast(gApi.changes().id(r.getChangeId()).get().messages);
assertThat(m.message).endsWith(in.message);
assertThat(m.author._accountId).isEqualTo(user.id.get());
CommentInfo c = Iterables.getOnlyElement(gApi.changes().id(r.getChangeId()).comments().get(di.path));
assertThat(c.author._accountId).isEqualTo(user.id.get());
assertThat(c.message).isEqualTo(di.message);
setApiUser(user);
assertThat(gApi.changes().id(r.getChangeId()).drafts()).isEmpty();
}
use of com.google.gerrit.extensions.api.changes.DraftInput 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 = 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.DraftInput in project gerrit by GerritCodeReview.
the class CommentsIT method putDraft.
@Test
public void putDraft() throws Exception {
for (Integer line : lines) {
PushOneCommit.Result r = createChange();
Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String path = "file1";
DraftInput comment = newDraft(path, Side.REVISION, line, "comment 1");
addDraft(changeId, revId, comment);
Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
String uuid = actual.id;
comment.message = "updated comment 1";
updateDraft(changeId, revId, comment, uuid);
result = getDraftComments(changeId, revId);
actual = Iterables.getOnlyElement(result.get(comment.path));
assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
// Posting a draft comment doesn't cause lastUpdatedOn to change.
assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
}
}
use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class CommentsIT method listDrafts.
@Test
public void listDrafts() throws Exception {
String file = "file";
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
assertThat(getDraftComments(changeId, revId)).isEmpty();
List<DraftInput> expectedDrafts = new ArrayList<>();
for (Integer line : lines) {
DraftInput comment = newDraft(file, Side.REVISION, line, "comment " + line);
expectedDrafts.add(comment);
addDraft(changeId, revId, comment);
}
Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
assertThat(result).isNotEmpty();
List<CommentInfo> actualComments = result.get(file);
assertThat(Lists.transform(actualComments, infoToDraft(file))).containsExactlyElementsIn(expectedDrafts);
}
use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.
the class CommentsIT method getDraft.
@Test
public void getDraft() throws Exception {
for (Integer line : lines) {
PushOneCommit.Result r = createChange();
String changeId = r.getChangeId();
String revId = r.getCommit().getName();
String path = "file1";
DraftInput comment = newDraft(path, Side.REVISION, line, "comment 1");
CommentInfo returned = addDraft(changeId, revId, comment);
CommentInfo actual = getDraftComment(changeId, revId, returned.id);
assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
}
}
Aggregations