Search in sources :

Example 71 with PatchSetApproval

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());
}
Also used : SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) ChangeData(com.google.gerrit.server.query.change.ChangeData) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 72 with PatchSetApproval

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();
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) CommitMergeStatus(com.google.gerrit.server.submit.CommitMergeStatus) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) SubmitInput(com.google.gerrit.extensions.api.changes.SubmitInput) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) BranchNameKey(com.google.gerrit.entities.BranchNameKey) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) List(java.util.List) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) MESSAGES(com.google.gerrit.extensions.client.ListChangesOption.MESSAGES) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) FooterConstants(com.google.gerrit.common.FooterConstants) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 73 with PatchSetApproval

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();
}
Also used : Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) DynamicItem(com.google.gerrit.extensions.registration.DynamicItem) Inject(com.google.inject.Inject) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) MergeUpdateException(com.google.gerrit.exceptions.MergeUpdateException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ImmutableList(com.google.common.collect.ImmutableList) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) CURRENT_REVISION(com.google.gerrit.extensions.client.ListChangesOption.CURRENT_REVISION) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PatchSet(com.google.gerrit.entities.PatchSet) UrlFormatter(com.google.gerrit.server.config.UrlFormatter) Comparator.comparing(java.util.Comparator.comparing) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) SubmitType(com.google.gerrit.extensions.client.SubmitType) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) NameKey(com.google.gerrit.entities.Project.NameKey) ChangeData(com.google.gerrit.server.query.change.ChangeData) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) FooterConstants(com.google.gerrit.common.FooterConstants) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit)

Example 74 with PatchSetApproval

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);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 75 with 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);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Entities(com.google.gerrit.proto.Entities) 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