use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method reissuedApproval_samePatchSet_differentUUID.
@Test
public void reissuedApproval_samePatchSet_differentUUID() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) -1);
update.commit();
ChangeNotes notes = newNotes(c);
assertThat(notes.getApprovals().keySet()).containsExactly(c.currentPatchSetId());
PatchSetApproval originalPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(originalPsa.patchSetId()).isEqualTo(c.currentPatchSetId());
assertThat(originalPsa.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(originalPsa.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(originalPsa.value()).isEqualTo((short) -1);
assertParsedUuid(originalPsa);
// Remove approval from current patch set
update = newUpdate(c, changeOwner);
update.removeApproval(LabelId.CODE_REVIEW);
update.commit();
notes = newNotes(c);
assertThat(notes.getApprovals().keySet()).hasSize(1);
PatchSetApproval removedPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(removedPsa.key()).isEqualTo(originalPsa.key());
assertThat(removedPsa.value()).isEqualTo(0);
// Add approval with the same author, label, value to the current patch set
update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) -1);
update.commit();
notes = newNotes(c);
assertThat(notes.getApprovals().keySet()).hasSize(1);
PatchSetApproval reAddedPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(reAddedPsa.key()).isEqualTo(originalPsa.key());
assertThat(reAddedPsa.value()).isEqualTo(originalPsa.value());
// The re-added approval has a different UUID
assertParsedUuid(reAddedPsa);
assertThat(reAddedPsa.uuid().get()).isNotEqualTo(originalPsa.uuid().get());
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method removeReviewer.
@Test
public void removeReviewer() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putReviewer(otherUser.getAccount().id(), REVIEWER);
update.commit();
update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.commit();
update = newUpdate(c, otherUser);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.commit();
ChangeNotes notes = newNotes(c);
List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
assertThat(psas).hasSize(2);
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().id());
update = newUpdate(c, changeOwner);
update.removeReviewer(otherUser.getAccount().id());
update.commit();
notes = newNotes(c);
psas = notes.getApprovals().get(c.currentPatchSetId());
assertThat(psas).hasSize(1);
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovals_keepsUUID.
@Test
public void copiedApprovals_keepsUUID() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 2);
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()).isEmpty();
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);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method multipleUpdatesInManager.
@Test
public void multipleUpdatesInManager() throws Exception {
Change c = newChange();
ChangeUpdate update1 = newUpdate(c, changeOwner);
update1.putApproval(LabelId.VERIFIED, (short) 1);
ChangeUpdate update2 = newUpdate(c, otherUser);
update2.putApproval(LabelId.CODE_REVIEW, (short) 2);
try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
updateManager.add(update1);
updateManager.add(update2);
updateManager.execute();
}
ChangeNotes notes = newNotes(c);
List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
assertThat(psas).hasSize(2);
assertThat(psas.get(0).accountId()).isEqualTo(changeOwner.getAccount().id());
assertThat(psas.get(0).label()).isEqualTo(LabelId.VERIFIED);
assertThat(psas.get(0).value()).isEqualTo((short) 1);
assertThat(psas.get(1).accountId()).isEqualTo(otherUser.getAccount().id());
assertThat(psas.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psas.get(1).value()).isEqualTo((short) 2);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsMultipleApprovals.
@Test
public void approvalsMultipleApprovals() 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.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psa.value()).isEqualTo((short) -1);
assertParsedUuid(psa);
update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.commit();
notes = newNotes(c);
psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(psa.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psa.value()).isEqualTo((short) 1);
assertParsedUuid(psa);
}
Aggregations