Search in sources :

Example 1 with Repo

use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method explicitVisibleTo.

@Test
public void explicitVisibleTo() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo), userId);
    Change change2 = insert(repo, newChangeWithStatus(repo, Change.Status.DRAFT), userId);
    String q = "project:repo";
    assertQuery(q, change2, change1);
    // Second user cannot see first user's drafts.
    Account.Id user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser")).getAccountId();
    assertQuery(q + " visibleto:" + user2.get(), change1);
}
Also used : Account(com.google.gerrit.reviewdb.client.Account) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 2 with Repo

use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo 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 3 with Repo

use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method implicitVisibleTo.

@Test
public void implicitVisibleTo() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo), userId);
    Change change2 = insert(repo, newChangeWithStatus(repo, Change.Status.DRAFT), userId);
    String q = "project:repo";
    assertQuery(q, change2, change1);
    // Second user cannot see first user's drafts.
    requestContext.setContext(newRequestContext(accountManager.authenticate(AuthRequest.forUser("anotheruser")).getAccountId()));
    assertQuery(q, change1);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 4 with Repo

use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byBefore.

@Test
public void byBefore() throws Exception {
    long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
    resetTimeWithClockStep(thirtyHoursInMs, MILLISECONDS);
    TestRepository<Repo> repo = createProject("repo");
    long startMs = TestTimeUtil.START.getMillis();
    Change change1 = insert(repo, newChange(repo), null, new Timestamp(startMs));
    Change change2 = insert(repo, newChange(repo), null, new Timestamp(startMs + thirtyHoursInMs));
    TestTimeUtil.setClockStep(0, MILLISECONDS);
    assertQuery("before:2009-09-29");
    assertQuery("before:2009-09-30");
    assertQuery("before:\"2009-09-30 16:59:00 -0400\"");
    assertQuery("before:\"2009-09-30 20:59:00 -0000\"");
    assertQuery("before:\"2009-09-30 20:59:00\"");
    assertQuery("before:\"2009-09-30 17:02:00 -0400\"", change1);
    assertQuery("before:\"2009-10-01 21:02:00 -0000\"", change1);
    assertQuery("before:\"2009-10-01 21:02:00\"", change1);
    assertQuery("before:2009-10-01", change1);
    assertQuery("before:2009-10-03", change2, change1);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 5 with Repo

use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method prepopulatedFields.

@Test
public void prepopulatedFields() throws Exception {
    assume().that(notesMigration.readChanges()).isFalse();
    TestRepository<Repo> repo = createProject("repo");
    Change change = insert(repo, newChange(repo));
    db = new DisabledReviewDb();
    requestContext.setContext(newRequestContext(userId));
    // Use QueryProcessor directly instead of API so we get ChangeDatas back.
    List<ChangeData> cds = queryProcessor.query(queryBuilder.parse(change.getId().toString())).entities();
    assertThat(cds).hasSize(1);
    ChangeData cd = cds.get(0);
    cd.change();
    cd.patchSets();
    cd.currentApprovals();
    cd.changedLines();
    cd.reviewedBy();
    cd.reviewers();
    cd.unresolvedCommentCount();
    // TODO(dborowitz): Swap out GitRepositoryManager somehow? Will probably be
    // necessary for NoteDb anyway.
    cd.isMergeable();
    exception.expect(DisabledReviewDb.Disabled.class);
    cd.messages();
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)11 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)11 Test (org.junit.Test)11 DisabledReviewDb (com.google.gerrit.testutil.DisabledReviewDb)4 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)3 Timestamp (java.sql.Timestamp)3 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 Account (com.google.gerrit.reviewdb.client.Account)2 MoreObjects (com.google.common.base.MoreObjects)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 ThrowableSubject (com.google.common.truth.ThrowableSubject)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 TruthJUnit.assume (com.google.common.truth.TruthJUnit.assume)1 Nullable (com.google.gerrit.common.Nullable)1 TimeUtil (com.google.gerrit.common.TimeUtil)1