Search in sources :

Example 16 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method approvalsPostSubmit.

@Test
public void approvalsPostSubmit() throws Exception {
    Change c = newChange();
    RequestId submissionId = RequestId.forChange(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval("Code-Review", (short) 1);
    update.putApproval("Verified", (short) 1);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel("Verified", "OK", changeOwner.getAccountId()), submitLabel("Code-Review", "NEED", null))));
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putApproval("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).getLabel()).isEqualTo("Verified");
    assertThat(approvals.get(0).getValue()).isEqualTo((short) 1);
    assertThat(approvals.get(0).isPostSubmit()).isFalse();
    assertThat(approvals.get(1).getLabel()).isEqualTo("Code-Review");
    assertThat(approvals.get(1).getValue()).isEqualTo((short) 2);
    assertThat(approvals.get(1).isPostSubmit()).isTrue();
}
Also used : RequestId(com.google.gerrit.server.util.RequestId) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 17 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method multipleUpdatesInManager.

@Test
public void multipleUpdatesInManager() throws Exception {
    Change c = newChange();
    ChangeUpdate update1 = newUpdate(c, changeOwner);
    update1.putApproval("Verified", (short) 1);
    ChangeUpdate update2 = newUpdate(c, otherUser);
    update2.putApproval("Code-Review", (short) 2);
    try (NoteDbUpdateManager updateManager = updateManagerFactory.create(project)) {
        updateManager.add(update1);
        updateManager.add(update2);
        updateManager.execute();
    }
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
    assertThat(psas).hasSize(2);
    assertThat(psas.get(0).getAccountId()).isEqualTo(changeOwner.getAccount().getId());
    assertThat(psas.get(0).getLabel()).isEqualTo("Verified");
    assertThat(psas.get(0).getValue()).isEqualTo((short) 1);
    assertThat(psas.get(1).getAccountId()).isEqualTo(otherUser.getAccount().getId());
    assertThat(psas.get(1).getLabel()).isEqualTo("Code-Review");
    assertThat(psas.get(1).getValue()).isEqualTo((short) 2);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 18 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method removeReviewer.

@Test
public void removeReviewer() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewer(otherUser.getAccount().getId(), REVIEWER);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putApproval("Code-Review", (short) 1);
    update.commit();
    update = newUpdate(c, otherUser);
    update.putApproval("Code-Review", (short) 1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> psas = notes.getApprovals().get(c.currentPatchSetId());
    assertThat(psas).hasSize(2);
    assertThat(psas.get(0).getAccountId()).isEqualTo(changeOwner.getAccount().getId());
    assertThat(psas.get(1).getAccountId()).isEqualTo(otherUser.getAccount().getId());
    update = newUpdate(c, changeOwner);
    update.removeReviewer(otherUser.getAccount().getId());
    update.commit();
    notes = newNotes(c);
    psas = notes.getApprovals().get(c.currentPatchSetId());
    assertThat(psas).hasSize(1);
    assertThat(psas.get(0).getAccountId()).isEqualTo(changeOwner.getAccount().getId());
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 19 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.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("Code-Review", (short) -1);
    update.commit();
    PatchSet.Id ps1 = c.currentPatchSetId();
    incrementPatchSet(c);
    update = newUpdate(c, changeOwner);
    update.putApproval("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.getPatchSetId()).isEqualTo(ps1);
    assertThat(psa1.getAccountId().get()).isEqualTo(1);
    assertThat(psa1.getLabel()).isEqualTo("Code-Review");
    assertThat(psa1.getValue()).isEqualTo((short) -1);
    assertThat(psa1.getGranted()).isEqualTo(truncate(after(c, 2000)));
    PatchSetApproval psa2 = Iterables.getOnlyElement(psas.get(ps2));
    assertThat(psa2.getPatchSetId()).isEqualTo(ps2);
    assertThat(psa2.getAccountId().get()).isEqualTo(1);
    assertThat(psa2.getLabel()).isEqualTo("Code-Review");
    assertThat(psa2.getValue()).isEqualTo((short) +1);
    assertThat(psa2.getGranted()).isEqualTo(truncate(after(c, 4000)));
}
Also used : PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RequestId(com.google.gerrit.server.util.RequestId) GerritServerId(com.google.gerrit.server.config.GerritServerId) ObjectId(org.eclipse.jgit.lib.ObjectId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 20 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.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.getAccountId()).isEqualTo(otherUserId);
    assertThat(psa.getLabel()).isEqualTo("Not-For-Long");
    assertThat(psa.getValue()).isEqualTo((short) 1);
    update = newUpdate(c, changeOwner);
    update.removeApprovalFor(otherUserId, "Not-For-Long");
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getApprovals()).containsExactlyEntriesIn(ImmutableListMultimap.of(psa.getPatchSetId(), new PatchSetApproval(psa.getKey(), (short) 0, update.getWhen())));
    // 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.getAccountId()).isEqualTo(otherUserId);
    assertThat(psa.getLabel()).isEqualTo("Not-For-Long");
    assertThat(psa.getValue()).isEqualTo((short) 2);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)71 Change (com.google.gerrit.reviewdb.client.Change)37 Test (org.junit.Test)32 Account (com.google.gerrit.reviewdb.client.Account)17 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)17 LabelType (com.google.gerrit.common.data.LabelType)14 LabelId (com.google.gerrit.reviewdb.client.LabelId)13 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)10 ChangeData (com.google.gerrit.server.query.change.ChangeData)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 RevId (com.google.gerrit.reviewdb.client.RevId)8 Timestamp (java.sql.Timestamp)8 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)7 HashMap (java.util.HashMap)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 LabelTypes (com.google.gerrit.common.data.LabelTypes)6 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 RequestId (com.google.gerrit.server.util.RequestId)5