Search in sources :

Example 6 with DraftInput

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();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 7 with DraftInput

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");
}
Also used : DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 8 with DraftInput

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);
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 9 with DraftInput

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);
}
Also used : ArrayList(java.util.ArrayList) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 10 with DraftInput

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));
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)20 Test (org.junit.Test)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 IdString (com.google.gerrit.extensions.restapi.IdString)7 Change (com.google.gerrit.reviewdb.client.Change)7 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)3 Timestamp (java.sql.Timestamp)3 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)2 MoreObjects (com.google.common.base.MoreObjects)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1