Search in sources :

Example 61 with PatchSetApproval

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

the class ChangeBundleTest method diffPatchSetApprovalsIgnoresPostSubmitBitOnZeroVote.

@Test
public void diffPatchSetApprovalsIgnoresPostSubmitBitOnZeroVote() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    c.setStatus(Change.Status.MERGED);
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 0, TimeUtil.nowTs());
    a1.setPostSubmit(false);
    PatchSetApproval a2 = clone(a1);
    a2.setPostSubmit(true);
    // Both are ReviewDb, exact match is required.
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {false} != {true}");
    // One NoteDb, postSubmit is ignored.
    b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
    // postSubmit is not ignored if vote isn't 0.
    a1.setValue((short) 1);
    a2.setValue((short) 1);
    assertDiffs(b1, b2, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {false} != {true}");
    assertDiffs(b2, b1, "postSubmit differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {true} != {false}");
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 62 with PatchSetApproval

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

the class ChangeBundleTest method diffPatchSetsGreaterThanCurrent.

@Test
public void diffPatchSetsGreaterThanCurrent() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSet ps1 = new PatchSet(new PatchSet.Id(c.getId(), 1));
    ps1.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps1.setUploader(accountId);
    ps1.setCreatedOn(TimeUtil.nowTs());
    PatchSet ps2 = new PatchSet(new PatchSet.Id(c.getId(), 2));
    ps2.setRevision(new RevId("badc0feebadc0feebadc0feebadc0feebadc0fee"));
    ps2.setUploader(accountId);
    ps2.setCreatedOn(TimeUtil.nowTs());
    assertThat(ps2.getId().get()).isGreaterThan(c.currentPatchSetId().get());
    ChangeMessage cm1 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid1"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
    ChangeMessage cm2 = new ChangeMessage(new ChangeMessage.Key(c.getId(), "uuid2"), accountId, TimeUtil.nowTs(), c.currentPatchSetId());
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(ps1.getId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    PatchSetApproval a2 = new PatchSetApproval(new PatchSetApproval.Key(ps2.getId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    // Both ReviewDb.
    ChangeBundle b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "ChangeMessage.Key sets differ: [] only in A; [" + cm2.getKey() + "] only in B", "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
    // One NoteDb.
    b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "ChangeMessages differ for Change.Id " + c.getId() + "\nOnly in B:\n  " + cm2, "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
    // Both NoteDb.
    b1 = new ChangeBundle(c, messages(cm1), patchSets(ps1), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(cm1, cm2), patchSets(ps1, ps2), approvals(a1, a2), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "ChangeMessages differ for Change.Id " + c.getId() + "\nOnly in B:\n  " + cm2, "PatchSet.Id sets differ: [] only in A; [" + ps2.getId() + "] only in B", "PatchSetApproval.Key sets differ: [] only in A; [" + a2.getKey() + "] only in B");
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 63 with PatchSetApproval

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

the class ChangeBundleTest method diffPatchSetApprovalsAllowsTruncatedTimestampInNoteDb.

@Test
public void diffPatchSetApprovalsAllowsTruncatedTimestampInNoteDb() throws Exception {
    Change c = TestChanges.newChange(project, accountId);
    PatchSetApproval a1 = new PatchSetApproval(new PatchSetApproval.Key(c.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, c.getCreatedOn());
    PatchSetApproval a2 = clone(a1);
    a2.setGranted(new Timestamp(new DateTime(1900, 1, 1, 0, 0, 0, DateTimeZone.forTimeZone(TimeZone.getDefault())).getMillis()));
    // Both are ReviewDb, exact match is required.
    ChangeBundle b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "granted differs for PatchSetApproval.Key " + c.getId() + "%2C1,100,Code-Review:" + " {2009-09-30 17:00:00.0} != {1900-01-01 00:00:00.0}");
    // Truncating NoteDb timestamp is allowed.
    b1 = new ChangeBundle(c, messages(), latest(c), approvals(a1), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c, messages(), latest(c), approvals(a2), comments(), reviewers(), REVIEW_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Timestamp(java.sql.Timestamp) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 64 with PatchSetApproval

use of com.google.gerrit.reviewdb.client.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("Verified", (short) 1);
    Change c2 = newChange();
    ChangeUpdate update2 = newUpdate(c2, otherUser);
    update2.putApproval("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.getLabel()).isEqualTo("Verified");
    PatchSetApproval approval2 = newNotes(c2).getApprovals().get(c2.currentPatchSetId()).iterator().next();
    assertThat(approval2.getLabel()).isEqualTo("Code-Review");
}
Also used : RefNames.changeMetaRef(com.google.gerrit.reviewdb.client.RefNames.changeMetaRef) Ref(org.eclipse.jgit.lib.Ref) Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 65 with PatchSetApproval

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

the class ChangeNotesTest method approvalsDuringSubmit.

@Test
public void approvalsDuringSubmit() 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();
    Account.Id ownerId = changeOwner.getAccountId();
    Account.Id otherId = otherUser.getAccountId();
    update = newUpdate(c, otherUser);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel("Verified", "OK", ownerId), submitLabel("Code-Review", "NEED", null))));
    update.putApproval("Other-Label", (short) 1);
    update.putApprovalFor(ownerId, "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).getAccountId()).isEqualTo(ownerId);
    assertThat(approvals.get(0).getLabel()).isEqualTo("Verified");
    assertThat(approvals.get(0).getValue()).isEqualTo(1);
    assertThat(approvals.get(0).isPostSubmit()).isFalse();
    assertThat(approvals.get(1).getAccountId()).isEqualTo(ownerId);
    assertThat(approvals.get(1).getLabel()).isEqualTo("Code-Review");
    assertThat(approvals.get(1).getValue()).isEqualTo(2);
    // During submit.
    assertThat(approvals.get(1).isPostSubmit()).isFalse();
    assertThat(approvals.get(2).getAccountId()).isEqualTo(otherId);
    assertThat(approvals.get(2).getLabel()).isEqualTo("Other-Label");
    assertThat(approvals.get(2).getValue()).isEqualTo(2);
    assertThat(approvals.get(2).isPostSubmit()).isTrue();
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) 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)

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