Search in sources :

Example 6 with Repo

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);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 7 with Repo

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);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 8 with Repo

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);
}
Also used : AllUsersName(com.google.gerrit.server.config.AllUsersName) Arrays(java.util.Arrays) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) ProjectCache(com.google.gerrit.server.project.ProjectCache) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) HashtagsInput(com.google.gerrit.extensions.api.changes.HashtagsInput) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Config(org.eclipse.jgit.lib.Config) ChangeTriplet(com.google.gerrit.server.change.ChangeTriplet) FluentIterable(com.google.common.collect.FluentIterable) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) ThrowableSubject(com.google.common.truth.ThrowableSubject) Schema(com.google.gerrit.server.index.Schema) ThreadLocalRequestContext(com.google.gerrit.server.util.ThreadLocalRequestContext) RefUpdate(org.eclipse.jgit.lib.RefUpdate) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RefNames(com.google.gerrit.reviewdb.client.RefNames) QueryOptions(com.google.gerrit.server.index.QueryOptions) AuthRequest(com.google.gerrit.server.account.AuthRequest) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) ExternalIdsUpdate(com.google.gerrit.server.account.externalids.ExternalIdsUpdate) GroupInput(com.google.gerrit.extensions.api.groups.GroupInput) AccountCache(com.google.gerrit.server.account.AccountCache) Iterables(com.google.common.collect.Iterables) ReviewDb(com.google.gerrit.reviewdb.server.ReviewDb) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Sequences(com.google.gerrit.server.Sequences) TestTimeUtil(com.google.gerrit.testutil.TestTimeUtil) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Lists(com.google.common.collect.Lists) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) Before(org.junit.Before) QueryRequest(com.google.gerrit.extensions.api.changes.Changes.QueryRequest) Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) RequestContext(com.google.gerrit.server.util.RequestContext) TimeUtil(com.google.gerrit.common.TimeUtil) MoreObjects(com.google.common.base.MoreObjects) ReviewDbUtil(com.google.gerrit.reviewdb.server.ReviewDbUtil) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) ManualRequestContext(com.google.gerrit.server.util.ManualRequestContext) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) SystemReader(org.eclipse.jgit.util.SystemReader) LifecycleManager(com.google.gerrit.lifecycle.LifecycleManager) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) HOURS(java.util.concurrent.TimeUnit.HOURS) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) FieldDef(com.google.gerrit.server.index.FieldDef) ChangeIndexCollection(com.google.gerrit.server.index.change.ChangeIndexCollection) ObjectReader(org.eclipse.jgit.lib.ObjectReader) AccountManager(com.google.gerrit.server.account.AccountManager) ChangeControl(com.google.gerrit.server.project.ChangeControl) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) Inject(com.google.inject.Inject) PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) ChangeIndexer(com.google.gerrit.server.index.change.ChangeIndexer) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) After(org.junit.After) REVIEWED(com.google.gerrit.extensions.client.ListChangesOption.REVIEWED) Assert.fail(org.junit.Assert.fail) OneOffRequestContext(com.google.gerrit.server.util.OneOffRequestContext) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) InMemoryRepositoryManager(com.google.gerrit.testutil.InMemoryRepositoryManager) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Ref(org.eclipse.jgit.lib.Ref) ConfigSuite(com.google.gerrit.testutil.ConfigSuite) Optional(java.util.Optional) Providers(com.google.inject.util.Providers) Branch(com.google.gerrit.reviewdb.client.Branch) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) InMemoryDatabase(com.google.gerrit.testutil.InMemoryDatabase) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) Patch(com.google.gerrit.reviewdb.client.Patch) SchemaCreator(com.google.gerrit.server.schema.SchemaCreator) HashSet(java.util.HashSet) IndexConfig(com.google.gerrit.server.index.IndexConfig) ImmutableList(com.google.common.collect.ImmutableList) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInserter(com.google.gerrit.server.change.ChangeInserter) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) GerritServerTests(com.google.gerrit.testutil.GerritServerTests) CurrentUser(com.google.gerrit.server.CurrentUser) Iterator(java.util.Iterator) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) IndexedChangeQuery(com.google.gerrit.server.index.change.IndexedChangeQuery) Truth.assertThat(com.google.common.truth.Truth.assertThat) SchemaFactory(com.google.gwtorm.server.SchemaFactory) StalenessChecker(com.google.gerrit.server.index.change.StalenessChecker) NoteDbChangeState(com.google.gerrit.server.notedb.NoteDbChangeState) ObjectId(org.eclipse.jgit.lib.ObjectId) ChangeField(com.google.gerrit.server.index.change.ChangeField) Injector(com.google.inject.Injector) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) PatchSetInserter(com.google.gerrit.server.change.PatchSetInserter) Provider(com.google.inject.Provider) Ignore(org.junit.Ignore) StarsInput(com.google.gerrit.extensions.api.changes.StarsInput) GerritApi(com.google.gerrit.extensions.api.GerritApi) PatchSetUtil(com.google.gerrit.server.PatchSetUtil) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) StarredChangesUtil(com.google.gerrit.server.StarredChangesUtil) Account(com.google.gerrit.reviewdb.client.Account) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) QueryOptions(com.google.gerrit.server.index.QueryOptions) Project(com.google.gerrit.reviewdb.client.Project) Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) RobotCommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.RobotCommentInput) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 9 with Repo

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);
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) Test(org.junit.Test)

Example 10 with Repo

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();
}
Also used : Repo(com.google.gerrit.testutil.InMemoryRepositoryManager.Repo) Change(com.google.gerrit.reviewdb.client.Change) DisabledReviewDb(com.google.gerrit.testutil.DisabledReviewDb) Test(org.junit.Test)

Aggregations

Change (com.google.gerrit.reviewdb.client.Change)11 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)11 Test (org.junit.Test)11 DisabledReviewDb (com.google.gerrit.testutil.DisabledReviewDb)4 DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)3 Timestamp (java.sql.Timestamp)3 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)2 Account (com.google.gerrit.reviewdb.client.Account)2 MoreObjects (com.google.common.base.MoreObjects)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1 Lists (com.google.common.collect.Lists)1 ThrowableSubject (com.google.common.truth.ThrowableSubject)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 TruthJUnit.assume (com.google.common.truth.TruthJUnit.assume)1 Nullable (com.google.gerrit.common.Nullable)1 TimeUtil (com.google.gerrit.common.TimeUtil)1