Search in sources :

Example 56 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CommentPorterTest method commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError.

@Test
public void commentsAreNotDroppedWhenRetrievingCommitSha1sHasUnexpectedError() {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) Test(org.junit.Test)

Example 57 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CommentPorterTest method commentsAreNotDroppedWhenDiffHasUnexpectedError.

@Test
public void commentsAreNotDroppedWhenDiffHasUnexpectedError() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 58 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CommentPorterTest method commentsAreNotDroppedWhenDiffNotAvailable.

@Test
public void commentsAreNotDroppedWhenDiffNotAvailable() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(DiffNotAvailableException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).isNotEmpty();
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 59 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class CommentPorterTest method commentsAreMappedToPatchsetLevelOnDiffError.

@Test
public void commentsAreMappedToPatchsetLevelOnDiffError() throws Exception {
    Project.NameKey project = Project.nameKey("myProject");
    Change.Id changeId = Change.id(1);
    Change change = createChange(project, changeId);
    PatchSet patchset1 = createPatchset(PatchSet.id(changeId, 1));
    PatchSet patchset2 = createPatchset(PatchSet.id(changeId, 2));
    ChangeNotes changeNotes = mockChangeNotes(project, change, patchset1, patchset2);
    CommentPorter commentPorter = new CommentPorter(diffOperations, commentsUtil, metrics);
    HumanComment comment = createComment(patchset1.id(), "myFile");
    when(commentsUtil.determineCommitId(any(), any(), anyShort())).thenReturn(Optional.of(dummyObjectId));
    when(diffOperations.listModifiedFiles(any(Project.NameKey.class), any(ObjectId.class), any(ObjectId.class), any(DiffOptions.class))).thenThrow(IllegalStateException.class);
    ImmutableList<HumanComment> portedComments = commentPorter.portComments(changeNotes, patchset2, ImmutableList.of(comment), ImmutableList.of());
    assertThat(portedComments).comparingElementsUsing(hasFilePath()).containsExactly(Patch.PATCHSET_LEVEL);
}
Also used : Project(com.google.gerrit.entities.Project) DiffOptions(com.google.gerrit.server.patch.DiffOptions) ObjectId(org.eclipse.jgit.lib.ObjectId) PatchSet(com.google.gerrit.entities.PatchSet) Change(com.google.gerrit.entities.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) HumanComment(com.google.gerrit.entities.HumanComment) BranchNameKey(com.google.gerrit.entities.BranchNameKey) Test(org.junit.Test)

Example 60 with ChangeNotes

use of com.google.gerrit.server.notedb.ChangeNotes in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method emptyTopic.

@Test
public void emptyTopic() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getPatchSetId().getParentKey();
    Change c = db.changes().get(id);
    assertThat(c.getTopic()).isNull();
    c.setTopic("");
    db.changes().update(Collections.singleton(c));
    checker.rebuildAndCheckChanges(id);
    setNotesMigration(true, true);
    // Rebuild and check was successful, but NoteDb doesn't support storing an
    // empty topic, so it comes out as null.
    ChangeNotes notes = notesFactory.create(db, project, id);
    assertThat(notes.getChange().getTopic()).isNull();
}
Also used : Change(com.google.gerrit.reviewdb.client.Change) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)134 Test (org.junit.Test)54 Change (com.google.gerrit.entities.Change)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)43 PatchSet (com.google.gerrit.entities.PatchSet)42 ObjectId (org.eclipse.jgit.lib.ObjectId)33 StorageException (com.google.gerrit.exceptions.StorageException)22 Change (com.google.gerrit.reviewdb.client.Change)21 Project (com.google.gerrit.entities.Project)17 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 FixInput (com.google.gerrit.extensions.api.changes.FixInput)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 HumanComment (com.google.gerrit.entities.HumanComment)13 TestChanges.newPatchSet (com.google.gerrit.testing.TestChanges.newPatchSet)12 IOException (java.io.IOException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)10 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)10 AuthException (com.google.gerrit.extensions.restapi.AuthException)9