Search in sources :

Example 86 with Change

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

the class ChangeNotesTest method patchSetStates.

@Test
public void patchSetStates() throws Exception {
    Change c = newChange();
    PatchSet.Id psId1 = c.currentPatchSetId();
    incrementCurrentPatchSetFieldOnly(c);
    PatchSet.Id psId2 = c.currentPatchSetId();
    RevCommit commit = tr.commit().message("PS2").create();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setCommit(rw, commit);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.setChangeMessage("This is a message");
    update.putComment(HumanComment.Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.now(), "Comment", (short) 1, commit, false));
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getPatchSets().keySet()).containsExactly(psId1, psId2);
    assertThat(notes.getApprovals()).isNotEmpty();
    assertThat(notes.getChangeMessages()).isNotEmpty();
    assertThat(notes.getHumanComments()).isNotEmpty();
    // publish ps2
    update = newUpdate(c, changeOwner);
    update.setPatchSetState(PatchSetState.PUBLISHED);
    update.commit();
    // delete ps2
    update = newUpdate(c, changeOwner);
    update.setPatchSetState(PatchSetState.DELETED);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getPatchSets().keySet()).containsExactly(psId1);
    assertThat(notes.getApprovals()).isEmpty();
    assertThat(notes.getChangeMessages()).isEmpty();
    assertThat(notes.getHumanComments()).isEmpty();
}
Also used : CommentRange(com.google.gerrit.entities.CommentRange) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 87 with Change

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

the class ChangeNotesTest method putAndRemoveReviewerByEmail.

@Test
public void putAndRemoveReviewerByEmail() throws Exception {
    Address adr = Address.create("Foo Bar", "foo.bar@gerritcodereview.com");
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewerByEmail(adr, ReviewerStateInternal.REVIEWER);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.removeReviewerByEmail(adr);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getReviewersByEmail().all()).isEmpty();
}
Also used : Address(com.google.gerrit.entities.Address) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 88 with Change

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

the class ChangeNotesTest method approvalsPostSubmit.

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

Example 89 with Change

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

the class ChangeNotesTest method submitRecords.

@Test
public void submitRecords() 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("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null)), submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null))));
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<SubmitRecord> recs = notes.getSubmitRecords();
    assertThat(recs).hasSize(2);
    assertThat(recs.get(0)).isEqualTo(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel(LabelId.CODE_REVIEW, "NEED", null)));
    assertThat(recs.get(1)).isEqualTo(submitRecord("NOT_READY", null, submitLabel(LabelId.VERIFIED, "OK", changeOwner.getAccountId()), submitLabel("Alternative-Code-Review", "NEED", null)));
    assertThat(notes.getChange().getSubmissionId()).isEqualTo(submissionId.toString());
}
Also used : SubmitRecord(com.google.gerrit.entities.SubmitRecord) SubmissionId(com.google.gerrit.entities.SubmissionId) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 90 with Change

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

the class ChangeNotesTest method putOtherUsersApprovals.

@Test
public void putOtherUsersApprovals() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) 1);
    update.putApprovalFor(otherUser.getAccountId(), LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    ImmutableList<PatchSetApproval> approvals = notes.getApprovals().get(c.currentPatchSetId()).stream().sorted(comparing(a -> a.accountId().get())).collect(toImmutableList());
    assertThat(approvals).hasSize(2);
    assertThat(approvals.get(0).accountId()).isEqualTo(changeOwner.getAccountId());
    assertThat(approvals.get(0).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(0).value()).isEqualTo((short) 1);
    assertParsedUuid(approvals.get(0));
    assertThat(approvals.get(1).accountId()).isEqualTo(otherUser.getAccountId());
    assertThat(approvals.get(1).label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(approvals.get(1).value()).isEqualTo((short) -1);
    assertThat(approvals.get(1).uuid()).isPresent();
    assertParsedUuid(approvals.get(1));
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.entities.Change)659 Test (org.junit.Test)510 PatchSet (com.google.gerrit.entities.PatchSet)167 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)165 ObjectId (org.eclipse.jgit.lib.ObjectId)113 Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)112 RevCommit (org.eclipse.jgit.revwalk.RevCommit)88 Account (com.google.gerrit.entities.Account)83 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)72 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)66 List (java.util.List)64 ImmutableList (com.google.common.collect.ImmutableList)63 ChangeData (com.google.gerrit.server.query.change.ChangeData)60 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)58 PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)56 Instant (java.time.Instant)54 Project (com.google.gerrit.entities.Project)52 StorageException (com.google.gerrit.exceptions.StorageException)50 Ref (org.eclipse.jgit.lib.Ref)49 HumanComment (com.google.gerrit.entities.HumanComment)46