use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsMultiplePatchSets.
@Test
public void approvalsMultiplePatchSets() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) -1);
update.commit();
PatchSet.Id ps1 = c.currentPatchSetId();
incrementPatchSet(c);
update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.commit();
PatchSet.Id ps2 = c.currentPatchSetId();
ChangeNotes notes = newNotes(c);
ListMultimap<PatchSet.Id, PatchSetApproval> psas = notes.getApprovals();
assertThat(psas).hasSize(2);
PatchSetApproval psa1 = Iterables.getOnlyElement(psas.get(ps1));
assertThat(psa1.patchSetId()).isEqualTo(ps1);
assertThat(psa1.accountId().get()).isEqualTo(1);
assertThat(psa1.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psa1.value()).isEqualTo((short) -1);
assertThat(psa1.granted()).isEqualTo(truncate(after(c, 2000)));
assertParsedUuid(psa1);
PatchSetApproval psa2 = Iterables.getOnlyElement(psas.get(ps2));
assertThat(psa2.patchSetId()).isEqualTo(ps2);
assertThat(psa2.accountId().get()).isEqualTo(1);
assertThat(psa2.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psa2.value()).isEqualTo((short) +1);
assertThat(psa2.granted()).isEqualTo(truncate(after(c, 4000)));
assertParsedUuid(psa2);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method removeOtherUsersApprovals.
@Test
public void removeOtherUsersApprovals() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, otherUser);
update.putApproval("Not-For-Long", (short) 1);
update.commit();
ChangeNotes notes = newNotes(c);
PatchSetApproval psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(psa.accountId()).isEqualTo(otherUserId);
assertThat(psa.label()).isEqualTo("Not-For-Long");
assertThat(psa.value()).isEqualTo((short) 1);
assertParsedUuid(psa);
update = newUpdate(c, changeOwner);
update.removeApprovalFor(otherUserId, "Not-For-Long");
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();
// Add back approval on same label.
update = newUpdate(c, otherUser);
update.putApproval("Not-For-Long", (short) 2);
update.commit();
notes = newNotes(c);
psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(psa.accountId()).isEqualTo(otherUserId);
assertThat(psa.label()).isEqualTo("Not-For-Long");
assertThat(psa.value()).isEqualTo((short) 2);
assertParsedUuid(psa);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovals.
@Test
public void copiedApprovals() throws Exception {
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("tag").realAccountId(otherUserId).build());
update.putApprovalFor(otherUserId, LabelId.CODE_REVIEW, (short) -1);
update.commit();
// Only the non copied approval is reachable by getApprovals.
ChangeNotes notes = newNotes(c);
PatchSetApproval approval = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
assertThat(approval.accountId()).isEqualTo(otherUser.getAccountId());
assertThat(approval.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approval.value()).isEqualTo((short) -1);
assertThat(approval.copied()).isFalse();
// Get approvals with copied gets all of the approvals (including copied).
ImmutableList<PatchSetApproval> approvals = notes.getApprovalsWithCopied().get(c.currentPatchSetId()).stream().sorted(comparing(a -> a.accountId().get())).collect(toImmutableList());
assertThat(approvals).hasSize(2);
PatchSetApproval copied = approvals.get(0);
assertThat(copied.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(copied.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(copied.value()).isEqualTo((short) 1);
assertThat(copied.tag()).hasValue("tag");
assertThat(copied.accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(copied.realAccountId()).isEqualTo(otherUserId);
assertThat(copied.copied()).isTrue();
PatchSetApproval nonCopied = approvals.get(1);
assertThat(nonCopied.accountId()).isEqualTo(otherUserId);
assertThat(nonCopied.realAccountId()).isEqualTo(otherUserId);
assertThat(nonCopied.label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(nonCopied.value()).isEqualTo((short) -1);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovalsCanBeRemoved.
@Test
public void copiedApprovalsCanBeRemoved() throws Exception {
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()).build());
update.commit();
update.removeApproval(LabelId.CODE_REVIEW);
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);
// The vote got removed since the latest patch-set only has one vote and it's "0". The copied
// approval will never have a "0" vote, but it can be overridden by a "0" vote of a
// non-copied approval.
assertThat(approval.value()).isEqualTo((short) 0);
assertThat(approval.copied()).isFalse();
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method tagApprovals.
@Test
public void tagApprovals() throws Exception {
String tag1 = "jenkins";
String tag2 = "ip";
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.VERIFIED, (short) -1);
update.setTag(tag1);
update.commit();
update = newUpdate(c, changeOwner);
update.putApproval(LabelId.VERIFIED, (short) 1);
update.setTag(tag2);
update.commit();
ChangeNotes notes = newNotes(c);
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
assertThat(approvals).hasSize(1);
assertThat(approvals.entries().asList().get(0).getValue().tag()).hasValue(tag2);
}
Aggregations