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