Search in sources :

Example 1 with Truth8.assertThat

use of com.google.common.truth.Truth8.assertThat in project gerrit by GerritCodeReview.

the class ChangeIT method implicitlyAddReviewerOnVotingReview.

@Test
public void implicitlyAddReviewerOnVotingReview() throws Exception {
    PushOneCommit.Result r = createChange();
    setApiUser(user);
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.recommend().message("LGTM"));
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.reviewers.get(REVIEWER).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id.get());
    // Further test: remove the vote, then comment again. The user should be
    // implicitly re-added to the ReviewerSet, as a CC if we're using NoteDb.
    setApiUser(admin);
    gApi.changes().id(r.getChangeId()).reviewer(user.getId().toString()).remove();
    c = gApi.changes().id(r.getChangeId()).get();
    assertThat(c.reviewers.values()).isEmpty();
    setApiUser(user);
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(new ReviewInput().message("hi"));
    c = gApi.changes().id(r.getChangeId()).get();
    ReviewerState state = notesMigration.readChanges() ? CC : REVIEWER;
    assertThat(c.reviewers.get(state).stream().map(ai -> ai._accountId).collect(toList())).containsExactly(user.id.get());
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) CHANGE_OWNER(com.google.gerrit.server.group.SystemGroupBackend.CHANGE_OWNER) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) RefNames.changeMetaRef(com.google.gerrit.reviewdb.client.RefNames.changeMetaRef) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) DeleteVoteInput(com.google.gerrit.extensions.api.changes.DeleteVoteInput) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) MergePatchSetInput(com.google.gerrit.extensions.common.MergePatchSetInput) NoHttpd(com.google.gerrit.acceptance.NoHttpd) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) RefNames(com.google.gerrit.reviewdb.client.RefNames) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) LabelId(com.google.gerrit.reviewdb.client.LabelId) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) MergeInput(com.google.gerrit.extensions.common.MergeInput) TestTimeUtil(com.google.gerrit.testutil.TestTimeUtil) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GitUtil(com.google.gerrit.acceptance.GitUtil) Before(org.junit.Before) Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) TimeUtil(com.google.gerrit.common.TimeUtil) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) FooterConstants(com.google.gerrit.common.FooterConstants) GitUtil.assertPushOk(com.google.gerrit.acceptance.GitUtil.assertPushOk) Repository(org.eclipse.jgit.lib.Repository) ChangeControl(com.google.gerrit.server.project.ChangeControl) AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) Inject(com.google.inject.Inject) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) After(org.junit.After) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Util.blockLabel(com.google.gerrit.server.project.Util.blockLabel) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) Permission(com.google.gerrit.common.data.Permission) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) LabelType(com.google.gerrit.common.data.LabelType) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Optional(java.util.Optional) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) GitPerson(com.google.gerrit.extensions.common.GitPerson) Branch(com.google.gerrit.reviewdb.client.Branch) CC(com.google.gerrit.extensions.client.ReviewerState.CC) Message(com.google.gerrit.testutil.FakeEmailSender.Message) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Util.category(com.google.gerrit.server.project.Util.category) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) Range(com.google.gerrit.extensions.client.Comment.Range) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeContext(com.google.gerrit.server.update.ChangeContext) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) Iterator(java.util.Iterator) Sandboxed(com.google.gerrit.acceptance.Sandboxed) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) Util(com.google.gerrit.server.project.Util) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Util.value(com.google.gerrit.server.project.Util.value) Collectors.toList(java.util.stream.Collectors.toList) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with Truth8.assertThat

use of com.google.common.truth.Truth8.assertThat in project gerrit by GerritCodeReview.

the class ChangeIT method getReviewerState.

private Optional<ReviewerState> getReviewerState(String changeId, Account.Id accountId) throws Exception {
    ChangeInfo c = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.DETAILED_LABELS));
    Set<ReviewerState> states = c.reviewers.entrySet().stream().filter(e -> e.getValue().stream().anyMatch(a -> a._accountId == accountId.get())).map(e -> e.getKey()).collect(toSet());
    assertThat(states.size()).named(states.toString()).isAtMost(1);
    return states.stream().findFirst();
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) CHANGE_OWNER(com.google.gerrit.server.group.SystemGroupBackend.CHANGE_OWNER) TestAccount(com.google.gerrit.acceptance.TestAccount) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) RefNames.changeMetaRef(com.google.gerrit.reviewdb.client.RefNames.changeMetaRef) RevWalk(org.eclipse.jgit.revwalk.RevWalk) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) GerritConfig(com.google.gerrit.acceptance.GerritConfig) Map(java.util.Map) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) DeleteVoteInput(com.google.gerrit.extensions.api.changes.DeleteVoteInput) Set(java.util.Set) Constants(org.eclipse.jgit.lib.Constants) MergePatchSetInput(com.google.gerrit.extensions.common.MergePatchSetInput) NoHttpd(com.google.gerrit.acceptance.NoHttpd) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) DeleteReviewerInput(com.google.gerrit.extensions.api.changes.DeleteReviewerInput) RefNames(com.google.gerrit.reviewdb.client.RefNames) PushResult(org.eclipse.jgit.transport.PushResult) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) LabelId(com.google.gerrit.reviewdb.client.LabelId) ChangeMessagesUtil(com.google.gerrit.server.ChangeMessagesUtil) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) MergeInput(com.google.gerrit.extensions.common.MergeInput) TestTimeUtil(com.google.gerrit.testutil.TestTimeUtil) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ChangeMessageModifier(com.google.gerrit.server.git.ChangeMessageModifier) RestApiException(com.google.gerrit.extensions.restapi.RestApiException) GitUtil(com.google.gerrit.acceptance.GitUtil) Before(org.junit.Before) Project(com.google.gerrit.reviewdb.client.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) TimeUtil(com.google.gerrit.common.TimeUtil) Test(org.junit.Test) ANONYMOUS_USERS(com.google.gerrit.server.group.SystemGroupBackend.ANONYMOUS_USERS) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) ChangeKind(com.google.gerrit.extensions.client.ChangeKind) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) FooterConstants(com.google.gerrit.common.FooterConstants) GitUtil.assertPushOk(com.google.gerrit.acceptance.GitUtil.assertPushOk) Repository(org.eclipse.jgit.lib.Repository) ChangeControl(com.google.gerrit.server.project.ChangeControl) AddReviewerResult(com.google.gerrit.extensions.api.changes.AddReviewerResult) Inject(com.google.inject.Inject) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) PrimaryStorage(com.google.gerrit.server.notedb.NoteDbChangeState.PrimaryStorage) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) After(org.junit.After) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) Util.blockLabel(com.google.gerrit.server.project.Util.blockLabel) Collectors.toSet(java.util.stream.Collectors.toSet) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) Permission(com.google.gerrit.common.data.Permission) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) LabelType(com.google.gerrit.common.data.LabelType) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) AccountGroup(com.google.gerrit.reviewdb.client.AccountGroup) List(java.util.List) RebaseInput(com.google.gerrit.extensions.api.changes.RebaseInput) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Optional(java.util.Optional) RegistrationHandle(com.google.gerrit.extensions.registration.RegistrationHandle) BatchUpdateOp(com.google.gerrit.server.update.BatchUpdateOp) GitPerson(com.google.gerrit.extensions.common.GitPerson) Branch(com.google.gerrit.reviewdb.client.Branch) CC(com.google.gerrit.extensions.client.ReviewerState.CC) Message(com.google.gerrit.testutil.FakeEmailSender.Message) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) ReviewerState(com.google.gerrit.extensions.client.ReviewerState) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Util.category(com.google.gerrit.server.project.Util.category) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) Range(com.google.gerrit.extensions.client.Comment.Range) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeContext(com.google.gerrit.server.update.ChangeContext) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) TruthJUnit.assume(com.google.common.truth.TruthJUnit.assume) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) Iterator(java.util.Iterator) Sandboxed(com.google.gerrit.acceptance.Sandboxed) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Truth.assertThat(com.google.common.truth.Truth.assertThat) Util(com.google.gerrit.server.project.Util) AnonymousCowardNameProvider(com.google.gerrit.server.config.AnonymousCowardNameProvider) Util.value(com.google.gerrit.server.project.Util.value) Collectors.toList(java.util.stream.Collectors.toList) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewerState(com.google.gerrit.extensions.client.ReviewerState)

Example 3 with Truth8.assertThat

use of com.google.common.truth.Truth8.assertThat in project gerrit by GerritCodeReview.

the class RevisionIT method postSubmitApprovalAfterVoteRemoved.

@Test
public void postSubmitApprovalAfterVoteRemoved() throws Exception {
    PushOneCommit.Result r = createChange();
    String changeId = project.get() + "~master~" + r.getChangeId();
    setApiUser(admin);
    revision(r).review(ReviewInput.approve());
    setApiUser(user);
    revision(r).review(ReviewInput.recommend());
    setApiUser(admin);
    gApi.changes().id(changeId).reviewer(user.username).deleteVote("Code-Review");
    Optional<ApprovalInfo> crUser = get(changeId, DETAILED_LABELS).labels.get("Code-Review").all.stream().filter(a -> a._accountId == user.id.get()).findFirst();
    assertThat(crUser).isPresent();
    assertThat(crUser.get().value).isEqualTo(0);
    revision(r).submit();
    setApiUser(user);
    ReviewInput in = new ReviewInput();
    in.label("Code-Review", 1);
    in.message = "Still LGTM";
    revision(r).review(in);
    ApprovalInfo cr = gApi.changes().id(changeId).get(EnumSet.of(ListChangesOption.DETAILED_LABELS)).labels.get("Code-Review").all.stream().filter(a -> a._accountId == user.getId().get()).findFirst().get();
    assertThat(cr.postSubmit).isTrue();
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) NotifyInfo(com.google.gerrit.extensions.api.changes.NotifyInfo) LabelInfo(com.google.gerrit.extensions.common.LabelInfo) PATCH_FILE_ONLY(com.google.gerrit.acceptance.PushOneCommit.PATCH_FILE_ONLY) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) TestAccount(com.google.gerrit.acceptance.TestAccount) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) REVIEWER(com.google.gerrit.extensions.client.ReviewerState.REVIEWER) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) RevisionInfo(com.google.gerrit.extensions.common.RevisionInfo) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) FILE_CONTENT(com.google.gerrit.acceptance.PushOneCommit.FILE_CONTENT) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) PATCH(com.google.gerrit.acceptance.PushOneCommit.PATCH) DraftApi(com.google.gerrit.extensions.api.changes.DraftApi) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) Locale(java.util.Locale) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) Assert.fail(org.junit.Assert.fail) DateFormat(java.text.DateFormat) EnumSet(java.util.EnumSet) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) ImmutableSet(com.google.common.collect.ImmutableSet) PatchSetWebLink(com.google.gerrit.extensions.webui.PatchSetWebLink) ImmutableMap(com.google.common.collect.ImmutableMap) RefSpec(org.eclipse.jgit.transport.RefSpec) SubmitType(com.google.gerrit.extensions.client.SubmitType) Timestamp(java.sql.Timestamp) Collection(java.util.Collection) RevisionApi(com.google.gerrit.extensions.api.changes.RevisionApi) DETAILED_LABELS(com.google.gerrit.extensions.client.ListChangesOption.DETAILED_LABELS) HEAD(org.eclipse.jgit.lib.Constants.HEAD) Permission(com.google.gerrit.common.data.Permission) RefUpdate(org.eclipse.jgit.lib.RefUpdate) CommitInfo(com.google.gerrit.extensions.common.CommitInfo) MethodNotAllowedException(com.google.gerrit.extensions.restapi.MethodNotAllowedException) NotifyHandling(com.google.gerrit.extensions.api.changes.NotifyHandling) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ChangeData(com.google.gerrit.server.query.change.ChangeData) List(java.util.List) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GitPerson(com.google.gerrit.extensions.common.GitPerson) Joiner(com.google.common.base.Joiner) Branch(com.google.gerrit.reviewdb.client.Branch) MergeableInfo(com.google.gerrit.extensions.common.MergeableInfo) Iterables(com.google.common.collect.Iterables) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) DiffInfo(com.google.gerrit.extensions.common.DiffInfo) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Change(com.google.gerrit.reviewdb.client.Change) COMMIT_MSG(com.google.gerrit.reviewdb.client.Patch.COMMIT_MSG) SimpleDateFormat(java.text.SimpleDateFormat) HashMap(java.util.HashMap) TestProjectInput(com.google.gerrit.acceptance.TestProjectInput) Iterators(com.google.common.collect.Iterators) ArrayList(java.util.ArrayList) MERGE_LIST(com.google.gerrit.reviewdb.client.Patch.MERGE_LIST) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) ImmutableList(com.google.common.collect.ImmutableList) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) Account(com.google.gerrit.reviewdb.client.Account) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) FileInfo(com.google.gerrit.extensions.common.FileInfo) GetRevisionActions(com.google.gerrit.server.change.GetRevisionActions) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ChangeApi(com.google.gerrit.extensions.api.changes.ChangeApi) ListChangesOption(com.google.gerrit.extensions.client.ListChangesOption) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) ETagView(com.google.gerrit.extensions.restapi.ETagView) WebLinkInfo(com.google.gerrit.extensions.common.WebLinkInfo) RecipientType(com.google.gerrit.extensions.api.changes.RecipientType) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) DynamicSet(com.google.gerrit.extensions.registration.DynamicSet) CherryPickInput(com.google.gerrit.extensions.api.changes.CherryPickInput) Collections(java.util.Collections) ChangeStatus(com.google.gerrit.extensions.client.ChangeStatus) NameKey(com.google.gerrit.reviewdb.client.Branch.NameKey) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with Truth8.assertThat

use of com.google.common.truth.Truth8.assertThat in project gerrit by GerritCodeReview.

the class KillTaskIT method killTask.

private void killTask() throws Exception {
    RestResponse r = adminRestSession.get("/config/server/tasks/");
    List<TaskInfo> result = newGson().fromJson(r.getReader(), new TypeToken<List<TaskInfo>>() {
    }.getType());
    r.consume();
    Optional<String> id = result.stream().filter(t -> "Log File Compressor".equals(t.command)).map(t -> t.id).findFirst();
    assertThat(id).isPresent();
    r = adminRestSession.delete("/config/server/tasks/" + id.get());
    r.assertNoContent();
    r.consume();
    r = adminRestSession.get("/config/server/tasks/");
    result = newGson().fromJson(r.getReader(), new TypeToken<List<TaskInfo>>() {
    }.getType());
    r.consume();
    Set<String> ids = result.stream().map(t -> t.id).collect(toSet());
    assertThat(ids).doesNotContain(id.get());
}
Also used : TaskInfo(com.google.gerrit.server.config.ListTasks.TaskInfo) List(java.util.List) TypeToken(com.google.gson.reflect.TypeToken) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) RestResponse(com.google.gerrit.acceptance.RestResponse) Optional(java.util.Optional) Set(java.util.Set) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) TaskInfo(com.google.gerrit.server.config.ListTasks.TaskInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Collectors.toSet(java.util.stream.Collectors.toSet) RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) List(java.util.List)

Example 5 with Truth8.assertThat

use of com.google.common.truth.Truth8.assertThat in project gerrit by GerritCodeReview.

the class CommentsIT method deleteOneCommentMultipleTimes.

@Test
public void deleteOneCommentMultipleTimes() throws Exception {
    PushOneCommit.Result result = createChange();
    Change.Id id = result.getChange().getId();
    String changeId = result.getChangeId();
    String ps1 = result.getCommit().name();
    CommentInput c1 = newComment(FILE_NAME, "comment 1");
    CommentInput c2 = newComment(FILE_NAME, "comment 2");
    CommentInput c3 = newComment(FILE_NAME, "comment 3");
    addComments(changeId, ps1, c1);
    addComments(changeId, ps1, c2);
    addComments(changeId, ps1, c3);
    List<CommentInfo> commentsBeforeDelete = getChangeSortedComments(changeId);
    assertThat(commentsBeforeDelete).hasSize(3);
    Optional<CommentInfo> targetComment = commentsBeforeDelete.stream().filter(c -> c.message.equals("comment 2")).findFirst();
    assertThat(targetComment).isPresent();
    String uuid = targetComment.get().id;
    CommentInfo oldComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    List<RevCommit> commitsBeforeDelete = new ArrayList<>();
    if (notesMigration.commitChangeWrites()) {
        commitsBeforeDelete = getCommits(id);
    }
    setApiUser(admin);
    for (int i = 0; i < 3; i++) {
        DeleteCommentInput input = new DeleteCommentInput("delete comment 2, iteration: " + i);
        gApi.changes().id(changeId).revision(ps1).comment(uuid).delete(input);
    }
    CommentInfo updatedComment = gApi.changes().id(changeId).revision(ps1).comment(uuid).get();
    String expectedMsg = String.format("Comment removed by: %s; Reason: %s", admin.fullName, "delete comment 2, iteration: 2");
    assertThat(updatedComment.message).isEqualTo(expectedMsg);
    oldComment.message = expectedMsg;
    assertThat(updatedComment).isEqualTo(oldComment);
    if (notesMigration.commitChangeWrites()) {
        assertMetaBranchCommitsAfterRewriting(commitsBeforeDelete, id, uuid, expectedMsg);
    }
    assertThat(getChangeSortedComments(changeId)).hasSize(3);
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Arrays(java.util.Arrays) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Matcher(java.util.regex.Matcher) Map(java.util.Map) AuthException(com.google.gerrit.extensions.restapi.AuthException) DraftHandling(com.google.gerrit.extensions.api.changes.ReviewInput.DraftHandling) Side(com.google.gerrit.extensions.client.Side) NoteMap(org.eclipse.jgit.notes.NoteMap) FILE_NAME(com.google.gerrit.acceptance.PushOneCommit.FILE_NAME) Function(com.google.common.base.Function) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) ImmutableMap(com.google.common.collect.ImmutableMap) Timestamp(java.sql.Timestamp) ChangeNoteUtil(com.google.gerrit.server.notedb.ChangeNoteUtil) AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) PostReview(com.google.gerrit.server.change.PostReview) Collectors(java.util.stream.Collectors) TopLevelResource(com.google.gerrit.extensions.restapi.TopLevelResource) NoHttpd(com.google.gerrit.acceptance.NoHttpd) List(java.util.List) RefNames(com.google.gerrit.reviewdb.client.RefNames) Ref(org.eclipse.jgit.lib.Ref) Entry(java.util.Map.Entry) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) Iterables(com.google.common.collect.Iterables) DraftInput(com.google.gerrit.extensions.api.changes.DraftInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) ChangesCollection(com.google.gerrit.server.change.ChangesCollection) Message(com.google.gerrit.testutil.FakeEmailSender.Message) IdString(com.google.gerrit.extensions.restapi.IdString) Patch(com.google.gerrit.reviewdb.client.Patch) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) Comment(com.google.gerrit.extensions.client.Comment) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ChangeResource(com.google.gerrit.server.change.ChangeResource) SUBJECT(com.google.gerrit.acceptance.PushOneCommit.SUBJECT) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Before(org.junit.Before) IOException(java.io.IOException) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) DeleteCommentRewriter(com.google.gerrit.server.notedb.DeleteCommentRewriter) Provider(com.google.inject.Provider) RevisionResource(com.google.gerrit.server.change.RevisionResource) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) Comparator(java.util.Comparator) ObjectReader(org.eclipse.jgit.lib.ObjectReader) Repository(org.eclipse.jgit.lib.Repository) ArrayList(java.util.ArrayList) Change(com.google.gerrit.reviewdb.client.Change) IdString(com.google.gerrit.extensions.restapi.IdString) CommentInfo(com.google.gerrit.extensions.common.CommentInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) CommentInput(com.google.gerrit.extensions.api.changes.ReviewInput.CommentInput) DeleteCommentInput(com.google.gerrit.extensions.api.changes.DeleteCommentInput) RevCommit(org.eclipse.jgit.revwalk.RevCommit) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Truth.assertThat (com.google.common.truth.Truth.assertThat)5 Truth8.assertThat (com.google.common.truth.Truth8.assertThat)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 Iterables (com.google.common.collect.Iterables)4 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)4 FILE_NAME (com.google.gerrit.acceptance.PushOneCommit.FILE_NAME)4 SUBJECT (com.google.gerrit.acceptance.PushOneCommit.SUBJECT)4 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)4 List (java.util.List)4 Optional (java.util.Optional)4 Test (org.junit.Test)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 Lists (com.google.common.collect.Lists)3 AcceptanceTestRequestScope (com.google.gerrit.acceptance.AcceptanceTestRequestScope)3 NoHttpd (com.google.gerrit.acceptance.NoHttpd)3 TestAccount (com.google.gerrit.acceptance.TestAccount)3 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)3 Permission (com.google.gerrit.common.data.Permission)3