Search in sources :

Example 76 with Change

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

the class ChangeNotesTest method changeMessageOnePatchSet.

@Test
public void changeMessageOnePatchSet() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putReviewer(changeOwner.getAccount().getId(), REVIEWER);
    update.setChangeMessage("Just a little code change.\n");
    update.commit();
    PatchSet.Id ps1 = c.currentPatchSetId();
    ChangeNotes notes = newNotes(c);
    ListMultimap<PatchSet.Id, ChangeMessage> changeMessages = notes.getChangeMessagesByPatchSet();
    assertThat(changeMessages.keySet()).containsExactly(ps1);
    ChangeMessage cm = Iterables.getOnlyElement(changeMessages.get(ps1));
    assertThat(cm.getMessage()).isEqualTo("Just a little code change.\n");
    assertThat(cm.getAuthor()).isEqualTo(changeOwner.getAccount().getId());
    assertThat(cm.getPatchSetId()).isEqualTo(ps1);
}
Also used : ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) 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) Test(org.junit.Test)

Example 77 with Change

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

the class ChangeNotesTest method tagInlineCommenrts.

@Test
public void tagInlineCommenrts() throws Exception {
    String tag = "jenkins";
    Change c = newChange();
    RevCommit commit = tr.commit().message("PS2").create();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putComment(Status.PUBLISHED, newComment(c.currentPatchSetId(), "a.txt", "uuid1", new CommentRange(1, 2, 3, 4), 1, changeOwner, null, TimeUtil.nowTs(), "Comment", (short) 1, commit.name(), false));
    update.setTag(tag);
    update.commit();
    ChangeNotes notes = newNotes(c);
    ImmutableListMultimap<RevId, Comment> comments = notes.getComments();
    assertThat(comments).hasSize(1);
    assertThat(comments.entries().asList().get(0).getValue().tag).isEqualTo(tag);
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) Change(com.google.gerrit.reviewdb.client.Change) RevId(com.google.gerrit.reviewdb.client.RevId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 78 with Change

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

the class ChangeNotesTest method approvalsMultipleApprovals.

@Test
public void approvalsMultipleApprovals() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval("Code-Review", (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    PatchSetApproval psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(psa.getLabel()).isEqualTo("Code-Review");
    assertThat(psa.getValue()).isEqualTo((short) -1);
    update = newUpdate(c, changeOwner);
    update.putApproval("Code-Review", (short) 1);
    update.commit();
    notes = newNotes(c);
    psa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(psa.getLabel()).isEqualTo("Code-Review");
    assertThat(psa.getValue()).isEqualTo((short) 1);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 79 with Change

use of com.google.gerrit.reviewdb.client.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("Code-Review", (short) 1);
    update.putApprovalFor(otherUser.getAccountId(), "Code-Review", (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    List<PatchSetApproval> approvals = ReviewDbUtil.intKeyOrdering().onResultOf(PatchSetApproval::getAccountId).sortedCopy(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(approvals).hasSize(2);
    assertThat(approvals.get(0).getAccountId()).isEqualTo(changeOwner.getAccountId());
    assertThat(approvals.get(0).getLabel()).isEqualTo("Code-Review");
    assertThat(approvals.get(0).getValue()).isEqualTo((short) 1);
    assertThat(approvals.get(1).getAccountId()).isEqualTo(otherUser.getAccountId());
    assertThat(approvals.get(1).getLabel()).isEqualTo("Code-Review");
    assertThat(approvals.get(1).getValue()).isEqualTo((short) -1);
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 80 with Change

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

the class ChangeNotesTest method patchLineCommentMultipleDraftsSameSidePublishOne.

@Test
public void patchLineCommentMultipleDraftsSameSidePublishOne() throws Exception {
    Change c = newChange();
    String uuid1 = "uuid1";
    String uuid2 = "uuid2";
    String rev = "abcd4567abcd4567abcd4567abcd4567abcd4567";
    CommentRange range1 = new CommentRange(1, 1, 2, 2);
    CommentRange range2 = new CommentRange(2, 2, 3, 3);
    String filename = "filename1";
    short side = (short) 1;
    Timestamp now = TimeUtil.nowTs();
    PatchSet.Id psId = c.currentPatchSetId();
    // Write two drafts on the same side of one patch set.
    ChangeUpdate update = newUpdate(c, otherUser);
    update.setPatchSetId(psId);
    Comment comment1 = newComment(psId, filename, uuid1, range1, range1.getEndLine(), otherUser, null, now, "comment on ps1", side, rev, false);
    Comment comment2 = newComment(psId, filename, uuid2, range2, range2.getEndLine(), otherUser, null, now, "other on ps1", side, rev, false);
    update.putComment(Status.DRAFT, comment1);
    update.putComment(Status.DRAFT, comment2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(new RevId(rev), comment1, new RevId(rev), comment2)).inOrder();
    assertThat(notes.getComments()).isEmpty();
    // Publish first draft.
    update = newUpdate(c, otherUser);
    update.setPatchSetId(psId);
    update.putComment(Status.PUBLISHED, comment1);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getDraftComments(otherUserId)).containsExactlyEntriesIn(ImmutableListMultimap.of(new RevId(rev), comment2));
    assertThat(notes.getComments()).containsExactlyEntriesIn(ImmutableListMultimap.of(new RevId(rev), comment1));
}
Also used : Comment(com.google.gerrit.reviewdb.client.Comment) CommentRange(com.google.gerrit.reviewdb.client.CommentRange) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) RevId(com.google.gerrit.reviewdb.client.RevId) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)390 Test (org.junit.Test)254 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)103 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)65 Timestamp (java.sql.Timestamp)60 ObjectId (org.eclipse.jgit.lib.ObjectId)55 Account (com.google.gerrit.reviewdb.client.Account)52 RevCommit (org.eclipse.jgit.revwalk.RevCommit)50 OrmException (com.google.gwtorm.server.OrmException)46 RevId (com.google.gerrit.reviewdb.client.RevId)45 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)36 PatchSetApproval (com.google.gerrit.reviewdb.client.PatchSetApproval)35 Comment (com.google.gerrit.reviewdb.client.Comment)34 Project (com.google.gerrit.reviewdb.client.Project)34 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)34 Repository (org.eclipse.jgit.lib.Repository)34 ChangeMessage (com.google.gerrit.reviewdb.client.ChangeMessage)30 CommentRange (com.google.gerrit.reviewdb.client.CommentRange)30 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)29 RevWalk (org.eclipse.jgit.revwalk.RevWalk)29