Search in sources :

Example 21 with Project

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

the class AbstractQueryChangesTest method insert.

protected Change insert(TestRepository<Repo> repo, ChangeInserter ins, @Nullable Account.Id owner, Timestamp createdOn) throws Exception {
    Project.NameKey project = new Project.NameKey(repo.getRepository().getDescription().getRepositoryName());
    Account.Id ownerId = owner != null ? owner : userId;
    IdentifiedUser user = userFactory.create(ownerId);
    try (BatchUpdate bu = updateFactory.create(db, project, user, createdOn)) {
        bu.insertChange(ins);
        bu.execute();
        return ins.getChange();
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) BatchUpdate(com.google.gerrit.server.update.BatchUpdate)

Example 22 with Project

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

the class AbstractQueryChangesTest method byDraftByExcludesZombieDrafts.

@Test
public void byDraftByExcludesZombieDrafts() throws Exception {
    assume().that(notesMigration.readChanges()).isTrue();
    Project.NameKey project = new Project.NameKey("repo");
    TestRepository<Repo> repo = createProject(project.get());
    Change change = insert(repo, newChange(repo));
    Change.Id id = change.getId();
    DraftInput in = new DraftInput();
    in.line = 1;
    in.message = "nit: trailing whitespace";
    in.path = Patch.COMMIT_MSG;
    gApi.changes().id(id.get()).current().createDraft(in);
    assertQuery("draftby:" + userId, change);
    assertQuery("commentby:" + userId);
    TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName));
    Ref draftsRef = allUsers.getRepository().exactRef(RefNames.refsDraftComments(id, userId));
    assertThat(draftsRef).isNotNull();
    ReviewInput rin = ReviewInput.dislike();
    rin.drafts = DraftHandling.PUBLISH_ALL_REVISIONS;
    gApi.changes().id(id.get()).current().review(rin);
    assertQuery("draftby:" + userId);
    assertQuery("commentby:" + userId, change);
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNull();
    // Re-add drafts ref and ensure it gets filtered out during indexing.
    allUsers.update(draftsRef.getName(), draftsRef.getObjectId());
    assertThat(allUsers.getRepository().exactRef(draftsRef.getName())).isNotNull();
    if (PrimaryStorage.of(change) == PrimaryStorage.REVIEW_DB && !notesMigration.disableChangeReviewDb()) {
        // Record draft ref in noteDbState as well.
        ReviewDb db = ReviewDbUtil.unwrapDb(this.db);
        change = db.changes().get(id);
        NoteDbChangeState.applyDelta(change, NoteDbChangeState.Delta.create(id, Optional.empty(), ImmutableMap.of(userId, draftsRef.getObjectId())));
        db.changes().update(Collections.singleton(change));
    }
    indexer.index(db, project, id);
    assertQuery("draftby:" + userId);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Ref(org.eclipse.jgit.lib.Ref) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) Test(org.junit.Test)

Example 23 with Project

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

the class PatchListCacheImpl method getDiffSummary.

@Override
public DiffSummary getDiffSummary(Change change, PatchSet patchSet) throws PatchListNotAvailableException {
    Project.NameKey project = change.getProject();
    ObjectId b = ObjectId.fromString(patchSet.getRevision().get());
    Whitespace ws = Whitespace.IGNORE_NONE;
    return getDiffSummary(DiffSummaryKey.fromPatchListKey(PatchListKey.againstDefaultBase(b, ws)), project);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ObjectId(org.eclipse.jgit.lib.ObjectId) Whitespace(com.google.gerrit.extensions.client.DiffPreferencesInfo.Whitespace)

Example 24 with Project

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

the class ChangeBundleTest method diffChangesSanitizesSubjectsBeforeComparison.

@Test
public void diffChangesSanitizesSubjectsBeforeComparison() throws Exception {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    c1.setCurrentPatchSet(c1.currentPatchSetId(), "Subject\r\rbody", "Original");
    Change c2 = clone(c1);
    c2.setCurrentPatchSet(c2.currentPatchSetId(), "Subject  body", "Original");
    // Both ReviewDb, exact match required
    ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "subject differs for Change.Id " + c1.getId() + ":" + " {Subject\r\rbody} != {Subject  body}");
    // Both NoteDb, exact match required (although it should be impossible to
    // create a NoteDb change with '\r' in the subject).
    b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertDiffs(b1, b2, "subject differs for Change.Id " + c1.getId() + ":" + " {Subject\r\rbody} != {Subject  body}");
    // One ReviewDb, one NoteDb, '\r' is normalized to ' '.
    b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
    assertNoDiffs(b2, b1);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 25 with Project

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

the class ChangeBundleTest method diffChangesDoesntTrimLeadingNonSpaceWhitespaceFromSubject.

@Test
public void diffChangesDoesntTrimLeadingNonSpaceWhitespaceFromSubject() throws Exception {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    Change c2 = clone(c1);
    c2.setCurrentPatchSet(c1.currentPatchSetId(), "\t" + c1.getSubject(), c1.getOriginalSubject());
    // Both ReviewDb.
    ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "subject differs for Change.Id " + c1.getId() + ":" + " {Change subject} != {\tChange subject}");
    // One NoteDb.
    b1 = new ChangeBundle(c1, messages(), latest(c1), approvals(), comments(), reviewers(), NOTE_DB);
    b2 = new ChangeBundle(c2, messages(), latest(c2), approvals(), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "subject differs for Change.Id " + c1.getId() + ":" + " {Change subject} != {\tChange subject}");
    assertDiffs(b2, b1, "subject differs for Change.Id " + c1.getId() + ":" + " {\tChange subject} != {Change subject}");
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.reviewdb.client.Project)93 Test (org.junit.Test)37 Change (com.google.gerrit.reviewdb.client.Change)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 Branch (com.google.gerrit.reviewdb.client.Branch)21 Account (com.google.gerrit.reviewdb.client.Account)19 Config (org.eclipse.jgit.lib.Config)18 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)17 Repository (org.eclipse.jgit.lib.Repository)17 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 SubmoduleSectionParser (com.google.gerrit.server.util.SubmoduleSectionParser)14 IOException (java.io.IOException)14 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)13 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)13 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)12 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)12 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12