Search in sources :

Example 1 with RevisionResource

use of com.google.gerrit.server.change.RevisionResource in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method commentPredatingChangeBySomeoneOtherThanOwner.

@Test
public void commentPredatingChangeBySomeoneOtherThanOwner() throws Exception {
    PushOneCommit.Result r = createChange();
    PatchSet.Id psId = r.getPatchSetId();
    Change.Id id = psId.getParentKey();
    Change c = db.changes().get(id);
    ReviewInput rin = new ReviewInput();
    rin.message = "comment";
    Timestamp ts = new Timestamp(c.getCreatedOn().getTime() - 10000);
    RevisionResource revRsrc = parseCurrentRevisionResource(r.getChangeId());
    setApiUser(user);
    postReview.get().apply(batchUpdateFactory, revRsrc, rin, ts);
    checker.rebuildAndCheckChanges(id);
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevisionResource(com.google.gerrit.server.change.RevisionResource) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Timestamp(java.sql.Timestamp) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with RevisionResource

use of com.google.gerrit.server.change.RevisionResource in project gerrit by GerritCodeReview.

the class BaseTestPrologCommand method run.

@Override
protected final void run() throws UnloggedFailure {
    try {
        RevisionResource revision = revisions.parse(changes.parse(TopLevelResource.INSTANCE, IdString.fromUrl(changeId)), IdString.fromUrl("current"));
        if (useStdin) {
            ByteBuffer buf = IO.readWholeStream(in, 4096);
            input.rule = RawParseUtils.decode(buf.array(), buf.arrayOffset(), buf.limit());
        }
        Object result = createView().apply(revision, input);
        OutputFormat.JSON.newGson().toJson(result, stdout);
        stdout.print('\n');
    } catch (Exception e) {
        throw die("Processing of prolog script failed: " + e);
    }
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) ByteBuffer(java.nio.ByteBuffer)

Example 3 with RevisionResource

use of com.google.gerrit.server.change.RevisionResource in project gerrit by GerritCodeReview.

the class AbstractSubmit method assertSubmittable.

protected void assertSubmittable(String changeId) throws Exception {
    assertThat(get(changeId, SUBMITTABLE).submittable).named("submit bit on ChangeInfo").isEqualTo(true);
    RevisionResource rsrc = parseCurrentRevisionResource(changeId);
    UiAction.Description desc = submitHandler.getDescription(rsrc);
    assertThat(desc.isVisible()).named("visible bit on submit action").isTrue();
    assertThat(desc.isEnabled()).named("enabled bit on submit action").isTrue();
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) UiAction(com.google.gerrit.extensions.webui.UiAction)

Example 4 with RevisionResource

use of com.google.gerrit.server.change.RevisionResource in project gerrit by GerritCodeReview.

the class CommentsIT method insertCommentsWithHistoricTimestamp.

@Test
public void insertCommentsWithHistoricTimestamp() throws Exception {
    Timestamp timestamp = new Timestamp(0);
    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();
        Timestamp origLastUpdated = r.getChange().change().getLastUpdatedOn();
        ReviewInput input = new ReviewInput();
        CommentInput comment = newComment(file, Side.REVISION, line, "comment 1", false);
        comment.updated = timestamp;
        input.comments = new HashMap<>();
        input.comments.put(comment.path, Lists.newArrayList(comment));
        ChangeResource changeRsrc = changes.get().parse(TopLevelResource.INSTANCE, IdString.fromDecoded(changeId));
        RevisionResource revRsrc = revisions.parse(changeRsrc, IdString.fromDecoded(revId));
        postReview.get().apply(batchUpdateFactory, revRsrc, input, timestamp);
        Map<String, List<CommentInfo>> result = getPublishedComments(changeId, revId);
        assertThat(result).isNotEmpty();
        CommentInfo actual = Iterables.getOnlyElement(result.get(comment.path));
        CommentInput ci = infoToInput(file).apply(actual);
        ci.updated = comment.updated;
        assertThat(comment).isEqualTo(ci);
        assertThat(actual.updated).isEqualTo(gApi.changes().id(r.getChangeId()).info().created);
        // Updating historic comments doesn't cause lastUpdatedOn to regress.
        assertThat(r.getChange().change().getLastUpdatedOn()).isEqualTo(origLastUpdated);
    }
}
Also used : RevisionResource(com.google.gerrit.server.change.RevisionResource) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Timestamp(java.sql.Timestamp) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) ChangeResource(com.google.gerrit.server.change.ChangeResource) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 5 with RevisionResource

use of com.google.gerrit.server.change.RevisionResource in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method commentBeforeFirstPatchSet.

@Test
public void commentBeforeFirstPatchSet() throws Exception {
    PushOneCommit.Result r = createChange();
    PatchSet.Id psId = r.getPatchSetId();
    Change.Id id = psId.getParentKey();
    Change c = db.changes().get(id);
    c.setCreatedOn(new Timestamp(c.getCreatedOn().getTime() - 5000));
    db.changes().update(Collections.singleton(c));
    indexer.index(db, project, id);
    ReviewInput rin = new ReviewInput();
    rin.message = "comment";
    Timestamp ts = new Timestamp(c.getCreatedOn().getTime() + 2000);
    assertThat(ts).isGreaterThan(c.getCreatedOn());
    assertThat(ts).isLessThan(db.patchSets().get(psId).getCreatedOn());
    RevisionResource revRsrc = parseCurrentRevisionResource(r.getChangeId());
    postReview.get().apply(batchUpdateFactory, revRsrc, rin, ts);
    checker.rebuildAndCheckChanges(id);
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) RevisionResource(com.google.gerrit.server.change.RevisionResource) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

RevisionResource (com.google.gerrit.server.change.RevisionResource)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)3 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)3 Timestamp (java.sql.Timestamp)3 Test (org.junit.Test)3 Change (com.google.gerrit.reviewdb.client.Change)2 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 ImmutableList (com.google.common.collect.ImmutableList)1 DeleteCommentInput (com.google.gerrit.extensions.api.changes.DeleteCommentInput)1 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)1 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 ChangeResource (com.google.gerrit.server.change.ChangeResource)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1