Search in sources :

Example 11 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class CommentsIT method createDraft.

@Test
public void createDraft() 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");
        addDraft(changeId, revId, comment);
        Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
        assertThat(result).hasSize(1);
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        assertThat(comment).isEqualTo(infoToDraft(path).apply(actual));
    }
}
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) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 12 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class RevisionIT method drafts.

@Test
public void drafts() throws Exception {
    PushOneCommit.Result r = createChange();
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = FILE_NAME;
    DraftApi draftApi = gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).createDraft(in);
    assertThat(draftApi.get().message).isEqualTo(in.message);
    assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).draft(draftApi.get().id).get().message).isEqualTo(in.message);
    assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).drafts()).hasSize(1);
    in.message = "good catch!";
    assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).draft(draftApi.get().id).update(in).message).isEqualTo(in.message);
    assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).draft(draftApi.get().id).get().author.email).isEqualTo(admin.email);
    draftApi.delete();
    assertThat(gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).drafts()).isEmpty();
}
Also used : DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 13 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class ImpersonationIT method voteOnBehalfOfCannotModifyDrafts.

@Test
public void voteOnBehalfOfCannotModifyDrafts() throws Exception {
    allowCodeReviewOnBehalfOf();
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    DraftInput di = new DraftInput();
    di.path = Patch.COMMIT_MSG;
    di.side = Side.REVISION;
    di.line = 1;
    di.message = "message";
    gApi.changes().id(r.getChangeId()).current().createDraft(di);
    setApiUser(admin);
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id.toString();
    in.label("Code-Review", 1);
    in.drafts = DraftHandling.PUBLISH;
    exception.expect(AuthException.class);
    exception.expectMessage("not allowed to modify other user's drafts");
    gApi.changes().id(r.getChangeId()).current().review(in);
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) 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 14 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class CommentsIT method deleteDraft.

@Test
public void deleteDraft() 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();
        DraftInput draft = newDraft("file1", Side.REVISION, line, "comment 1");
        CommentInfo returned = addDraft(changeId, revId, draft);
        deleteDraft(changeId, revId, returned.id);
        Map<String, List<CommentInfo>> drafts = getDraftComments(changeId, revId);
        assertThat(drafts).isEmpty();
        // Deleting 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 15 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class CommentsIT method createDraftOnMergeCommitChange.

@Test
public void createDraftOnMergeCommitChange() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createMergeCommitChange("refs/for/master");
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        String path = "file1";
        DraftInput c1 = newDraft(path, Side.REVISION, line, "ps-1");
        DraftInput c2 = newDraft(path, Side.PARENT, line, "auto-merge of ps-1");
        DraftInput c3 = newDraftOnParent(path, 1, line, "parent-1 of ps-1");
        DraftInput c4 = newDraftOnParent(path, 2, line, "parent-2 of ps-1");
        addDraft(changeId, revId, c1);
        addDraft(changeId, revId, c2);
        addDraft(changeId, revId, c3);
        addDraft(changeId, revId, c4);
        Map<String, List<CommentInfo>> result = getDraftComments(changeId, revId);
        assertThat(result).hasSize(1);
        assertThat(Lists.transform(result.get(path), infoToDraft(path))).containsExactly(c1, c2, c3, c4);
    }
}
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) 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