Search in sources :

Example 66 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class AbstractSubmitOnPush method assertSubmitApproval.

private void assertSubmitApproval(PatchSet.Id patchSetId) throws Exception {
    PatchSetApproval a = getSubmitter(patchSetId);
    assertThat(a.isLegacySubmit()).isTrue();
    assertThat(a.value()).isEqualTo((short) 1);
    assertThat(a.accountId()).isEqualTo(admin.id());
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 67 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class AbstractSubmit method assertSubmitter.

protected void assertSubmitter(String changeId, int psId, TestAccount user) throws Throwable {
    Change c = getOnlyElement(queryProvider.get().byKeyPrefix(changeId)).change();
    ChangeNotes cn = notesFactory.createChecked(c);
    PatchSetApproval submitter = approvalsUtil.getSubmitter(cn, PatchSet.id(cn.getChangeId(), psId));
    assertThat(submitter).isNotNull();
    assertThat(submitter.isLegacySubmit()).isTrue();
    assertThat(submitter.accountId()).isEqualTo(user.id());
}
Also used : Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval)

Example 68 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ApprovalQueryIT method contextForCodeReviewLabel.

private ApprovalContext contextForCodeReviewLabel(int value, PatchSet.Id psId, Account.Id approver) throws Exception {
    ChangeNotes changeNotes = changeNotesFactory.create(project, psId.changeId());
    PatchSet.Id newPsId = PatchSet.id(psId.changeId(), psId.get() + 1);
    ChangeKind changeKind = changeKindCache.getChangeKind(changeNotes.getChange(), changeNotes.getPatchSets().get(newPsId));
    PatchSetApproval approval = PatchSetApproval.builder().postSubmit(false).granted(Instant.now()).key(PatchSetApproval.key(psId, approver, LabelId.create("Code-Review"))).value(value).build();
    try (Repository repo = repoManager.openRepository(project);
        RevWalk rw = new RevWalk(repo.newObjectReader())) {
        return ApprovalContext.create(changeNotes, approval, changeNotes.getPatchSets().get(newPsId), changeKind, rw, repo.getConfig());
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) PatchSet(com.google.gerrit.entities.PatchSet) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ChangeKind(com.google.gerrit.extensions.client.ChangeKind)

Example 69 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesStateTest method serializeApprovalsWithUUID.

@Test
public void serializeApprovalsWithUUID() throws Exception {
    PatchSetApproval a1 = PatchSetApproval.builder().key(PatchSetApproval.key(PatchSet.id(ID, 1), Account.id(2001), LabelId.create(LabelId.CODE_REVIEW))).uuid(Optional.of(PatchSetApproval.uuid("577fb248e474018276351785930358ec0450e9f7"))).value(1).tag("tag").granted(Instant.ofEpochMilli(1212L)).build();
    Entities.PatchSetApproval psa1 = PatchSetApprovalProtoConverter.INSTANCE.toProto(a1);
    ByteString a1Bytes = Protos.toByteString(psa1);
    PatchSetApproval a2 = PatchSetApproval.builder().key(PatchSetApproval.key(PatchSet.id(ID, 1), Account.id(2002), LabelId.create(LabelId.VERIFIED))).uuid(Optional.of(PatchSetApproval.uuid("577fb248e474018276351785930358ec0450e9f7"))).value(-1).tag("tag").copied(true).granted(Instant.ofEpochMilli(3434L)).build();
    Entities.PatchSetApproval psa2 = PatchSetApprovalProtoConverter.INSTANCE.toProto(a2);
    ByteString a2Bytes = Protos.toByteString(psa2);
    assertThat(a2Bytes.size()).isEqualTo(98);
    assertThat(a2Bytes).isNotEqualTo(a1Bytes);
    assertRoundTrip(newBuilder().approvals(ImmutableListMultimap.of(a2.patchSetId(), a2, a1.patchSetId(), a1).entries()).build(), ChangeNotesStateProto.newBuilder().setMetaId(SHA_BYTES).setChangeId(ID.get()).setColumns(colsProto).addApproval(psa2).addApproval(psa1).build());
}
Also used : ByteString(com.google.protobuf.ByteString) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 70 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ImpersonationIT method runAsWithOnBehalfOf.

@Test
public void runAsWithOnBehalfOf() throws Exception {
    // - Has the same restrictions as on_behalf_of (e.g. requires labels).
    // - Takes the effective user from on_behalf_of (user).
    // - Takes the real user from the real caller, not the intermediate
    // X-Gerrit-RunAs user (user2).
    allowRunAs();
    allowCodeReviewOnBehalfOf();
    TestAccount user2 = accountCreator.user2();
    PushOneCommit.Result r = createChange();
    ReviewInput in = new ReviewInput();
    in.onBehalfOf = user.id().toString();
    in.message = "Message on behalf of";
    String endpoint = "/changes/" + r.getChangeId() + "/revisions/current/review";
    RestResponse res = adminRestSession.postWithHeaders(endpoint, in, runAsHeader(user2.id()));
    res.assertForbidden();
    assertThat(res.getEntityContent()).isEqualTo("label required to post review on behalf of \"" + in.onBehalfOf + '"');
    in.label("Code-Review", 1);
    adminRestSession.postWithHeaders(endpoint, in, runAsHeader(user2.id())).assertOK();
    PatchSetApproval psa = Iterables.getOnlyElement(r.getChange().approvals().values());
    assertThat(psa.patchSetId().get()).isEqualTo(1);
    assertThat(psa.label()).isEqualTo("Code-Review");
    assertThat(psa.accountId()).isEqualTo(user.id());
    assertThat(psa.value()).isEqualTo(1);
    // not user2
    assertThat(psa.realAccountId()).isEqualTo(admin.id());
    ChangeData cd = r.getChange();
    ChangeMessage m = Iterables.getLast(cmUtil.byChange(cd.notes()));
    assertThat(m.getMessage()).endsWith(in.message);
    assertThat(m.getAuthor()).isEqualTo(user.id());
    // not user2
    assertThat(m.getRealAuthor()).isEqualTo(admin.id());
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ChangeMessage(com.google.gerrit.entities.ChangeMessage) TestAccount(com.google.gerrit.acceptance.TestAccount) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8