Search in sources :

Example 11 with Repo

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

the class AbstractQueryChangesTest method byUnresolved.

@Test
public void byUnresolved() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    Change change3 = insert(repo, newChange(repo));
    // Change1 has one resolved comment (unresolvedcount = 0)
    // Change2 has one unresolved comment (unresolvedcount = 1)
    // Change3 has one resolved comment and one unresolved comment (unresolvedcount = 1)
    addComment(change1.getChangeId(), "comment 1", false);
    addComment(change2.getChangeId(), "comment 2", true);
    addComment(change3.getChangeId(), "comment 3", false);
    addComment(change3.getChangeId(), "comment 4", true);
    assertQuery("has:unresolved", change3, change2);
    assertQuery("unresolved:0", change1);
    List<ChangeInfo> changeInfos = assertQuery("unresolved:>=0", change3, change2, change1);
    // Change3
    assertThat(changeInfos.get(0).unresolvedCommentCount).isEqualTo(1);
    // Change2
    assertThat(changeInfos.get(1).unresolvedCommentCount).isEqualTo(1);
    // Change1
    assertThat(changeInfos.get(2).unresolvedCommentCount).isEqualTo(0);
    assertQuery("unresolved:>0", change3, change2);
    assertQuery("unresolved:<1", change1);
    assertQuery("unresolved:<=1", change3, change2, change1);
    assertQuery("unresolved:1", change3, change2);
    assertQuery("unresolved:>1");
    assertQuery("unresolved:>=1", change3, change2);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 12 with Repo

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

the class AbstractQueryChangesTest method byCommit.

@Test
public void byCommit() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins = newChange(repo);
    Change change = insert(repo, ins);
    String sha = ins.getCommitId().name();
    assertQuery("0000000000000000000000000000000000000000");
    assertQuery("commit:0000000000000000000000000000000000000000");
    for (int i = 0; i <= 36; i++) {
        String q = sha.substring(0, 40 - i);
        assertQuery(q, change);
        assertQuery("commit:" + q, change);
    }
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 13 with Repo

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

the class AbstractQueryChangesTest method byAge.

@Test
public void byAge() throws Exception {
    long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
    resetTimeWithClockStep(thirtyHoursInMs, MILLISECONDS);
    TestRepository<Repo> repo = createProject("repo");
    long startMs = TestTimeUtil.START.toEpochMilli();
    Change change1 = insert(repo, newChange(repo), null, Instant.ofEpochMilli(startMs));
    Change change2 = insert(repo, newChange(repo), null, Instant.ofEpochMilli(startMs + thirtyHoursInMs));
    // Stop time so age queries use the same endpoint.
    TestTimeUtil.setClockStep(0, MILLISECONDS);
    TestTimeUtil.setClock(new Timestamp(startMs + 2 * thirtyHoursInMs));
    long nowMs = TimeUtil.nowMs();
    assertThat(lastUpdatedMs(change2) - lastUpdatedMs(change1)).isEqualTo(thirtyHoursInMs);
    assertThat(nowMs - lastUpdatedMs(change2)).isEqualTo(thirtyHoursInMs);
    assertThat(TimeUtil.nowMs()).isEqualTo(nowMs);
    // Change1 was last updated on 2009-09-30 21:00:00 -0000
    // Change2 was last updated on 2009-10-02 03:00:00 -0000
    // The endpoint is 2009-10-03 09:00:00 -0000
    assertQuery("-age:1d");
    assertQuery("-age:" + (30 * 60 - 1) + "m");
    assertQuery("-age:2d", change2);
    assertQuery("-age:3d", change2, change1);
    assertQuery("age:3d");
    assertQuery("age:2d", change1);
    assertQuery("age:1d", change2, change1);
    // Same test as above, but using filter code path.
    assertQuery(makeIndexedPredicateFilterQuery("-age:1d"));
    assertQuery(makeIndexedPredicateFilterQuery("-age:" + (30 * 60 - 1) + "m"));
    assertQuery(makeIndexedPredicateFilterQuery("-age:2d"), change2);
    assertQuery(makeIndexedPredicateFilterQuery("-age:3d"), change2, change1);
    assertQuery(makeIndexedPredicateFilterQuery("age:3d"));
    assertQuery(makeIndexedPredicateFilterQuery("age:2d"), change1);
    assertQuery(makeIndexedPredicateFilterQuery("age:1d"), change2, change1);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 14 with Repo

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

the class AbstractQueryChangesTest method byStatusClosed.

@Test
public void byStatusClosed() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.MERGED);
    Change change1 = insert(repo, ins1);
    ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.ABANDONED);
    Change change2 = insert(repo, ins2);
    insert(repo, newChangeWithStatus(repo, Change.Status.NEW));
    Change[] expected = new Change[] { change2, change1 };
    assertQuery("status:closed", expected);
    assertQuery("status:CLOSED", expected);
    assertQuery("status:c", expected);
    assertQuery("status:cl", expected);
    assertQuery("status:clo", expected);
    assertQuery("status:clos", expected);
    assertQuery("status:close", expected);
    assertQuery("status:closed", expected);
    assertQuery("is:closed", expected);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 15 with Repo

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

the class AbstractQueryChangesTest method byPathExact.

@Test
public void byPathExact() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change = insert(repo, newChangeWithFiles(repo, "dir/file1", "dir/file2"));
    assertQuery("path:file");
    assertQuery("path:dir");
    assertQuery("path:file1");
    assertQuery("path:file2");
    assertQuery("path:dir/file1", change);
    assertQuery("path:dir/file2", change);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)126 Test (org.junit.Test)117 Change (com.google.gerrit.entities.Change)112 Account (com.google.gerrit.entities.Account)30 RevCommit (org.eclipse.jgit.revwalk.RevCommit)30 ChangeInserter (com.google.gerrit.server.change.ChangeInserter)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)8 Project (com.google.gerrit.entities.Project)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)5 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 QueryParseException (com.google.gerrit.index.query.QueryParseException)4 IOException (java.io.IOException)4