use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byDirectory.
@Test
public void byDirectory() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChangeWithFiles(repo, "src/foo.h", "src/foo.cc"));
Change change2 = insert(repo, newChangeWithFiles(repo, "src/java/foo.java", "src/js/bar.js"));
Change change3 = insert(repo, newChangeWithFiles(repo, "documentation/training/slides/README.txt"));
Change change4 = insert(repo, newChangeWithFiles(repo, "a.txt"));
Change change5 = insert(repo, newChangeWithFiles(repo, "a/b/c/d/e/foo.txt"));
Change change6 = insert(repo, newChangeWithFiles(repo, "all/caps/DIRECTORY/file.txt"));
// matching by directory prefix works
assertQuery("directory:src", change2, change1);
assertQuery("directory:src/java", change2);
assertQuery("directory:src/js", change2);
assertQuery("directory:documentation/", change3);
assertQuery("directory:documentation/training", change3);
assertQuery("directory:documentation/training/slides", change3);
// 'dir' alias works
assertQuery("dir:src", change2, change1);
assertQuery("dir:src/java", change2);
// case doesn't matter
assertQuery("directory:Documentation/TrAiNiNg/SLIDES", change3);
assertQuery("directory:all/caps/directory", change6);
// leading and trailing '/' doesn't matter
assertQuery("directory:/documentation/training/slides", change3);
assertQuery("directory:documentation/training/slides/", change3);
assertQuery("directory:/documentation/training/slides/", change3);
// files do not match as directory
assertQuery("directory:src/foo.h");
assertQuery("directory:documentation/training/slides/README.txt");
// root directory matches all changes
assertQuery("directory:/", change6, change5, change4, change3, change2, change1);
assertQuery("directory:\"\"", change6, change5, change4, change3, change2, change1);
assertFailingQuery("directory:");
// matching single directory segments works
assertQuery("directory:java", change2);
assertQuery("directory:slides", change3);
// files do not match as directory segment
assertQuery("directory:foo.h");
// matching any combination of intermediate directory segments works
assertQuery("directory:training/slides", change3);
assertQuery("directory:b/c", change5);
assertQuery("directory:b/c/d", change5);
assertQuery("directory:b/c/d/e", change5);
assertQuery("directory:c/d", change5);
assertQuery("directory:c/d/e", change5);
assertQuery("directory:d/e", change5);
// files do not match as directory segments
assertQuery("directory:d/e/foo.txt");
assertQuery("directory:e/foo.txt");
// matching any combination of intermediate directory segments works with leading and trailing
// '/'
assertQuery("directory:/b/c", change5);
assertQuery("directory:/b/c/", change5);
assertQuery("directory:b/c/", change5);
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method visible.
@Test
public void visible() throws Exception {
TestRepository<Repo> repo = createProject("repo");
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChangePrivate(repo));
String q = "project:repo";
// Bad request for query with non-existent user
assertThatQueryException(q + " visibleto:notexisting");
// Current user can see all changes
assertQuery(q, change2, change1);
assertQuery(q + " visibleto:self", change2, change1);
// Second user cannot see first user's private change
Account.Id user2 = createAccount("user2");
assertQuery(q + " visibleto:" + user2.get(), change1);
assertQuery(q + " visibleto:user2", change1);
String g1 = createGroup("group1", "Administrators");
gApi.groups().id(g1).addMembers("user2");
// By default when a group is created without any permission granted,
// nothing is visible to it; having members or not has nothing to do with it
assertQuery(q + " visibleto:" + g1);
// change is visible to group ONLY when access is granted
grant(Project.nameKey("repo"), "refs/*", Permission.READ, false, AccountGroup.uuid(gApi.groups().id(g1).get().id));
assertQuery(q + " visibleto:" + g1, change1);
// Both changes are visible to InternalUser
try (ManualRequestContext ctx = oneOffRequestContext.open()) {
assertQuery(q, change2, change1);
}
requestContext.setContext(newRequestContext(user2));
assertQuery("is:visible", change1);
Account.Id user3 = createAccount("user3");
// Explicitly authenticate user2 and user3 so that display name gets set
AuthRequest authRequest = authRequestFactory.createForUser("user2");
authRequest.setDisplayName("Another User");
authRequest.setEmailAddress("user2@example.com");
accountManager.authenticate(authRequest);
authRequest = authRequestFactory.createForUser("user3");
authRequest.setDisplayName("Another User");
authRequest.setEmailAddress("user3@example.com");
accountManager.authenticate(authRequest);
// Switch to user3
requestContext.setContext(newRequestContext(user3));
Change change3 = insert(repo, newChange(repo), user3);
Change change4 = insert(repo, newChangePrivate(repo), user3);
// User3 can see both their changes and the first user's change
assertQuery(q + " visibleto:" + user3.get(), change4, change3, change1);
// User2 cannot see user3's private change
assertQuery(q + " visibleto:" + user2.get(), change3, change1);
// Query as user3 by display name matching user2 and user3; bad request
assertFailingQuery(q + " visibleto:\"Another User\"", "\"Another User\" resolves to multiple accounts");
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method mergeableFailsWhenNotIndexed.
@Test
@GerritConfig(name = "change.mergeabilityComputationBehavior", value = "NEVER")
public void mergeableFailsWhenNotIndexed() throws Exception {
TestRepository<Repo> repo = createProject("repo");
RevCommit commit1 = repo.parseBody(repo.commit().add("file1", "contents1").create());
insert(repo, newChangeForCommit(repo, commit1));
Throwable thrown = assertThrows(Throwable.class, () -> assertQuery("status:open is:mergeable"));
assertThat(thrown.getCause()).isInstanceOf(QueryParseException.class);
assertThat(thrown).hasMessageThat().contains("'is:mergeable' operator is not supported by server");
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method updatedThenMergedOrder.
@Test
public void updatedThenMergedOrder() throws Exception {
assume().that(getSchema().hasField(ChangeField.MERGED_ON)).isTrue();
long thirtyHoursInMs = MILLISECONDS.convert(30, HOURS);
// Stop the clock, will set time to specific test values.
resetTimeWithClockStep(0, MILLISECONDS);
TestRepository<Repo> repo = createProject("repo");
long startMs = TestTimeUtil.START.toEpochMilli();
TestTimeUtil.setClock(new Timestamp(startMs));
Change change1 = insert(repo, newChange(repo));
Change change2 = insert(repo, newChange(repo));
Change change3 = insert(repo, newChange(repo));
TestTimeUtil.setClock(new Timestamp(startMs + thirtyHoursInMs));
submit(change2);
submit(change3);
TestTimeUtil.setClock(new Timestamp(startMs + 2 * thirtyHoursInMs));
// Approve post submit just to update lastUpdatedOn
approve(change3);
approve(change2);
submit(change1);
// All Changes were last updated at the same time.
assertThat(lastUpdatedMsApi(change3)).isEqualTo(startMs + 2 * thirtyHoursInMs);
assertThat(lastUpdatedMsApi(change2)).isEqualTo(startMs + 2 * thirtyHoursInMs);
assertThat(lastUpdatedMsApi(change1)).isEqualTo(startMs + 2 * thirtyHoursInMs);
// Changes are sorted by lastUpdatedOn first, then by mergedOn, then by Id in reverse order.
// 1. Change3 and Change2 were merged at the same time, but Change3 ID > Change2 ID.
// 2. Change1 ID < Change3 ID & Change2 ID but it was merged last.
assertQuery("mergedbefore:2009-10-06", change1, change3, change2);
assertQuery("mergedafter:2009-09-30", change1, change3, change2);
assertQuery("status:merged", change1, change3, change2);
}
use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.
the class AbstractQueryChangesTest method byParentOf.
@Test
public void byParentOf() throws Exception {
TestRepository<Repo> repo1 = createProject("repo1");
RevCommit commit1 = repo1.parseBody(repo1.commit().message("message").create());
Change change1 = insert(repo1, newChangeForCommit(repo1, commit1));
RevCommit commit2 = repo1.parseBody(repo1.commit(commit1));
Change change2 = insert(repo1, newChangeForCommit(repo1, commit2));
RevCommit commit3 = repo1.parseBody(repo1.commit(commit1, commit2));
Change change3 = insert(repo1, newChangeForCommit(repo1, commit3));
assertQuery("parentof:" + change1.getId().get());
assertQuery("parentof:" + change1.getKey().get());
assertQuery("parentof:" + change2.getId().get(), change1);
assertQuery("parentof:" + change2.getKey().get(), change1);
assertQuery("parentof:" + change3.getId().get(), change2, change1);
assertQuery("parentof:" + change3.getKey().get(), change2, change1);
}
Aggregations