use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ImpersonationIT method submitOnBehalfOf.
@Test
public void submitOnBehalfOf() throws Exception {
allowSubmitOnBehalfOf();
PushOneCommit.Result r = createChange();
String changeId = project.get() + "~master~" + r.getChangeId();
gApi.changes().id(changeId).current().review(ReviewInput.approve());
SubmitInput in = new SubmitInput();
in.onBehalfOf = admin2.email();
gApi.changes().id(changeId).current().submit(in);
ChangeData cd = r.getChange();
assertThat(cd.change().isMerged()).isTrue();
PatchSetApproval submitter = approvalsUtil.getSubmitter(cd.notes(), cd.change().currentPatchSetId());
assertThat(submitter.accountId()).isEqualTo(admin2.id());
assertThat(submitter.realAccountId()).isEqualTo(admin.id());
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class SubmitByCherryPickIT method stickyVoteStoredOnSubmitOnNewPatchset.
private void stickyVoteStoredOnSubmitOnNewPatchset() throws Exception {
PushOneCommit.Result r = createChange();
// Add a new vote.
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Submit, also keeping the Code-Review +2 vote.
gApi.changes().id(r.getChangeId()).current().submit();
// The last approval is stored on the submitted patch-set which was created by cherry-pick
// during submit.
PatchSetApproval patchSetApprovals = Iterables.getLast(r.getChange().notes().getApprovalsWithCopied().values().stream().filter(a -> a.labelId().equals(LabelId.create(LabelId.CODE_REVIEW))).sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList()));
assertThat(patchSetApprovals.patchSetId().get()).isEqualTo(2);
assertThat(patchSetApprovals.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(patchSetApprovals.value()).isEqualTo((short) 2);
// The approval is not copied since we don't need to persist copied votes on submit, only
// persist votes normally.
assertThat(patchSetApprovals.copied()).isFalse();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class SubmitByRebaseAlwaysIT method stickyVoteStoredOnSubmitOnNewPatchset.
private void stickyVoteStoredOnSubmitOnNewPatchset() throws Exception {
PushOneCommit.Result r = createChange();
// Add a new vote.
ReviewInput input = new ReviewInput().label(LabelId.CODE_REVIEW, 2);
gApi.changes().id(r.getChangeId()).current().review(input);
// Submit, also keeping the Code-Review +2 vote.
gApi.changes().id(r.getChangeId()).current().submit();
// The last approval is stored on the submitted patch-set which was created by rebase during
// submit.
PatchSetApproval patchSetApprovals = Iterables.getLast(r.getChange().notes().getApprovalsWithCopied().values().stream().filter(a -> a.labelId().equals(LabelId.create(LabelId.CODE_REVIEW))).sorted(comparing(a -> a.patchSetId().get())).collect(toImmutableList()));
assertThat(patchSetApprovals.patchSetId().get()).isEqualTo(2);
assertThat(patchSetApprovals.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(patchSetApprovals.value()).isEqualTo((short) 2);
// The approval is not copied since we don't need to persist copied votes on submit, only
// persist votes normally.
assertThat(patchSetApprovals.copied()).isFalse();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class PatchSetApprovalProtoConverterTest method allValuesConvertedToProtoAndBackAgain.
@Test
public void allValuesConvertedToProtoAndBackAgain() {
PatchSetApproval patchSetApproval = PatchSetApproval.builder().key(PatchSetApproval.key(PatchSet.id(Change.id(42), 14), Account.id(100013), LabelId.create("label-8"))).uuid(Optional.of(PatchSetApproval.uuid("577fb248e474018276351785930358ec0450e9f7"))).value(456).granted(Instant.ofEpochMilli(987654L)).tag("tag-21").realAccountId(Account.id(612)).postSubmit(true).copied(true).build();
PatchSetApproval convertedPatchSetApproval = protoConverter.fromProto(protoConverter.toProto(patchSetApproval));
assertThat(convertedPatchSetApproval).isEqualTo(patchSetApproval);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class PatchSetApprovalProtoConverterTest method protoWithOnlyRequiredValuesCanBeConvertedBack.
// We need this special test as some values are only optional in the protobuf definition but can
// never be unset in our entity object.
@Test
public void protoWithOnlyRequiredValuesCanBeConvertedBack() {
Entities.PatchSetApproval proto = Entities.PatchSetApproval.newBuilder().setKey(Entities.PatchSetApproval_Key.newBuilder().setPatchSetId(Entities.PatchSet_Id.newBuilder().setChangeId(Entities.Change_Id.newBuilder().setId(42)).setId(14)).setAccountId(Entities.Account_Id.newBuilder().setId(100013)).setLabelId(Entities.LabelId.newBuilder().setId("label-8"))).build();
PatchSetApproval patchSetApproval = protoConverter.fromProto(proto);
assertThat(patchSetApproval.patchSetId()).isEqualTo(PatchSet.id(Change.id(42), 14));
assertThat(patchSetApproval.accountId()).isEqualTo(Account.id(100013));
assertThat(patchSetApproval.labelId()).isEqualTo(LabelId.create("label-8"));
// Default values for unset protobuf fields which can't be unset in the entity object.
assertThat(patchSetApproval.value()).isEqualTo(0);
assertThat(patchSetApproval.granted()).isEqualTo(Instant.EPOCH);
assertThat(patchSetApproval.postSubmit()).isEqualTo(false);
assertThat(patchSetApproval.copied()).isEqualTo(false);
}
Aggregations