Search in sources :

Example 86 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method approval_UUIDGenerated_forAllValues.

@Test
public void approval_UUIDGenerated_forAllValues() throws Exception {
    for (int value = -2; value <= 2; value++) {
        Change c = newChange();
        ChangeUpdate update = newUpdate(c, changeOwner);
        update.putApproval(LabelId.CODE_REVIEW, (short) value);
        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) value);
        assertParsedUuid(psa);
    }
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 87 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method multipleUpdatesAcrossRefs.

@Test
public void multipleUpdatesAcrossRefs() throws Exception {
    Change c1 = newChange();
    ChangeUpdate update1 = newUpdate(c1, changeOwner);
    update1.putApproval(LabelId.VERIFIED, (short) 1);
    Change c2 = newChange();
    ChangeUpdate update2 = newUpdate(c2, otherUser);
    update2.putApproval(LabelId.CODE_REVIEW, (short) 2);
    Ref initial1 = repo.exactRef(update1.getRefName());
    assertThat(initial1).isNotNull();
    Ref initial2 = repo.exactRef(update2.getRefName());
    assertThat(initial2).isNotNull();
    try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
        updateManager.add(update1);
        updateManager.add(update2);
        updateManager.execute();
    }
    Ref ref1 = repo.exactRef(update1.getRefName());
    assertThat(ref1.getObjectId()).isEqualTo(update1.getResult());
    assertThat(ref1.getObjectId()).isNotEqualTo(initial1.getObjectId());
    Ref ref2 = repo.exactRef(update2.getRefName());
    assertThat(ref2.getObjectId()).isEqualTo(update2.getResult());
    assertThat(ref2.getObjectId()).isNotEqualTo(initial2.getObjectId());
    PatchSetApproval approval1 = newNotes(c1).getApprovals().get(c1.currentPatchSetId()).iterator().next();
    assertThat(approval1.label()).isEqualTo(LabelId.VERIFIED);
    PatchSetApproval approval2 = newNotes(c2).getApprovals().get(c2.currentPatchSetId()).iterator().next();
    assertThat(approval2.label()).isEqualTo(LabelId.CODE_REVIEW);
}
Also used : RefNames.changeMetaRef(com.google.gerrit.entities.RefNames.changeMetaRef) Ref(org.eclipse.jgit.lib.Ref) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 88 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method copiedApprovalsWithStrangeTags.

@Test
public void copiedApprovalsWithStrangeTags() throws Exception {
    String strangeTag = "!@#$%^\0&*):\" \n: \r\"#$@,. :";
    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(strangeTag).build());
    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);
    assertThat(approval.value()).isEqualTo((short) 1);
    assertThat(approval.tag()).hasValue(NoteDbUtil.sanitizeFooter(strangeTag));
    assertThat(approval.copied()).isTrue();
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 89 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method approvalsOnePatchSet.

@Test
public void approvalsOnePatchSet() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.VERIFIED, (short) 1);
    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(1);
    assertThat(psas.get(1).label()).isEqualTo(LabelId.VERIFIED);
    assertThat(psas.get(1).value()).isEqualTo((short) 1);
    assertThat(psas.get(1).granted()).isEqualTo(psas.get(0).granted());
    assertParsedUuid(psas.get(1));
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 90 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method copiedApprovals_withTag_keepsUUID.

@Test
public void copiedApprovals_withTag_keepsUUID() throws Exception {
    ImmutableList<String> strangeTags = ImmutableList.of(", ", ":\"", ",", "!@#$%^\0&*):\" \n: \r\"#$@,. :");
    for (String strangeTag : strangeTags) {
        Change c = newChange();
        ChangeUpdate update = newUpdate(c, changeOwner);
        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(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);
    }
}
Also used : Change(com.google.gerrit.entities.Change) 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