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);
}
}
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");
}
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));
}
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);
}
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;
}
Aggregations