Search in sources :

Example 26 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byParentRepo.

@Test
public void byParentRepo() throws Exception {
    TestRepository<Repo> repo1 = createProject("repo1");
    TestRepository<Repo> repo2 = createProject("repo2", "repo1");
    Change change1 = insert(repo1, newChange(repo1));
    Change change2 = insert(repo2, newChange(repo2));
    assertQuery("parentrepo:repo1", change2, change1);
    assertQuery("parentrepo:repo2", change2);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 27 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byBranchAndRef.

@Test
public void byBranchAndRef() throws Exception {
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChangeForBranch(repo, "master"));
    Change change2 = insert(repo, newChangeForBranch(repo, "branch"));
    assertQuery("branch:foo");
    assertQuery("branch:master", change1);
    assertQuery("branch:refs/heads/master", change1);
    assertQuery("ref:master");
    assertQuery("ref:refs/heads/master", change1);
    assertQuery("branch:refs/heads/master", change1);
    assertQuery("branch:branch", change2);
    assertQuery("branch:refs/heads/branch", change2);
    assertQuery("ref:branch");
    assertQuery("ref:refs/heads/branch", change2);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 28 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byUploader.

@Test
public void byUploader() throws Exception {
    assume().that(getSchema().hasField(ChangeField.UPLOADER)).isTrue();
    Account.Id user2 = accountManager.authenticate(authRequestFactory.createForUser("anotheruser")).getAccountId();
    CurrentUser user2CurrentUser = userFactory.create(user2);
    TestRepository<Repo> repo = createProject("repo");
    Change change1 = insert(repo, newChange(repo), userId);
    assertQuery("is:uploader", change1);
    assertQuery("uploader:" + userId.get(), change1);
    change1 = newPatchSet(repo, change1, user2CurrentUser);
    // Uploader has changed
    assertQuery("uploader:" + userId.get());
    assertQuery("uploader:" + user2.get(), change1);
    requestContext.setContext(newRequestContext(user2));
    // self (user2)
    assertQuery("is:uploader", change1);
    String nameEmail = user2CurrentUser.asIdentifiedUser().getNameEmail();
    assertQuery("uploader: \"" + nameEmail + "\"", change1);
}
Also used : Account(com.google.gerrit.entities.Account) CurrentUser(com.google.gerrit.server.CurrentUser) Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Example 29 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method byMergedBefore.

@Test
public void byMergedBefore() 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(change3);
    TestTimeUtil.setClock(new Timestamp(startMs + 2 * thirtyHoursInMs));
    submit(change2);
    TestTimeUtil.setClock(new Timestamp(startMs + 3 * thirtyHoursInMs));
    // Put another approval on the change, just to update it.
    approve(change1);
    approve(change3);
    assertThat(TimeUtil.nowMs()).isEqualTo(startMs + 3 * thirtyHoursInMs);
    assertThat(lastUpdatedMsApi(change3)).isEqualTo(startMs + 3 * thirtyHoursInMs);
    assertThat(lastUpdatedMsApi(change2)).isEqualTo(startMs + 2 * thirtyHoursInMs);
    assertThat(lastUpdatedMsApi(change1)).isEqualTo(startMs + 3 * thirtyHoursInMs);
    // Verify that:
    // 1. Change1 was not submitted and should be never returned.
    // 2. Change2 was merged on 2009-10-02 03:00:00 -0000
    // 3. Change3 was merged on 2009-10-03 09:00:00.0 -0000
    assertQuery("mergedbefore:2009-10-01");
    // Changes excluded on the date submitted.
    assertQuery("mergedbefore:2009-10-02");
    assertQuery("mergedbefore:\"2009-10-01 22:59:00 -0400\"");
    assertQuery("mergedbefore:\"2009-10-01 02:59:00\"");
    assertQuery("mergedbefore:\"2009-10-01 23:02:00 -0400\"", change3);
    assertQuery("mergedbefore:\"2009-10-02 03:02:00 -0000\"", change3);
    assertQuery("mergedbefore:\"2009-10-02 03:02:00\"", change3);
    assertQuery("mergedbefore:2009-10-03", change3);
    // Changes are sorted by lastUpdatedOn first, then by mergedOn.
    // Even though Change2 was merged after Change3, Change3 is returned first.
    assertQuery("mergedbefore:2009-10-04", change3, change2);
    // Same test as above, but using filter code path.
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:2009-10-01"));
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:2009-10-02"));
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:\"2009-10-01 22:59:00 -0400\""));
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:\"2009-10-01 02:59:00\""));
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:\"2009-10-01 23:02:00 -0400\""), change3);
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:\"2009-10-02 03:02:00 -0000\""), change3);
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:\"2009-10-02 03:02:00\""), change3);
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:2009-10-03"), change3);
    assertQuery(makeIndexedPredicateFilterQuery("mergedbefore:2009-10-04"), change3, change2);
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.entities.Change) Timestamp(java.sql.Timestamp) Test(org.junit.Test)

Example 30 with Repo

use of com.google.gerrit.testing.InMemoryRepositoryManager.Repo in project gerrit by GerritCodeReview.

the class AbstractQueryChangesTest method isPureRevert.

@Test
public void isPureRevert() throws Exception {
    assume().that(getSchema().hasField(ChangeField.IS_PURE_REVERT)).isTrue();
    TestRepository<Repo> repo = createProject("repo");
    // Create two commits and revert second commit (initial commit can't be reverted)
    Change initial = insert(repo, newChange(repo));
    gApi.changes().id(initial.getChangeId()).current().review(ReviewInput.approve());
    gApi.changes().id(initial.getChangeId()).current().submit();
    ChangeInfo changeToRevert = gApi.changes().create(new ChangeInput("repo", "master", "commit to revert")).get();
    gApi.changes().id(changeToRevert.id).current().review(ReviewInput.approve());
    gApi.changes().id(changeToRevert.id).current().submit();
    ChangeInfo changeThatReverts = gApi.changes().id(changeToRevert.id).revert().get();
    Change.Id changeThatRevertsId = Change.id(changeThatReverts._number);
    assertQueryByIds("is:pure-revert", changeThatRevertsId);
    // Update the change that reverts such that it's not a pure revert
    gApi.changes().id(changeThatReverts.id).edit().modifyFile("some-file.txt", RawInputUtil.create("newcontent".getBytes(UTF_8)));
    gApi.changes().id(changeThatReverts.id).edit().publish();
    assertQueryByIds("is:pure-revert");
}
Also used : Repo(com.google.gerrit.testing.InMemoryRepositoryManager.Repo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Change(com.google.gerrit.entities.Change) Test(org.junit.Test)

Aggregations

Repo (com.google.gerrit.testing.InMemoryRepositoryManager.Repo)126 Test (org.junit.Test)117 Change (com.google.gerrit.entities.Change)112 Account (com.google.gerrit.entities.Account)30 RevCommit (org.eclipse.jgit.revwalk.RevCommit)30 ChangeInserter (com.google.gerrit.server.change.ChangeInserter)17 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)8 Project (com.google.gerrit.entities.Project)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)6 GerritConfig (com.google.gerrit.acceptance.config.GerritConfig)5 ReviewerInput (com.google.gerrit.extensions.api.changes.ReviewerInput)5 RevWalk (org.eclipse.jgit.revwalk.RevWalk)5 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)4 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)4 AuthException (com.google.gerrit.extensions.restapi.AuthException)4 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)4 QueryParseException (com.google.gerrit.index.query.QueryParseException)4 IOException (java.io.IOException)4