use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approval_UUIDGenerated_forAllValues.
@Test
public void approval_UUIDGenerated_forAllValues() throws Exception {
for (int value = -2; value <= 2; value++) {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) value);
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) value);
assertParsedUuid(psa);
}
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method multipleUpdatesAcrossRefs.
@Test
public void multipleUpdatesAcrossRefs() throws Exception {
Change c1 = newChange();
ChangeUpdate update1 = newUpdate(c1, changeOwner);
update1.putApproval(LabelId.VERIFIED, (short) 1);
Change c2 = newChange();
ChangeUpdate update2 = newUpdate(c2, otherUser);
update2.putApproval(LabelId.CODE_REVIEW, (short) 2);
Ref initial1 = repo.exactRef(update1.getRefName());
assertThat(initial1).isNotNull();
Ref initial2 = repo.exactRef(update2.getRefName());
assertThat(initial2).isNotNull();
try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
updateManager.add(update1);
updateManager.add(update2);
updateManager.execute();
}
Ref ref1 = repo.exactRef(update1.getRefName());
assertThat(ref1.getObjectId()).isEqualTo(update1.getResult());
assertThat(ref1.getObjectId()).isNotEqualTo(initial1.getObjectId());
Ref ref2 = repo.exactRef(update2.getRefName());
assertThat(ref2.getObjectId()).isEqualTo(update2.getResult());
assertThat(ref2.getObjectId()).isNotEqualTo(initial2.getObjectId());
PatchSetApproval approval1 = newNotes(c1).getApprovals().get(c1.currentPatchSetId()).iterator().next();
assertThat(approval1.label()).isEqualTo(LabelId.VERIFIED);
PatchSetApproval approval2 = newNotes(c2).getApprovals().get(c2.currentPatchSetId()).iterator().next();
assertThat(approval2.label()).isEqualTo(LabelId.CODE_REVIEW);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovalsWithStrangeTags.
@Test
public void copiedApprovalsWithStrangeTags() throws Exception {
String strangeTag = "!@#$%^\0&*):\" \n: \r\"#$@,. :";
Change c = newChange();
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()).tag(strangeTag).build());
update.commit();
ChangeNotes notes = newNotes(c);
PatchSetApproval approval = Iterables.getOnlyElement(notes.getApprovalsWithCopied().get(c.currentPatchSetId()));
assertThat(approval.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(approval.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approval.value()).isEqualTo((short) 1);
assertThat(approval.tag()).hasValue(NoteDbUtil.sanitizeFooter(strangeTag));
assertThat(approval.copied()).isTrue();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsOnePatchSet.
@Test
public void approvalsOnePatchSet() 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> psas = notes.getApprovals().get(c.currentPatchSetId());
assertThat(psas).hasSize(2);
assertThat(psas.get(0).patchSetId()).isEqualTo(c.currentPatchSetId());
assertThat(psas.get(0).accountId().get()).isEqualTo(1);
assertThat(psas.get(0).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psas.get(0).value()).isEqualTo((short) -1);
assertThat(psas.get(0).granted()).isEqualTo(truncate(after(c, 2000)));
assertParsedUuid(psas.get(0));
assertThat(psas.get(1).patchSetId()).isEqualTo(c.currentPatchSetId());
assertThat(psas.get(1).accountId().get()).isEqualTo(1);
assertThat(psas.get(1).label()).isEqualTo(LabelId.VERIFIED);
assertThat(psas.get(1).value()).isEqualTo((short) 1);
assertThat(psas.get(1).granted()).isEqualTo(psas.get(0).granted());
assertParsedUuid(psas.get(1));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovals_withTag_keepsUUID.
@Test
public void copiedApprovals_withTag_keepsUUID() throws Exception {
ImmutableList<String> strangeTags = ImmutableList.of(", ", ":\"", ",", "!@#$%^\0&*):\" \n: \r\"#$@,. :");
for (String strangeTag : strangeTags) {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 2);
update.setTag(strangeTag);
update.commit();
ChangeNotes notes = newNotes(c);
PatchSetApproval originalPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(originalPsa.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(originalPsa.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(originalPsa.value()).isEqualTo(2);
assertThat(originalPsa.tag()).hasValue(NoteDbUtil.sanitizeFooter(strangeTag));
assertThat(originalPsa.realAccountId()).isEqualTo(changeOwner.getAccountId());
assertParsedUuid(originalPsa);
// Copied approvals are persisted at the patch set upload, add new patch set
incrementPatchSet(c);
addCopiedApproval(c, changeOwner, originalPsa);
notes = newNotes(c);
assertThat(notes.getApprovalsWithCopied().keySet()).hasSize(2);
PatchSetApproval copiedApproval = Iterables.getOnlyElement(notes.getApprovalsWithCopied().get(c.currentPatchSetId()).stream().filter(a -> a.copied()).collect(toImmutableList()));
PatchSetApproval nonCopiedApproval = Iterables.getOnlyElement(notes.getApprovalsWithCopied().get(originalPsa.patchSetId()).stream().filter(a -> !a.copied()).collect(toImmutableList()));
// Still same original PSA is returned
assertThat(nonCopiedApproval).isEqualTo(originalPsa);
// The copied approval matches the original approval, including UUID
assertCopiedApproval(originalPsa, copiedApproval);
}
}
Aggregations