Search in sources :

Example 16 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class CommentsIT method listChangeWithDrafts.

@Test
public void listChangeWithDrafts() throws Exception {
    for (Integer line : lines) {
        PushOneCommit.Result r = createChange();
        String changeId = r.getChangeId();
        String revId = r.getCommit().getName();
        DraftInput comment = newDraft("file1", Side.REVISION, line, "comment 1");
        addDraft(changeId, revId, comment);
        assertThat(gApi.changes().query("change:" + changeId + " has:draft").get()).hasSize(1);
    }
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) IdString(com.google.gerrit.extensions.restapi.IdString) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 17 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class ChangeRebuilderIT method putDraft.

private void putDraft(TestAccount account, Change.Id id, int line, String msg, Boolean unresolved) throws Exception {
    DraftInput in = new DraftInput();
    in.line = line;
    in.message = msg;
    in.path = PushOneCommit.FILE_NAME;
    in.unresolved = unresolved;
    AcceptanceTestRequestScope.Context old = setApiUser(account);
    try {
        gApi.changes().id(id.get()).current().createDraft(in);
    } finally {
        atrScope.set(old);
    }
}
Also used : AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput)

Example 18 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method deleteDraftComment.

@Test
public void deleteDraftComment() throws Exception {
    PushOneCommit.Result r = createChange();
    Change.Id id = r.getChange().getId();
    setNoteDbPrimary(id);
    DraftInput din = new DraftInput();
    din.path = PushOneCommit.FILE_NAME;
    din.line = 1;
    din.message = "A comment";
    gApi.changes().id(id.get()).current().createDraft(din);
    CommentInfo di = Iterables.getOnlyElement(gApi.changes().id(id.get()).current().drafts().get(PushOneCommit.FILE_NAME));
    assertThat(di.message).isEqualTo(din.message);
    assertThat(db.patchComments().draftByChangeFileAuthor(id, din.path, admin.id)).isEmpty();
    gApi.changes().id(id.get()).current().draft(di.id).delete();
    assertThat(gApi.changes().id(id.get()).current().drafts()).isEmpty();
}
Also used : DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 19 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput in project gerrit by GerritCodeReview.

the class NoteDbPrimaryIT method rebuildReviewDb.

@Test
public void rebuildReviewDb() throws Exception {
    Change c = createChange().getChange().change();
    Change.Id id = c.getId();
    CommentInput cin = new CommentInput();
    cin.line = 1;
    cin.message = "Published comment";
    ReviewInput rin = ReviewInput.approve();
    rin.comments = ImmutableMap.of(PushOneCommit.FILE_NAME, ImmutableList.of(cin));
    gApi.changes().id(id.get()).current().review(ReviewInput.approve());
    DraftInput din = new DraftInput();
    din.path = PushOneCommit.FILE_NAME;
    din.line = 1;
    din.message = "Draft comment";
    gApi.changes().id(id.get()).current().createDraft(din);
    gApi.changes().id(id.get()).current().review(ReviewInput.approve());
    gApi.changes().id(id.get()).current().createDraft(din);
    assertThat(db.changeMessages().byChange(id)).isNotEmpty();
    assertThat(db.patchSets().byChange(id)).isNotEmpty();
    assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
    assertThat(db.patchComments().byChange(id)).isNotEmpty();
    ChangeBundle noteDbBundle = ChangeBundle.fromNotes(commentsUtil, notesFactory.create(db, project, id));
    setNoteDbPrimary(id);
    db.changeMessages().delete(db.changeMessages().byChange(id));
    db.patchSets().delete(db.patchSets().byChange(id));
    db.patchSetApprovals().delete(db.patchSetApprovals().byChange(id));
    db.patchComments().delete(db.patchComments().byChange(id));
    ChangeMessage bogusMessage = ChangeMessagesUtil.newMessage(c.currentPatchSetId(), identifiedUserFactory.create(admin.getId()), TimeUtil.nowTs(), "some message", null);
    db.changeMessages().insert(Collections.singleton(bogusMessage));
    rebuilderWrapper.rebuildReviewDb(db, project, id);
    assertThat(db.changeMessages().byChange(id)).isNotEmpty();
    assertThat(db.patchSets().byChange(id)).isNotEmpty();
    assertThat(db.patchSetApprovals().byChange(id)).isNotEmpty();
    assertThat(db.patchComments().byChange(id)).isNotEmpty();
    ChangeBundle reviewDbBundle = bundleReader.fromReviewDb(ReviewDbUtil.unwrapDb(db), id);
    assertThat(reviewDbBundle.differencesFrom(noteDbBundle)).isEmpty();
}
Also used : CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeBundle(com.google.gerrit.server.notedb.ChangeBundle) ChangeMessage(com.google.gerrit.reviewdb.client.ChangeMessage) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) Change(com.google.gerrit.reviewdb.client.Change) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 20 with DraftInput

use of com.google.gerrit.extensions.api.changes.DraftInput 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)

Aggregations

DraftInput (com.google.gerrit.extensions.api.changes.DraftInput)20 Test (org.junit.Test)18 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)13 CommentInfo (com.google.gerrit.extensions.common.CommentInfo)9 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)7 IdString (com.google.gerrit.extensions.restapi.IdString)7 Change (com.google.gerrit.reviewdb.client.Change)7 ImmutableList (com.google.common.collect.ImmutableList)6 ArrayList (java.util.ArrayList)6 List (java.util.List)6 CommentInput (com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput)3 Timestamp (java.sql.Timestamp)3 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)2 Repo (com.google.gerrit.testutil.InMemoryRepositoryManager.Repo)2 MoreObjects (com.google.common.base.MoreObjects)1 FluentIterable (com.google.common.collect.FluentIterable)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Iterables (com.google.common.collect.Iterables)1