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());
}
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());
}
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());
}
}
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());
}
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());
}
Aggregations