use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsMultipleUsers.
@Test
public void approvalsMultipleUsers() throws Exception {
Change c = newChange();
ChangeUpdate 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);
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(2);
assertThat(psas.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(psas.get(1).value()).isEqualTo((short) 1);
assertThat(psas.get(1).granted()).isEqualTo(truncate(after(c, 3000)));
assertParsedUuid(psas.get(1));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsTombstone.
@Test
public void approvalsTombstone() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
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().get()).isEqualTo(1);
assertThat(psa.label()).isEqualTo("Not-For-Long");
assertThat(psa.value()).isEqualTo((short) 1);
assertParsedUuid(psa);
update = newUpdate(c, changeOwner);
update.removeApproval("Not-For-Long");
update.commit();
notes = newNotes(c);
assertThat(notes.getApprovals()).containsExactlyEntriesIn(ImmutableListMultimap.of(psa.patchSetId(), PatchSetApproval.builder().key(psa.key()).value(0).granted(update.getWhen()).build()));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method multipleTags.
@Test
public void multipleTags() throws Exception {
String ipTag = "ip";
String coverageTag = "coverage";
String integrationTag = "integration";
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.VERIFIED, (short) -1);
update.setChangeMessage("integration verification");
update.setTag(integrationTag);
update.commit();
RevCommit commit = tr.commit().message("PS2").create();
update = newUpdate(c, changeOwner);
update.putComment(HumanComment.Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.now(), "Comment", (short) 1, commit, false));
update.setChangeMessage("coverage verification");
update.setTag(coverageTag);
update.commit();
update = newUpdate(c, changeOwner);
update.setChangeMessage("ip clear");
update.setTag(ipTag);
update.commit();
ChangeNotes notes = newNotes(c);
ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
assertThat(approvals).hasSize(1);
PatchSetApproval approval = approvals.entries().asList().get(0).getValue();
assertThat(approval.tag()).hasValue(integrationTag);
assertThat(approval.value()).isEqualTo(-1);
ImmutableListMultimap<ObjectId, HumanComment> comments = notes.getHumanComments();
assertThat(comments).hasSize(1);
assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(coverageTag);
ImmutableList<ChangeMessage> messages = notes.getChangeMessages();
assertThat(messages).hasSize(3);
assertThat(messages.get(0).getTag()).isEqualTo(integrationTag);
assertThat(messages.get(1).getTag()).isEqualTo(coverageTag);
assertThat(messages.get(2).getTag()).isEqualTo(ipTag);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsDuringSubmit.
@Test
public void approvalsDuringSubmit() throws Exception {
Change c = newChange();
SubmissionId submissionId = new SubmissionId(c);
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.putApproval(LabelId.VERIFIED, (short) 1);
update.commit();
Account.Id ownerId = changeOwner.getAccountId();
Account.Id otherId = otherUser.getAccountId();
update = newUpdate(c, otherUser);
update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", ownerId), submitLabel(LabelId.CODE_REVIEW, "NEED", null))));
update.putApproval("Other-Label", (short) 1);
update.putApprovalFor(ownerId, LabelId.CODE_REVIEW, (short) 2);
update.commit();
update = newUpdate(c, otherUser);
update.putApproval("Other-Label", (short) 2);
update.commit();
ChangeNotes notes = newNotes(c);
List<PatchSetApproval> approvals = Lists.newArrayList(notes.getApprovals().values());
assertThat(approvals).hasSize(3);
assertThat(approvals.get(0).accountId()).isEqualTo(ownerId);
assertThat(approvals.get(0).label()).isEqualTo(LabelId.VERIFIED);
assertThat(approvals.get(0).value()).isEqualTo(1);
assertThat(approvals.get(0).postSubmit()).isFalse();
assertParsedUuid(approvals.get(0));
assertThat(approvals.get(1).accountId()).isEqualTo(ownerId);
assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approvals.get(1).value()).isEqualTo(2);
// During submit.
assertThat(approvals.get(1).postSubmit()).isFalse();
assertParsedUuid(approvals.get(1));
assertThat(approvals.get(2).accountId()).isEqualTo(otherId);
assertThat(approvals.get(2).label()).isEqualTo("Other-Label");
assertThat(approvals.get(2).value()).isEqualTo(2);
assertThat(approvals.get(2).postSubmit()).isTrue();
assertParsedUuid(approvals.get(2));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method copiedApprovals_withRealUserAndTag_keepsUUID.
@Test
public void copiedApprovals_withRealUserAndTag_keepsUUID() throws Exception {
ImmutableList<String> strangeTags = ImmutableList.of(", ", ":\"", ",", "!@#$%^\0&*):\" \n: \r\"#$@,. :");
for (String strangeTag : strangeTags) {
Change c = newChange();
CurrentUser otherUserAsOwner = userFactory.runAs(null, changeOwner.getAccountId(), otherUser);
ChangeUpdate update = newUpdate(c, otherUserAsOwner);
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(otherUserId);
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