Search in sources :

Example 31 with LabelInfo

use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.

the class CustomLabelIT method customLabelMaxNoBlock_MaxVoteSubmittable.

@Test
public void customLabelMaxNoBlock_MaxVoteSubmittable() throws Exception {
    saveLabelConfig(LABEL.toBuilder().setFunction(MAX_NO_BLOCK), P.toBuilder().setFunction(NO_OP));
    PushOneCommit.Result r = createChange();
    assertThat(info(r.getChangeId()).submittable).isNull();
    revision(r).review(ReviewInput.approve().label(LABEL_NAME, 1));
    ChangeInfo c = getWithLabels(r);
    assertThat(c.submittable).isTrue();
    LabelInfo q = c.labels.get(LABEL_NAME);
    assertThat(q.all).hasSize(1);
    assertThat(q.approved).isNotNull();
    assertThat(q.recommended).isNull();
    assertThat(q.disliked).isNull();
    assertThat(q.rejected).isNull();
    assertThat(q.blocking).isNull();
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 32 with LabelInfo

use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.

the class CustomLabelIT method customLabelMaxWithBlock_MaxVoteNegativeVoteBlock.

@Test
public void customLabelMaxWithBlock_MaxVoteNegativeVoteBlock() throws Exception {
    saveLabelConfig(LABEL.toBuilder().setFunction(MAX_WITH_BLOCK));
    PushOneCommit.Result r = createChange();
    revision(r).review(new ReviewInput().label(LABEL_NAME, 1));
    revision(r).review(new ReviewInput().label(LABEL_NAME, -1));
    ChangeInfo c = getWithLabels(r);
    LabelInfo q = c.labels.get(LABEL_NAME);
    assertThat(q.all).hasSize(1);
    assertThat(q.approved).isNull();
    assertThat(q.recommended).isNull();
    assertThat(q.disliked).isNull();
    assertThat(q.rejected).isNotNull();
    assertThat(q.blocking).isTrue();
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 33 with LabelInfo

use of com.google.gerrit.extensions.common.LabelInfo in project gerrit by GerritCodeReview.

the class CommentAddedEventIT method reviewChange_MultipleVotes.

@Test
public void reviewChange_MultipleVotes() throws Exception {
    TestListener listener = new TestListener();
    try (Registration registration = extensionRegistry.newRegistration().add(listener)) {
        saveLabelConfig();
        PushOneCommit.Result r = createChange();
        ReviewInput reviewInput = new ReviewInput().label(label.getName(), -1);
        reviewInput.message = label.getName();
        revision(r).review(reviewInput);
        ChangeInfo c = get(r.getChangeId(), DETAILED_LABELS);
        LabelInfo q = c.labels.get(label.getName());
        assertThat(q.all).hasSize(1);
        ApprovalValues labelAttr = getApprovalValues(label, listener);
        assertThat(labelAttr.oldValue).isEqualTo(0);
        assertThat(labelAttr.value).isEqualTo(-1);
        assertThat(listener.getLastCommentAddedEvent().getComment()).isEqualTo(String.format("Patch Set 1: %s-1\n\n%s", label.getName(), label.getName()));
        // there should be 3 approval labels (label, pLabel, and CRVV)
        assertThat(listener.getLastCommentAddedEvent().getApprovals()).hasSize(3);
        // check the approvals that were not voted on
        ApprovalValues pLabelAttr = getApprovalValues(pLabel, listener);
        assertThat(pLabelAttr.oldValue).isNull();
        assertThat(pLabelAttr.value).isEqualTo(0);
        LabelType crLabel = LabelType.withDefaultValues("Code-Review");
        ApprovalValues crlAttr = getApprovalValues(crLabel, listener);
        assertThat(crlAttr.oldValue).isNull();
        assertThat(crlAttr.value).isEqualTo(0);
        // update pLabel approval
        reviewInput = new ReviewInput().label(pLabel.getName(), 1);
        reviewInput.message = pLabel.getName();
        revision(r).review(reviewInput);
        c = get(r.getChangeId(), DETAILED_LABELS);
        q = c.labels.get(label.getName());
        assertThat(q.all).hasSize(1);
        pLabelAttr = getApprovalValues(pLabel, listener);
        assertThat(pLabelAttr.oldValue).isEqualTo(0);
        assertThat(pLabelAttr.value).isEqualTo(1);
        assertThat(listener.getLastCommentAddedEvent().getComment()).isEqualTo(String.format("Patch Set 1: %s+1\n\n%s", pLabel.getName(), pLabel.getName()));
        // check the approvals that were not voted on
        labelAttr = getApprovalValues(label, listener);
        assertThat(labelAttr.oldValue).isNull();
        assertThat(labelAttr.value).isEqualTo(-1);
        crlAttr = getApprovalValues(crLabel, listener);
        assertThat(crlAttr.oldValue).isNull();
        assertThat(crlAttr.value).isEqualTo(0);
    }
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) LabelType(com.google.gerrit.entities.LabelType) ReviewInput(com.google.gerrit.extensions.api.changes.ReviewInput) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

LabelInfo (com.google.gerrit.extensions.common.LabelInfo)33 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)27 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)23 Test (org.junit.Test)23 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)22 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)13 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)10 RestResponse (com.google.gerrit.acceptance.RestResponse)4 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)4 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)4 HashMap (java.util.HashMap)4 TreeMap (java.util.TreeMap)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Lists (com.google.common.collect.Lists)3 Maps (com.google.common.collect.Maps)3 Nullable (com.google.gerrit.common.Nullable)3 AccountLoader (com.google.gerrit.server.account.AccountLoader)3 ReviewerStateInternal (com.google.gerrit.server.notedb.ReviewerStateInternal)3 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)3 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)3