use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byDefault.
@Test
public void byDefault() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo));
RevCommit commit2 = repo.parseBody(repo.commit().message("foosubject").create());
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
RevCommit commit3 = repo.parseBody(repo.commit().add("Foo.java", "foo contents").create());
Change change3 = insert(repo, newChangeForCommit(repo, commit3));
ChangeInserter ins4 = newChange(repo);
Change change4 = insert(repo, ins4);
ReviewInput ri4 = new ReviewInput();
ri4.message = "toplevel";
ri4.labels = ImmutableMap.of("Code-Review", (short) 1);
gApi.changes().id(change4.getId().get()).current().review(ri4);
ChangeInserter ins5 = newChangeWithTopic(repo, "feature5");
Change change5 = insert(repo, ins5);
Change change6 = insert(repo, newChangeForBranch(repo, "branch6"));
assertQuery(change1.getId().get(), change1);
assertQuery(ChangeTriplet.format(change1), change1);
assertQuery("foosubject", change2);
assertQuery("Foo.java", change3);
assertQuery("Code-Review+1", change4);
assertQuery("toplevel", change4);
assertQuery("feature5", change5);
assertQuery("branch6", change6);
assertQuery("refs/heads/branch6", change6);
Change[] expected = new Change[] { change6, change5, change4, change3, change2, change1 };
assertQuery("user@example.com", expected);
assertQuery("repo", expected);
assertQuery("Code-Review=+1", change4);
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method bySize.
@Test
public void bySize() throws Exception {
TestRepository<Repo> repo = createProject("repo");
// added = 3, deleted = 0, delta = 3
RevCommit commit1 = repo.parseBody(repo.commit().add("file1", "foo\n\foo\nfoo").create());
// added = 0, deleted = 2, delta = 2
RevCommit commit2 = repo.parseBody(repo.commit().parent(commit1).add("file1", "foo").create());
Change change1 = insert(repo, newChangeForCommit(repo, commit1));
Change change2 = insert(repo, newChangeForCommit(repo, commit2));
assertQuery("added:>4");
assertQuery("-added:<=4");
assertQuery("added:3", change1);
assertQuery("-(added:<3 OR added:>3)", change1);
assertQuery("added:>2", change1);
assertQuery("-added:<=2", change1);
assertQuery("added:>=3", change1);
assertQuery("-added:<3", change1);
assertQuery("added:<1", change2);
assertQuery("-added:>=1", change2);
assertQuery("added:<=0", change2);
assertQuery("-added:>0", change2);
assertQuery("deleted:>3");
assertQuery("-deleted:<=3");
assertQuery("deleted:2", change2);
assertQuery("-(deleted:<2 OR deleted:>2)", change2);
assertQuery("deleted:>1", change2);
assertQuery("-deleted:<=1", change2);
assertQuery("deleted:>=2", change2);
assertQuery("-deleted:<2", change2);
assertQuery("deleted:<1", change1);
assertQuery("-deleted:>=1", change1);
assertQuery("deleted:<=0", change1);
for (String str : Lists.newArrayList("delta:", "size:")) {
assertQuery(str + "<2");
assertQuery(str + "3", change1);
assertQuery(str + ">2", change1);
assertQuery(str + ">=3", change1);
assertQuery(str + "<3", change2);
assertQuery(str + "<=2", change2);
}
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byTopic.
@Test
public void byTopic() throws Exception {
TestRepository<Repo> repo = createProject("repo");
ChangeInserter ins1 = newChangeWithTopic(repo, "feature1");
Change change1 = insert(repo, ins1);
ChangeInserter ins2 = newChangeWithTopic(repo, "feature2");
Change change2 = insert(repo, ins2);
ChangeInserter ins3 = newChangeWithTopic(repo, "Cherrypick-feature2");
Change change3 = insert(repo, ins3);
ChangeInserter ins4 = newChangeWithTopic(repo, "feature2-fixup");
Change change4 = insert(repo, ins4);
ChangeInserter ins5 = newChangeWithTopic(repo, "https://gerrit.local");
Change change5 = insert(repo, ins5);
ChangeInserter ins6 = newChangeWithTopic(repo, "git_gerrit_training");
Change change6 = insert(repo, ins6);
Change change_no_topic = insert(repo, newChange(repo));
assertQuery("intopic:foo");
assertQuery("intopic:feature1", change1);
assertQuery("intopic:feature2", change4, change3, change2);
assertQuery("topic:feature2", change2);
assertQuery("intopic:feature2", change4, change3, change2);
assertQuery("intopic:fixup", change4);
assertQuery("intopic:gerrit", change6, change5);
assertQuery("topic:\"\"", change_no_topic);
assertQuery("intopic:\"\"", change_no_topic);
assume().that(getSchema().hasField(ChangeField.PREFIX_TOPIC)).isTrue();
assertQuery("prefixtopic:feature", change4, change2, change1);
assertQuery("prefixtopic:Cher", change3);
assertQuery("prefixtopic:feature22");
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method userDestination.
@GerritConfig(name = "accounts.visibility", value = "NONE")
@Test
public void userDestination() throws Exception {
TestRepository<Repo> repo1 = createProject("repo1");
Change change1 = insert(repo1, newChange(repo1));
TestRepository<Repo> repo2 = createProject("repo2");
Change change2 = insert(repo2, newChange(repo2));
assertThatQueryException("destination:foo").hasMessageThat().isEqualTo("Unknown named destination: foo");
Account.Id anotherUserId = accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId();
String destination1 = "refs/heads/master\trepo1";
String destination2 = "refs/heads/master\trepo2";
String destination3 = "refs/heads/master\trepo1\nrefs/heads/master\trepo2";
String destination4 = "refs/heads/master\trepo3";
String destination5 = "refs/heads/other\trepo1";
try (TestRepository<Repo> allUsers = new TestRepository<>(repoManager.openRepository(allUsersName))) {
String refsUsers = RefNames.refsUsers(userId);
allUsers.branch(refsUsers).commit().add("destinations/destination1", destination1).create();
allUsers.branch(refsUsers).commit().add("destinations/destination2", destination2).create();
allUsers.branch(refsUsers).commit().add("destinations/destination3", destination3).create();
allUsers.branch(refsUsers).commit().add("destinations/destination4", destination4).create();
allUsers.branch(refsUsers).commit().add("destinations/destination5", destination5).create();
String anotherRefsUsers = RefNames.refsUsers(anotherUserId);
allUsers.branch(anotherRefsUsers).commit().add("destinations/destination6", destination1).create();
allUsers.branch(anotherRefsUsers).commit().add("destinations/destination7", destination2).create();
allUsers.branch(anotherRefsUsers).commit().add("destinations/destination8", destination3).create();
allUsers.branch(anotherRefsUsers).commit().add("destinations/destination9", destination4).create();
Ref userRef = allUsers.getRepository().exactRef(refsUsers);
Ref anotherUserRef = allUsers.getRepository().exactRef(anotherRefsUsers);
assertThat(userRef).isNotNull();
assertThat(anotherUserRef).isNotNull();
}
assertQuery("destination:destination1", change1);
assertQuery("destination:destination2", change2);
assertQuery("destination:destination3", change2, change1);
assertQuery("destination:destination4");
assertQuery("destination:destination5");
assertQuery("destination:destination6,user=" + anotherUserId, change1);
assertQuery("destination:name=destination6,user=" + anotherUserId, change1);
assertQuery("destination:user=" + anotherUserId + ",destination7", change2);
assertQuery("destination:user=" + anotherUserId + ",name=destination8", change2, change1);
assertQuery("destination:destination9,user=" + anotherUserId);
assertThatQueryException("destination:destination3,user=" + anotherUserId).hasMessageThat().isEqualTo("Unknown named destination: destination3");
assertThatQueryException("destination:destination3,user=test").hasMessageThat().isEqualTo("Account 'test' not found");
requestContext.setContext(newRequestContext(anotherUserId));
// account 1000000 is not visible to 'anotheruser' as they are not an admin
assertThatQueryException("destination:destination3,user=" + userId).hasMessageThat().isEqualTo("Account '1000000' not found");
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byStatus.
@Test
public void byStatus() 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.MERGED);
Change change2 = insert(repo, ins2);
assertQuery("status:new", change1);
assertQuery("status:NEW", change1);
assertQuery("is:new", change1);
assertQuery("status:merged", change2);
assertQuery("is:merged", change2);
Exception thrown = assertThrows(BadRequestException.class, () -> assertQuery("is:draft"));
assertThat(thrown).hasMessageThat().isEqualTo("Unrecognized value: draft");
thrown = assertThrows(BadRequestException.class, () -> assertQuery("status:draft"));
assertThat(thrown).hasMessageThat().isEqualTo("Unrecognized value: draft");
}
Aggregations