Search in sources :

Example 56 with Change

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

the class ChangeNotesTest method revertOfIsNullByDefault.

@Test
public void revertOfIsNullByDefault() throws Exception {
    Change c = newChange();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getChange().getRevertOf()).isNull();
}
Also used : Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 57 with Change

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

the class ChangeNotesTest method tagApprovals.

@Test
public void tagApprovals() throws Exception {
    String tag1 = "jenkins";
    String tag2 = "ip";
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.VERIFIED, (short) -1);
    update.setTag(tag1);
    update.commit();
    update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.VERIFIED, (short) 1);
    update.setTag(tag2);
    update.commit();
    ChangeNotes notes = newNotes(c);
    ImmutableListMultimap<PatchSet.Id, PatchSetApproval> approvals = notes.getApprovals();
    assertThat(approvals).hasSize(1);
    assertThat(approvals.entries().asList().get(0).getValue().tag()).hasValue(tag2);
}
Also used : Change(com.google.gerrit.entities.Change) SubmissionId(com.google.gerrit.entities.SubmissionId) LabelId(com.google.gerrit.entities.LabelId) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 58 with Change

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

the class ChangeNotesTest method patchSetDescription.

@Test
public void patchSetDescription() throws Exception {
    String description = "descriptive";
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.setPsDescription(description);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getCurrentPatchSet().description()).hasValue(description);
    description = "new, now more descriptive!";
    update = newUpdate(c, changeOwner);
    update.setPsDescription(description);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getCurrentPatchSet().description()).hasValue(description);
}
Also used : Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 59 with Change

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

the class ChangeNotesTest method reissuedApproval_samePatchSet_differentUUID.

@Test
public void reissuedApproval_samePatchSet_differentUUID() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getApprovals().keySet()).containsExactly(c.currentPatchSetId());
    PatchSetApproval originalPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(originalPsa.patchSetId()).isEqualTo(c.currentPatchSetId());
    assertThat(originalPsa.accountId()).isEqualTo(changeOwner.getAccountId());
    assertThat(originalPsa.label()).isEqualTo(LabelId.CODE_REVIEW);
    assertThat(originalPsa.value()).isEqualTo((short) -1);
    assertParsedUuid(originalPsa);
    // Remove approval from current patch set
    update = newUpdate(c, changeOwner);
    update.removeApproval(LabelId.CODE_REVIEW);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getApprovals().keySet()).hasSize(1);
    PatchSetApproval removedPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(removedPsa.key()).isEqualTo(originalPsa.key());
    assertThat(removedPsa.value()).isEqualTo(0);
    // Add approval with the same author, label, value to the current patch set
    update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    notes = newNotes(c);
    assertThat(notes.getApprovals().keySet()).hasSize(1);
    PatchSetApproval reAddedPsa = Iterables.getOnlyElement(notes.getApprovals().get(c.currentPatchSetId()));
    assertThat(reAddedPsa.key()).isEqualTo(originalPsa.key());
    assertThat(reAddedPsa.value()).isEqualTo(originalPsa.value());
    // The re-added approval has a different UUID
    assertParsedUuid(reAddedPsa);
    assertThat(reAddedPsa.uuid().get()).isNotEqualTo(originalPsa.uuid().get());
}
Also used : Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 60 with Change

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

the class ChangeNotesTest method commitChangeNotesUnique.

@Test
public void commitChangeNotesUnique() throws Exception {
    // PatchSetId -> ObjectId must be a one to one mapping
    Change c = newChange();
    ChangeNotes notes = newNotes(c);
    PatchSet ps = notes.getCurrentPatchSet();
    assertThat(ps).isNotNull();
    // new revId for the same patch set, ps1
    ChangeUpdate update = newUpdate(c, changeOwner);
    RevCommit commit = tr.commit().message("PS1 again").create();
    update.setCommit(rw, commit);
    update.commit();
    StorageException e = assertThrows(StorageException.class, () -> newNotes(c));
    assertCause(e, ConfigInvalidException.class, "Multiple revisions parsed for patch set 1:" + " " + commit.name() + " and " + ps.commitId().name());
}
Also used : PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) StorageException(com.google.gerrit.exceptions.StorageException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) 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