Search in sources :

Example 6 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method testByCommitsOnBranchNotMerged.

private void testByCommitsOnBranchNotMerged(TestRepository<Repo> repo, Collection<ObjectId> extra) throws Exception {
    int n = 10;
    List<String> shas = new ArrayList<>(n + extra.size());
    extra.forEach(i -> shas.add(i.name()));
    List<Integer> expectedIds = new ArrayList<>(n);
    Branch.NameKey dest = null;
    for (int i = 0; i < n; i++) {
        ChangeInserter ins = newChange(repo);
        insert(repo, ins);
        if (dest == null) {
            dest = ins.getChange().getDest();
        }
        shas.add(ins.getCommitId().name());
        expectedIds.add(ins.getChange().getId().get());
    }
    for (int i = 1; i <= 11; i++) {
        Iterable<ChangeData> cds = internalChangeQuery.byCommitsOnBranchNotMerged(repo.getRepository(), db, dest, shas, i);
        Iterable<Integer> ids = FluentIterable.from(cds).transform(in -> in.getId().get());
        String name = "limit " + i;
        assertThat(ids).named(name).hasSize(n);
        assertThat(ids).named(name).containsExactlyElementsIn(expectedIds);
    }
}
Also used : Branch(com.google.gerrit.reviewdb.client.Branch) ArrayList(java.util.ArrayList) ChangeInserter(com.google.gerrit.server.change.ChangeInserter)

Example 7 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byStatusPrefix.

@Test
public void byStatusPrefix() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
    Change change1 = insert(repo, ins1);
    insert(repo, newChangeWithStatus(repo, Change.Status.MERGED));
    assertQuery("status:n", change1);
    assertQuery("status:ne", change1);
    assertQuery("status:new", change1);
    assertQuery("status:N", change1);
    assertQuery("status:nE", change1);
    assertQuery("status:neW", change1);
    assertThatQueryException("status:nx").hasMessageThat().isEqualTo("invalid change status: nx");
    assertThatQueryException("status:newx").hasMessageThat().isEqualTo("invalid change status: newx");
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 8 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class ConsistencyCheckerIT method insertChange.

private ChangeControl insertChange(TestAccount owner, String dest) throws Exception {
    Change.Id id = new Change.Id(sequences.nextChangeId());
    ChangeInserter ins;
    try (BatchUpdate bu = newUpdate(owner.getId())) {
        RevCommit commit = patchSetCommit(new PatchSet.Id(id, 1));
        ins = changeInserterFactory.create(id, commit, dest).setValidate(false).setNotify(NotifyHandling.NONE).setFireRevisionCreated(false).setSendMail(false);
        bu.insertChange(ins).execute();
    }
    // Return control for admin regardless of owner.
    return changeControlFactory.controlFor(db, ins.getChange(), userFactory.create(adminId));
}
Also used : ChangeInserter(com.google.gerrit.server.change.ChangeInserter) TestChanges.newPatchSet(com.google.gerrit.testutil.TestChanges.newPatchSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byStatusOpen.

@Test
public void byStatusOpen() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    ChangeInserter ins1 = newChangeWithStatus(repo, Change.Status.NEW);
    Change change1 = insert(repo, ins1);
    ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
    Change change2 = insert(repo, ins2);
    insert(repo, newChangeWithStatus(repo, Change.Status.MERGED));
    Change[] expected = new Change[] { change2, change1 };
    assertQuery("status:open", expected);
    assertQuery("status:OPEN", expected);
    assertQuery("status:o", expected);
    assertQuery("status:op", expected);
    assertQuery("status:ope", expected);
    assertQuery("status:pending", expected);
    assertQuery("status:PENDING", expected);
    assertQuery("status:p", expected);
    assertQuery("status:pe", expected);
    assertQuery("status:pen", expected);
    assertQuery("is:open", expected);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 10 with ChangeInserter

use of com.google.gerrit.server.change.ChangeInserter in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method newChange.

protected ChangeInserter newChange(TestRepository<Repo> repo, @Nullable RevCommit commit, @Nullable String branch, @Nullable Change.Status status, @Nullable String topic) throws Exception {
    if (commit == null) {
        commit = repo.parseBody(repo.commit().message("message").create());
    }
    branch = MoreObjects.firstNonNull(branch, "refs/heads/master");
    if (!branch.startsWith("refs/heads/")) {
        branch = "refs/heads/" + branch;
    }
    Change.Id id = new Change.Id(seq.nextChangeId());
    ChangeInserter ins = changeFactory.create(id, commit, branch).setValidate(false).setStatus(status).setTopic(topic);
    return ins;
}
Also used : ChangeInserter(com.google.gerrit.server.change.ChangeInserter) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) ObjectId(org.eclipse.jgit.lib.ObjectId) Change(com.google.gerrit.reviewdb.client.Change)

Aggregations

ChangeInserter (com.google.gerrit.server.change.ChangeInserter)16 Change (com.google.gerrit.reviewdb.client.Change)14 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)13 Test (org.junit.Test)13 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 ArrayList (java.util.ArrayList)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 RevCommit (org.eclipse.jgit.revwalk.RevCommit)2 ImmutableList (com.google.common.collect.ImmutableList)1 RobotCommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput)1 ChangeMessageInfo (com.google.gerrit.extensions.common.ChangeMessageInfo)1 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)1 Account (com.google.gerrit.reviewdb.client.Account)1 Branch (com.google.gerrit.reviewdb.client.Branch)1 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)1 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)1 BatchUpdate (com.google.gerrit.server.update.BatchUpdate)1 TestChanges.newPatchSet (com.google.gerrit.testutil.TestChanges.newPatchSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1