Search in sources :

Example 16 with SubmissionId

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

the class ChangeNotesTest method approvalsDuringSubmit.

@Test
public void approvalsDuringSubmit() 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();
    Account.Id ownerId = changeOwner.getAccountId();
    Account.Id otherId = otherUser.getAccountId();
    update = newUpdate(c, otherUser);
    update.merge(submissionId, ImmutableList.of(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", ownerId), submitLabel(LabelId.CODE_REVIEW, "NEED", null))));
    update.putApproval("Other-Label", (short) 1);
    update.putApprovalFor(ownerId, LabelId.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).accountId()).isEqualTo(ownerId);
    assertThat(approvals.get(0).label()).isEqualTo(LabelId.VERIFIED);
    assertThat(approvals.get(0).value()).isEqualTo(1);
    assertThat(approvals.get(0).postSubmit()).isFalse();
    assertParsedUuid(approvals.get(0));
    assertThat(approvals.get(1).accountId()).isEqualTo(ownerId);
    assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(1).value()).isEqualTo(2);
    // During submit.
    assertThat(approvals.get(1).postSubmit()).isFalse();
    assertParsedUuid(approvals.get(1));
    assertThat(approvals.get(2).accountId()).isEqualTo(otherId);
    assertThat(approvals.get(2).label()).isEqualTo("Other-Label");
    assertThat(approvals.get(2).value()).isEqualTo(2);
    assertThat(approvals.get(2).postSubmit()).isTrue();
    assertParsedUuid(approvals.get(2));
}
Also used : Account(com.google.gerrit.entities.Account) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 17 with SubmissionId

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

the class ChangeNotesTest method latestSubmitRecordsOnly.

@Test
public void latestSubmitRecordsOnly() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Submit patch set 1");
    update.merge(submissionId, ImmutableList.of(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", otherUser.getAccountId()))));
    update.commit();
    incrementPatchSet(c);
    update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Submit patch set 2");
    update.merge(submissionId, ImmutableList.of(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", changeOwner.getAccountId()))));
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getSubmitRecords()).containsExactly(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", changeOwner.getAccountId())));
    assertThat(notes.getChange().getSubmissionId()).isEqualTo(submissionId.toString());
}
Also used : SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 18 with SubmissionId

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

the class ChangeNotesTest method latestMergedOn.

@Test
public void latestMergedOn() throws Exception {
    Change c = newChange();
    SubmissionId submissionId = new SubmissionId(c);
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Update patch set 1");
    update.merge(submissionId, ImmutableList.of(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", otherUser.getAccountId()))));
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getMergedOn()).isPresent();
    Instant mergedOn = notes.getMergedOn().get();
    assertThat(mergedOn).isEqualTo(notes.getChange().getLastUpdatedOn());
    incrementPatchSet(c);
    update = newUpdate(c, changeOwner);
    update.setSubjectForCommit("Update patch set 2");
    update.merge(submissionId, ImmutableList.of(submitRecord("OK", null, submitLabel(LabelId.CODE_REVIEW, "OK", changeOwner.getAccountId()))));
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getMergedOn().get()).isGreaterThan(mergedOn);
    assertThat(notes.getMergedOn().get()).isEqualTo(notes.getChange().getLastUpdatedOn());
}
Also used : Instant(java.time.Instant) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

SubmissionId (com.google.gerrit.entities.SubmissionId)18 Change (com.google.gerrit.entities.Change)13 Test (org.junit.Test)12 ObjectId (org.eclipse.jgit.lib.ObjectId)5 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)4 Instant (java.time.Instant)4 Joiner (com.google.common.base.Joiner)3 SubmitRecord (com.google.gerrit.entities.SubmitRecord)3 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)3 BatchUpdateOp (com.google.gerrit.server.update.BatchUpdateOp)3 ChangeContext (com.google.gerrit.server.update.ChangeContext)3 MoreObjects.firstNonNull (com.google.common.base.MoreObjects.firstNonNull)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSetMultimap (com.google.common.collect.ImmutableSetMultimap)2 ListMultimap (com.google.common.collect.ListMultimap)2 MultimapBuilder (com.google.common.collect.MultimapBuilder)2 Account (com.google.gerrit.entities.Account)2 LabelTypes (com.google.gerrit.entities.LabelTypes)2