Search in sources :

Example 91 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class ChangeNotesTest method approvalUUID_samePatchSet_differentUsers.

@Test
public void approvalUUID_samePatchSet_differentUsers() throws Exception {
    Change c = newChange();
    ChangeUpdate update = newUpdate(c, changeOwner);
    update.putApproval(LabelId.CODE_REVIEW, (short) -1);
    update.putApprovalFor(otherUserId, LabelId.CODE_REVIEW, (short) -1);
    update.commit();
    ChangeNotes notes = newNotes(c);
    assertThat(notes.getApprovals().keySet()).containsExactly(c.currentPatchSetId());
    List<PatchSetApproval> patchSetApprovals = notes.getApprovals().get(c.currentPatchSetId());
    assertThat(patchSetApprovals).hasSize(2);
    assertThat(patchSetApprovals.stream().filter(psa -> psa.value() == (short) -1 && psa.label().equals(LabelId.CODE_REVIEW)).count()).isEqualTo(2);
    // Count UUIDs to make sure they are unique
    assertThat(patchSetApprovals.stream().map(psa -> psa.uuid().get()).distinct().count()).isEqualTo(2);
    assertThat(patchSetApprovals.stream().map(psa -> psa.accountId()).collect(toImmutableSet())).containsExactly(changeOwner.getAccountId(), otherUserId);
}
Also used : TestChanges(com.google.gerrit.testing.TestChanges) RefNames.changeMetaRef(com.google.gerrit.entities.RefNames.changeMetaRef) OBJ_BLOB(org.eclipse.jgit.lib.Constants.OBJ_BLOB) ListMultimap(com.google.common.collect.ListMultimap) Inject(com.google.inject.Inject) HumanComment(com.google.gerrit.entities.HumanComment) SubmissionId(com.google.gerrit.entities.SubmissionId) ReviewerSet(com.google.gerrit.server.ReviewerSet) RevWalk(org.eclipse.jgit.revwalk.RevWalk) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) AttentionSetUpdate(com.google.gerrit.entities.AttentionSetUpdate) Map(java.util.Map) CommentRange(com.google.gerrit.entities.CommentRange) NoteMap(org.eclipse.jgit.notes.NoteMap) ImmutableSet(com.google.common.collect.ImmutableSet) Truth.assertWithMessage(com.google.common.truth.Truth.assertWithMessage) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Account(com.google.gerrit.entities.Account) ChangeNotesRevWalk(com.google.gerrit.server.notedb.ChangeNotesCommit.ChangeNotesRevWalk) Instant(java.time.Instant) SubmitRecord(com.google.gerrit.entities.SubmitRecord) BranchNameKey(com.google.gerrit.entities.BranchNameKey) List(java.util.List) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Ref(org.eclipse.jgit.lib.Ref) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Iterables(com.google.common.collect.Iterables) LabelId(com.google.gerrit.entities.LabelId) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RevCommit(org.eclipse.jgit.revwalk.RevCommit) RefNames.refsDraftComments(com.google.gerrit.entities.RefNames.refsDraftComments) CC(com.google.gerrit.server.notedb.ReviewerStateInternal.CC) ChangeMessage(com.google.gerrit.entities.ChangeMessage) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Change(com.google.gerrit.entities.Change) PatchSet(com.google.gerrit.entities.PatchSet) Comparator.comparing(java.util.Comparator.comparing) Address(com.google.gerrit.entities.Address) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) REVIEWER(com.google.gerrit.server.notedb.ReviewerStateInternal.REVIEWER) AssigneeStatusUpdate(com.google.gerrit.server.AssigneeStatusUpdate) LinkedHashSet(java.util.LinkedHashSet) Operation(com.google.gerrit.entities.AttentionSetUpdate.Operation) CurrentUser(com.google.gerrit.server.CurrentUser) ValidationException(com.google.gerrit.server.validators.ValidationException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) StorageException(com.google.gerrit.exceptions.StorageException) Throwables(com.google.common.base.Throwables) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ObjectId(org.eclipse.jgit.lib.ObjectId) AccountTemplateUtil(com.google.gerrit.server.util.AccountTemplateUtil) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ImmutableTable(com.google.common.collect.ImmutableTable) TimeUtil(com.google.gerrit.server.util.time.TimeUtil) REMOVED(com.google.gerrit.server.notedb.ReviewerStateInternal.REMOVED) Repository(org.eclipse.jgit.lib.Repository) Change(com.google.gerrit.entities.Change) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 92 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class IgnoreSelfApprovalRuleTest method filtersByLabel.

@Test
public void filtersByLabel() {
    LabelType codeReview = makeLabel(LabelId.CODE_REVIEW);
    PatchSetApproval approvalVerified = makeApproval(VERIFIED.getLabelId(), USER1, 2);
    PatchSetApproval approvalCr = makeApproval(codeReview.getLabelId(), USER1, 2);
    Collection<PatchSetApproval> filteredApprovals = IgnoreSelfApprovalRule.filterApprovalsByLabel(ImmutableList.of(approvalVerified, approvalCr), VERIFIED);
    assertThat(filteredApprovals).containsExactly(approvalVerified);
}
Also used : LabelType(com.google.gerrit.entities.LabelType) PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Example 93 with PatchSetApproval

use of com.google.gerrit.entities.PatchSetApproval in project gerrit by GerritCodeReview.

the class IgnoreSelfApprovalRuleTest method filtersVotesFromUser.

@Test
public void filtersVotesFromUser() {
    PatchSetApproval approvalM2 = makeApproval(VERIFIED.getLabelId(), USER1, -2);
    PatchSetApproval approvalM1 = makeApproval(VERIFIED.getLabelId(), USER1, -1);
    ImmutableList<PatchSetApproval> approvals = ImmutableList.of(approvalM2, approvalM1, makeApproval(VERIFIED.getLabelId(), USER1, 0), makeApproval(VERIFIED.getLabelId(), USER1, +1), makeApproval(VERIFIED.getLabelId(), USER1, +2));
    Collection<PatchSetApproval> filteredApprovals = IgnoreSelfApprovalRule.filterOutPositiveApprovalsOfUser(approvals, USER1);
    assertThat(filteredApprovals).containsExactly(approvalM1, approvalM2);
}
Also used : PatchSetApproval(com.google.gerrit.entities.PatchSetApproval) Test(org.junit.Test)

Aggregations

PatchSetApproval (com.google.gerrit.entities.PatchSetApproval)93 Test (org.junit.Test)57 Change (com.google.gerrit.entities.Change)41 LabelType (com.google.gerrit.entities.LabelType)22 Account (com.google.gerrit.entities.Account)20 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)14 Map (java.util.Map)14 ObjectId (org.eclipse.jgit.lib.ObjectId)14 LabelId (com.google.gerrit.entities.LabelId)13 PatchSet (com.google.gerrit.entities.PatchSet)12 SubmitRecord (com.google.gerrit.entities.SubmitRecord)12 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)11 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)10 SubmissionId (com.google.gerrit.entities.SubmissionId)9 ChangeData (com.google.gerrit.server.query.change.ChangeData)9 Inject (com.google.inject.Inject)9 Instant (java.time.Instant)9 HashMap (java.util.HashMap)9 List (java.util.List)9 ChangeMessage (com.google.gerrit.entities.ChangeMessage)8