use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byDraftBy.
@Test
public void byDraftBy() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChange(repo));
DraftInput in = new DraftInput();
in.line = 1;
in.message = "nit: trailing whitespace";
in.path = Patch.COMMIT_MSG;
gApi.changes().id(change1.getId().get()).current().createDraft(in);
in = new DraftInput();
in.line = 2;
in.message = "nit: point in the end of the statement";
in.path = Patch.COMMIT_MSG;
gApi.changes().id(change2.getId().get()).current().createDraft(in);
int user2 = accountManager.authenticate(AuthRequest.forUser("anotheruser")).getAccountId().get();
assertQuery("draftby:" + userId.get(), change2, change1);
assertQuery("draftby:" + user2);
}
use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byStatusDraft.
@Test
public void byStatusDraft() throws Exception {
TestRepository<Repo> repo = createProject("repo");
insert(repo, newChangeWithStatus(repo, Change.Status.NEW));
ChangeInserter ins2 = newChangeWithStatus(repo, Change.Status.DRAFT);
Change change2 = insert(repo, ins2);
Change[] expected = new Change[] { change2 };
assertQuery("status:draft", expected);
assertQuery("status:DRAFT", expected);
assertQuery("status:d", expected);
assertQuery("status:dr", expected);
assertQuery("status:dra", expected);
assertQuery("status:draf", expected);
assertQuery("is:draft", expected);
}
use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method refStateFields.
@Test
public void refStateFields() throws Exception {
// This test method manages primary storage manually.
assume().that(notesMigration.changePrimaryStorage()).isEqualTo(PrimaryStorage.REVIEW_DB);
Account.Id user = createAccount("user");
Project.NameKey project = new Project.NameKey("repo");
TestRepository<Repo> repo = createProject(project.get());
String path = "file";
RevCommit commit = repo.parseBody(repo.commit().message("one").add(path, "contents").create());
Change change = insert(repo, newChangeForCommit(repo, commit));
Change.Id id = change.getId();
int c = id.get();
String changeId = change.getKey().get();
requestContext.setContext(newRequestContext(user));
// Ensure one of each type of supported ref is present for the change. If
// any more refs are added, update this test to reflect them.
// Edit
gApi.changes().id(changeId).edit().create();
// Star
gApi.accounts().self().starChange(change.getId().toString());
if (notesMigration.readChanges()) {
// Robot comment.
ReviewInput rin = new ReviewInput();
RobotCommentInput rcin = new RobotCommentInput();
rcin.robotId = "happyRobot";
rcin.robotRunId = "1";
rcin.line = 1;
rcin.message = "nit: trailing whitespace";
rcin.path = path;
rin.robotComments = ImmutableMap.of(path, ImmutableList.of(rcin));
gApi.changes().id(c).current().review(rin);
}
// Draft.
DraftInput din = new DraftInput();
din.path = path;
din.line = 1;
din.message = "draft";
gApi.changes().id(c).current().createDraft(din);
if (notesMigration.readChanges()) {
// Force NoteDb primary.
change = ReviewDbUtil.unwrapDb(db).changes().get(id);
change.setNoteDbState(NoteDbChangeState.NOTE_DB_PRIMARY_STATE);
ReviewDbUtil.unwrapDb(db).changes().update(Collections.singleton(change));
indexer.index(db, change);
}
QueryOptions opts = IndexedChangeQuery.createOptions(indexConfig, 0, 1, StalenessChecker.FIELDS);
ChangeData cd = indexes.getSearchIndex().get(id, opts).get();
String cs = RefNames.shard(c);
int u = user.get();
String us = RefNames.shard(u);
List<String> expectedStates = Lists.newArrayList("repo:refs/users/" + us + "/edit-" + c + "/1", "All-Users:refs/starred-changes/" + cs + "/" + u);
if (notesMigration.readChanges()) {
expectedStates.add("repo:refs/changes/" + cs + "/meta");
expectedStates.add("repo:refs/changes/" + cs + "/robot-comments");
expectedStates.add("All-Users:refs/draft-comments/" + cs + "/" + u);
}
assertThat(cd.getRefStates().stream().map(String::new).map(s -> s.substring(0, s.lastIndexOf(':'))).collect(toList())).containsExactlyElementsIn(expectedStates);
List<String> expectedPatterns = Lists.newArrayList("repo:refs/users/*/edit-" + c + "/*");
expectedPatterns.add("All-Users:refs/starred-changes/" + cs + "/*");
if (notesMigration.readChanges()) {
expectedPatterns.add("All-Users:refs/draft-comments/" + cs + "/*");
}
assertThat(cd.getRefStatePatterns().stream().map(String::new).collect(toList())).containsExactlyElementsIn(expectedPatterns);
}
use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method selfAndMe.
@Test
public void selfAndMe() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChange(repo), userId);
insert(repo, newChange(repo));
gApi.accounts().self().starChange(change1.getId().toString());
gApi.accounts().self().starChange(change2.getId().toString());
assertQuery("starredby:self", change2, change1);
assertQuery("starredby:me", change2, change1);
}
use of com.google.gerrit.testutil.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method prepopulateOnlyRequestedFields.
@Test
public void prepopulateOnlyRequestedFields() 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.setRequestedFields(ImmutableSet.of(ChangeField.PATCH_SET.getName(), ChangeField.CHANGE.getName())).query(queryBuilder.parse(change.getId().toString())).entities();
assertThat(cds).hasSize(1);
ChangeData cd = cds.get(0);
cd.change();
cd.patchSets();
exception.expect(DisabledReviewDb.Disabled.class);
cd.currentApprovals();
}
Aggregations