Search in sources :

Example 16 with Repo

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

the class AbstractQueryChangesTest method byHasDraftExcludesZombieDrafts.

/**
 * This test does not have a test about drafts computed from All-Users Repository because zombie
 * drafts can't be filtered when computing from All-Users repository. TODO(paiking): During
 * rollout, we should find a way to fix zombie drafts.
 */
public void byHasDraftExcludesZombieDrafts() throws Exception {
    Project.NameKey project = 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("has:draft", change);
    assertQuery("commentby:" + userId);
    try (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("has:draft");
        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();
    }
    indexer.index(project, id);
    assertQuery("has:draft");
}
Also used : Project(com.google.gerrit.entities.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Ref(org.eclipse.jgit.lib.Ref) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.entities.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput)

Example 17 with Repo

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

the class AbstractQueryChangesTest method byStarredBy.

private void byStarredBy() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo));
    Change change2 = insert(repo, newChange(repo));
    insert(repo, newChange(repo));
    gApi.accounts().self().starChange(change1.getId().toString());
    gApi.accounts().self().starChange(change2.getId().toString());
    Account.Id user2 = accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId();
    assertQuery("has:star", change2, change1);
    assertQuery("star:star", change2, change1);
    requestContext.setContext(newRequestContext(user2));
    assertQuery("has:star");
    assertQuery("star:star");
}
Also used : Account(com.google.gerrit.entities.Account) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change)

Example 18 with Repo

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

the class AbstractQueryChangesTest method excludeWipChangeFromReviewersDashboards.

@Test
public void excludeWipChangeFromReviewersDashboards() throws Exception {
    Account.Id user1 = createAccount("user1");
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChangeWorkInProgress(repo), userId);
    assertQuery("is:wip", change1);
    assertQuery("reviewer:" + user1);
    gApi.changes().id(change1.getChangeId()).setReadyForReview();
    assertQuery("is:wip");
    assertQuery("reviewer:" + user1);
    gApi.changes().id(change1.getChangeId()).setWorkInProgress();
    assertQuery("is:wip", change1);
    assertQuery("reviewer:" + user1);
}
Also used : Account(com.google.gerrit.entities.Account) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 19 with Repo

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

the class AbstractQueryChangesTest method byProject.

@Test
public void byProject() throws Exception {
    TestRepository<Repo> repo1 = createProject("repo1");
    TestRepository<Repo> repo2 = createProject("repo2");
    Change change1 = insert(repo1, newChange(repo1));
    Change change2 = insert(repo2, newChange(repo2));
    assertQuery("project:foo");
    assertQuery("project:repo");
    assertQuery("project:repo1", change1);
    assertQuery("project:repo2", change2);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 20 with Repo

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

the class AbstractQueryChangesTest method revertOf.

@Test
public void revertOf() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    // Create two commits and revert second commit (initial commit can't be reverted)
    Change initial = insert(repo, newChange(repo));
    gApi.changes().id(initial.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(initial.getChangeId()).current().submit();
    ChangeInfo changeToRevert = gApi.changes().create(new ChangeInput("repo", "master", "commit to revert")).get();
    gApi.changes().id(changeToRevert.id).current().review(ReviewInput.approve());
    gApi.changes().id(changeToRevert.id).current().submit();
    ChangeInfo changeThatReverts = gApi.changes().id(changeToRevert.id).revert().get();
    assertQueryByIds("revertof:" + changeToRevert._number, Change.id(changeThatReverts._number));
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) 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