use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method emptyApproval_uuidGenerated.
@Test
public void emptyApproval_uuidGenerated() 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.putApproval(LabelId.CODE_REVIEW, (short) 0);
update.commit();
notes = newNotes(c);
PatchSetApproval emptyPsa = Iterables.getOnlyElement(notes.getApprovals().get(psa.patchSetId()));
assertThat(emptyPsa.key()).isEqualTo(psa.key());
assertThat(emptyPsa.value()).isEqualTo((short) 0);
assertThat(emptyPsa.label()).isEqualTo(psa.label());
assertParsedUuid(emptyPsa);
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalUUID_differentChanges.
@Test
public void approvalUUID_differentChanges() throws Exception {
Change c1 = newChange();
ChangeUpdate update1 = newUpdate(c1, changeOwner);
update1.putApproval(LabelId.CODE_REVIEW, (short) +2);
update1.commit();
Change c2 = newChange();
ChangeUpdate update = newUpdate(c2, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) +2);
update.commit();
ChangeNotes notes1 = newNotes(c1);
PatchSetApproval psa1 = Iterables.getOnlyElement(notes1.getApprovals().get(c1.currentPatchSetId()));
ChangeNotes notes2 = newNotes(c2);
PatchSetApproval psa2 = Iterables.getOnlyElement(notes2.getApprovals().get(c2.currentPatchSetId()));
assertThat(psa1.label()).isEqualTo(psa2.label());
assertThat(psa1.accountId()).isEqualTo(psa2.accountId());
assertThat(psa1.value()).isEqualTo(psa2.value());
// UUID is global: different across changes.
assertThat(psa1.uuid()).isNotEqualTo(psa2.uuid());
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method approvalsPostSubmit.
@Test
public void approvalsPostSubmit() 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();
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.putApproval(LabelId.CODE_REVIEW, (short) 2);
update.commit();
ChangeNotes notes = newNotes(c);
List<PatchSetApproval> approvals = Lists.newArrayList(notes.getApprovals().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();
assertParsedUuid(approvals.get(1));
assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approvals.get(1).value()).isEqualTo((short) 2);
assertThat(approvals.get(1).postSubmit()).isTrue();
assertParsedUuid(approvals.get(1));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesTest method putOtherUsersApprovals.
@Test
public void putOtherUsersApprovals() throws Exception {
Change c = newChange();
ChangeUpdate update = newUpdate(c, changeOwner);
update.putApproval(LabelId.CODE_REVIEW, (short) 1);
update.putApprovalFor(otherUser.getAccountId(), LabelId.CODE_REVIEW, (short) -1);
update.commit();
ChangeNotes notes = newNotes(c);
ImmutableList<PatchSetApproval> approvals = notes.getApprovals().get(c.currentPatchSetId()).stream().sorted(comparing(a -> a.accountId().get())).collect(toImmutableList());
assertThat(approvals).hasSize(2);
assertThat(approvals.get(0).accountId()).isEqualTo(changeOwner.getAccountId());
assertThat(approvals.get(0).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approvals.get(0).value()).isEqualTo((short) 1);
assertParsedUuid(approvals.get(0));
assertThat(approvals.get(1).accountId()).isEqualTo(otherUser.getAccountId());
assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
assertThat(approvals.get(1).value()).isEqualTo((short) -1);
assertThat(approvals.get(1).uuid()).isPresent();
assertParsedUuid(approvals.get(1));
}
use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.
the class ChangeNotesParser method parseCopiedApproval.
/**
* Parses copied {@link PatchSetApproval}.
*/
private void parseCopiedApproval(PatchSet.Id psId, Instant ts, String line) throws ConfigInvalidException {
ParsedPatchSetApproval parsedPatchSetApproval = ChangeNoteUtil.parseCopiedApproval(line);
checkFooter(parsedPatchSetApproval.accountIdent().isPresent(), FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
PersonIdent accountIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.accountIdent().get());
checkFooter(accountIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
Account.Id accountId = parseIdent(accountIdent);
Account.Id realAccountId = null;
if (parsedPatchSetApproval.realAccountIdent().isPresent()) {
PersonIdent realIdent = RawParseUtils.parsePersonIdent(parsedPatchSetApproval.realAccountIdent().get());
checkFooter(realIdent != null, FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
realAccountId = parseIdent(realIdent);
}
LabelVote l;
try {
l = LabelVote.parseWithEquals(parsedPatchSetApproval.labelVote());
} catch (IllegalArgumentException e) {
ConfigInvalidException pe = parseException("invalid %s: %s", FOOTER_COPIED_LABEL, parsedPatchSetApproval.footerLine());
pe.initCause(e);
throw pe;
}
PatchSetApproval.Builder psa = PatchSetApproval.builder().key(PatchSetApproval.key(psId, accountId, LabelId.create(l.label()))).uuid(parsedPatchSetApproval.uuid().map(PatchSetApproval::uuid)).value(l.value()).granted(ts).tag(parsedPatchSetApproval.tag()).copied(true);
if (realAccountId != null) {
psa.realAccountId(realAccountId);
}
approvals.putIfAbsent(psa.key(), psa);
bufferedApprovals.add(psa);
}
Aggregations