Search in sources :

Example 76 with PatchSetApproval

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

the class PatchSetApprovalProtoConverterTest method allValuesConvertedToProto.

@Test
public void allValuesConvertedToProto() {
    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();
    Entities.PatchSetApproval proto = protoConverter.toProto(patchSetApproval);
    Entities.PatchSetApproval expectedProto = 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"))).setUuid("577fb248e474018276351785930358ec0450e9f7").setValue(456).setGranted(987654L).setTag("tag-21").setRealAccountId(Entities.Account_Id.newBuilder().setId(612)).setPostSubmit(true).setCopied(true).build();
    assertThat(proto).isEqualTo(expectedProto);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Entities(com.google.gerrit.proto.Entities) Test(org.junit.Test)

Example 77 with PatchSetApproval

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

the class ChangeNotesTest method approvalUUID_samePatchSet_differentLabels.

@Test
public void approvalUUID_samePatchSet_differentLabels() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.VERIFIED, (short) -1);
    update.putApproval(LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getApprovals().keySet()).containsExactly(c.currentPatchSetId());
    List<PatchSetApproval> patchSetApprovals = notes.getApprovals().get(c.currentPatchSetId());
    assertThat(patchSetApprovals).hasSize(2);
    assertThat(patchSetApprovals.stream().filter(psa -> psa.value() == (short) -1 && psa.accountId().equals(changeOwner.getAccountId())).count()).isEqualTo(2);
    // Count UUIDs to make sure they are unique
    assertThat(patchSetApprovals.stream().map(psa -> psa.uuid().get()).distinct().count()).isEqualTo(2);
    assertThat(patchSetApprovals.stream().map(psa -> psa.label()).collect(toImmutableSet())).containsExactly(LabelId.VERIFIED, LabelId.CODE_REVIEW);
}
Also used : TestChanges(com.google.gerrit.testing.TestChanges) RefNames.changeMetaRef(com.google.gerrit.entities.RefNames.changeMetaRef) OBJ_BLOB(org.eclipse.jgit.lib.Constants.OBJ_BLOB) ListMultimap(com.google.common.collect.ListMultimap) Inject(com.google.inject.Inject) HumanComment(com.google.gerrit.entities.HumanComment) SubmissionId(com.google.gerrit.entities.SubmissionId) ReviewerSet(com.google.gerrit.server.ReviewerSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) CommentRange(com.google.gerrit.entities.CommentRange) NoteMap(org.eclipse.jgit.notes.NoteMap) ImmutableSet(com.google.common.collect.ImmutableSet) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) BranchNameKey(com.google.gerrit.entities.BranchNameKey) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Ref(org.eclipse.jgit.lib.Ref) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefNames.refsDraftComments(com.google.gerrit.entities.RefNames.refsDraftComments) CC(com.google.gerrit.server.notedb.ReviewerStateInternal.CC) ChangeMessage(com.google.gerrit.entities.ChangeMessage) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) Address(com.google.gerrit.entities.Address) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) REVIEWER(com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER) AssigneeStatusUpdate(com.google.gerrit.server.AssigneeStatusUpdate) LinkedHashSet(java.util.LinkedHashSet) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) CurrentUser(com.google.gerrit.server.CurrentUser) ValidationException(com.google.gerrit.server.validators.ValidationException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StorageException(com.google.gerrit.exceptions.StorageException) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ImmutableTable(com.google.common.collect.ImmutableTable) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) REMOVED(com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 78 with PatchSetApproval

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

the class ChangeNotesTest method copiedApprovalsPostSubmit.

@Test
public void copiedApprovalsPostSubmit() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.CODE_REVIEW))).value(1).copied(true).granted(TimeUtil.now()).build());
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.VERIFIED))).value(1).copied(true).granted(TimeUtil.now()).build());
    update.commit();
    update = newUpdate(c, changeOwner);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null))));
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putCopiedApproval(PatchSetApproval.builder().key(PatchSetApproval.key(c.currentPatchSetId(), changeOwner.getAccountId(), LabelId.create(LabelId.CODE_REVIEW))).value(2).copied(true).granted(TimeUtil.now()).build());
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> approvals = Lists.newArrayList(notes.getApprovalsWithCopied().values());
    assertThat(approvals).hasSize(2);
    assertThat(approvals.get(0).label()).isEqualTo(LabelId.VERIFIED);
    assertThat(approvals.get(0).value()).isEqualTo((short) 1);
    assertThat(approvals.get(0).postSubmit()).isFalse();
    assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(1).value()).isEqualTo((short) 2);
    assertThat(approvals.get(1).postSubmit()).isTrue();
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 79 with PatchSetApproval

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

the class ChangeNotesTest method removedApproval_noUuid.

@Test
public void removedApproval_noUuid() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    PatchSetApproval psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(psa.accountId()).isEqualTo(changeOwner.getAccountId());
    assertThat(psa.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(psa.value()).isEqualTo((short) -1);
    assertParsedUuid(psa);
    update = newUpdate(c, changeOwner);
    update.removeApproval(LabelId.CODE_REVIEW);
    update.commit();
    notes = newNotes(c);
    PatchSetApproval removedPsa = Iterables.getOnlyElement(notes.getApprovals().get(psa.patchSetId()));
    assertThat(removedPsa.key()).isEqualTo(psa.key());
    assertThat(removedPsa.value()).isEqualTo((short) 0);
    assertThat(removedPsa.label()).isEqualTo(psa.label());
    assertThat(removedPsa.uuid()).isEmpty();
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 80 with PatchSetApproval

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

the class ChangeNotesStateTest method serializeApprovals.

@Test
public void serializeApprovals() throws Exception {
    PatchSetApproval a1 = PatchSetApproval.builder().key(PatchSetApproval.key(PatchSet.id(ID, 1), Account.id(2001), LabelId.create(LabelId.CODE_REVIEW))).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))).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(56);
    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)

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