Search in sources :

Example 1 with DraftInput

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

the class DeleteDraftPatchSetIT method deleteDraftPatchSetAndChange.

@Test
public void deleteDraftPatchSetAndChange() throws Exception {
    String changeId = createDraftChangeWith2PS();
    PatchSet ps = getCurrentPatchSet(changeId);
    Change.Id id = ps.getId().getParentKey();
    DraftInput din = new DraftInput();
    din.path = "a.txt";
    din.message = "comment on a.txt";
    gApi.changes().id(changeId).current().createDraft(din);
    if (notesMigration.commitChangeWrites()) {
        assertThat(getDraftRef(admin, id)).isNotNull();
    }
    ChangeData cd = getChange(changeId);
    assertThat(cd.patchSets()).hasSize(2);
    assertThat(cd.change().currentPatchSetId().get()).isEqualTo(2);
    assertThat(cd.change().getStatus()).isEqualTo(Change.Status.DRAFT);
    deletePatchSet(changeId, ps);
    cd = getChange(changeId);
    assertThat(cd.patchSets()).hasSize(1);
    assertThat(cd.change().currentPatchSetId().get()).isEqualTo(1);
    ps = getCurrentPatchSet(changeId);
    deletePatchSet(changeId, ps);
    assertThat(queryProvider.get().byKeyPrefix(changeId)).isEmpty();
    if (notesMigration.commitChangeWrites()) {
        assertThat(getDraftRef(admin, id)).isNull();
        assertThat(getMetaRef(id)).isNull();
    }
    exception.expect(ResourceNotFoundException.class);
    gApi.changes().id(id.get());
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with DraftInput

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

the class ChangeRebuilderIT method rebuildEntitiesCreatedByImpersonation.

@Test
public void rebuildEntitiesCreatedByImpersonation() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getPatchSetId().getParentKey();
    PatchSet.Id psId = new PatchSet.Id(id, 1);
    String prefix = "/changes/" + id + "/revisions/current/";
    // For each of the entities that have a real user field, create one entity
    // without impersonation and one with.
    CommentInput ci = new CommentInput();
    ci.path = Patch.COMMIT_MSG;
    ci.side = Side.REVISION;
    ci.line = 1;
    ci.message = "comment without impersonation";
    ReviewInput ri = new ReviewInput();
    ri.label("Code-Review", -1);
    ri.message = "message without impersonation";
    ri.drafts = DraftHandling.KEEP;
    ri.comments = ImmutableMap.of(ci.path, ImmutableList.of(ci));
    userRestSession.post(prefix + "review", ri).assertOK();
    DraftInput di = new DraftInput();
    di.path = Patch.COMMIT_MSG;
    di.side = Side.REVISION;
    di.line = 1;
    di.message = "draft without impersonation";
    userRestSession.put(prefix + "drafts", di).assertCreated();
    allowRunAs();
    try {
        Header runAs = new BasicHeader("X-Gerrit-RunAs", user.id.toString());
        ci.message = "comment with impersonation";
        ri.message = "message with impersonation";
        ri.label("Code-Review", 1);
        adminRestSession.postWithHeader(prefix + "review", ri, runAs).assertOK();
        di.message = "draft with impersonation";
        adminRestSession.putWithHeader(prefix + "drafts", runAs, di).assertCreated();
    } finally {
        removeRunAs();
    }
    List<ChangeMessage> msgs = Ordering.natural().onResultOf(ChangeMessage::getWrittenOn).sortedCopy(db.changeMessages().byChange(id));
    assertThat(msgs).hasSize(3);
    assertThat(msgs.get(1).getMessage()).endsWith("message without impersonation");
    assertThat(msgs.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(1).getRealAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(2).getMessage()).endsWith("message with impersonation");
    assertThat(msgs.get(2).getAuthor()).isEqualTo(user.id);
    assertThat(msgs.get(2).getRealAuthor()).isEqualTo(admin.id);
    List<PatchSetApproval> psas = db.patchSetApprovals().byChange(id).toList();
    assertThat(psas).hasSize(1);
    assertThat(psas.get(0).getLabel()).isEqualTo("Code-Review");
    assertThat(psas.get(0).getValue()).isEqualTo(1);
    assertThat(psas.get(0).getAccountId()).isEqualTo(user.id);
    assertThat(psas.get(0).getRealAccountId()).isEqualTo(admin.id);
    Ordering<PatchLineComment> commentOrder = Ordering.natural().onResultOf(PatchLineComment::getWrittenOn);
    List<PatchLineComment> drafts = commentOrder.sortedCopy(db.patchComments().draftByPatchSetAuthor(psId, user.id));
    assertThat(drafts).hasSize(2);
    assertThat(drafts.get(0).getMessage()).isEqualTo("draft without impersonation");
    assertThat(drafts.get(0).getAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(0).getRealAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(1).getMessage()).isEqualTo("draft with impersonation");
    assertThat(drafts.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(drafts.get(1).getRealAuthor()).isEqualTo(admin.id);
    List<PatchLineComment> pub = commentOrder.sortedCopy(db.patchComments().publishedByPatchSet(psId));
    assertThat(pub).hasSize(2);
    assertThat(pub.get(0).getMessage()).isEqualTo("comment without impersonation");
    assertThat(pub.get(0).getAuthor()).isEqualTo(user.id);
    assertThat(pub.get(0).getRealAuthor()).isEqualTo(user.id);
    assertThat(pub.get(1).getMessage()).isEqualTo("comment with impersonation");
    assertThat(pub.get(1).getAuthor()).isEqualTo(user.id);
    assertThat(pub.get(1).getRealAuthor()).isEqualTo(admin.id);
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchLineComment(com.google.gerrit.reviewdb.client.PatchLineComment) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) ObjectId(org.eclipse.jgit.lib.ObjectId) BasicHeader(org.apache.http.message.BasicHeader) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with DraftInput

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

the class AbstractQueryChangesTest method byDraftBy.

@Test
public void byDraftBy() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(change1.getId().get()).current().createDraft(in);
    in = new DraftInput();
    in.line = 2;
    in.message = "nit: point in the end of the statement";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(change2.getId().get()).current().createDraft(in);
    int user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser")).getAccountId().get();
    assertQuery("draftby:" + userId.get(), change2, change1);
    assertQuery("draftby:" + user2);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 4 with DraftInput

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

the class AbstractPushForReview method newDraft.

private DraftInput newDraft(String path, int line, String message) {
    DraftInput d = new DraftInput();
    d.path = path;
    d.side = Side.REVISION;
    d.line = line;
    d.message = message;
    d.unresolved = true;
    return d;
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput)

Example 5 with DraftInput

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

the class AbstractQueryChangesTest method byDraftByExcludesZombieDrafts.

@Test
public void byDraftByExcludesZombieDrafts() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    Project.NameKey project = new Project.NameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    Change change = insert(repo, newChange(repo));
    Change.Id id = change.getId();
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(id.get()).current().createDraft(in);
    assertQuery("draftby:" + userId, change);
    assertQuery("commentby:" + userId);
    TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
    Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
    assertThat(draftsRef).isNotNull();
    ReviewInput rin = ReviewInput.dislike();
    rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    gApi.changes().id(id.get()).current().review(rin);
    assertQuery("draftby:" + userId);
    assertQuery("commentby:" + userId, change);
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
    // Re-add drafts ref and ensure it gets filtered out during indexing.
    allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
    if (PrimaryStorage.of(change) == PrimaryStorage.REVIEW_DB && !notesMigration.disableChangeReviewDb()) {
        // Record draft ref in noteDbState as well.
        ReviewDb db = ReviewDbUtil.unwrapDb(this.db);
        change = db.changes().get(id);
        NoteDbChangeState.applyDelta(change, NoteDbChangeState.Delta.create(id, Optional.empty(), ImmutableMap.of(userId, draftsRef.getObjectId())));
        db.changes().update(Collections.singleton(change));
    }
    indexer.index(db, project, id);
    assertQuery("draftby:" + userId);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Ref(org.eclipse.jgit.lib.Ref) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) 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