Search in sources :

Example 6 with PatchSetApproval

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);
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 7 with PatchSetApproval

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);
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 8 with PatchSetApproval

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);
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 9 with PatchSetApproval

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();
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 10 with PatchSetApproval

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);
}
Also used : Change(com.google.gerrit.entities.Change) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8