Search in sources :

Example 16 with LabelInfo

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

the class ChangeReviewersIT method addSelfAsCc.

@Test
public void addSelfAsCc() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // user adds self as CC.
    ReviewInput input = new ReviewInput().reviewer(user.username, CC, false);
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    ReviewResult result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER);
        assertReviewers(c, CC, user);
        // Verify no approvals were added.
        assertThat(c.labels).isNotNull();
        LabelInfo label = c.labels.get("Code-Review");
        assertThat(label).isNotNull();
        assertThat(label.all).isNull();
    } else {
        // When approvals are stored in ReviewDb, we still create a label for
        // the reviewing user, and force them into the REVIEWER state.
        assertReviewers(c, REVIEWER, user);
        assertReviewers(c, CC);
        LabelInfo label = c.labels.get("Code-Review");
        assertThat(label).isNotNull();
        assertThat(label.all).isNotNull();
        assertThat(label.all).hasSize(1);
        ApprovalInfo approval = label.all.get(0);
        assertThat(approval._accountId).isEqualTo(user.getId().get());
    }
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) 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 17 with LabelInfo

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

the class ChangeReviewersIT method reviewerReplyWithoutVote.

@Test
public void reviewerReplyWithoutVote() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER);
    assertReviewers(c, CC);
    LabelInfo label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNull();
    // Add user as REVIEWER.
    ReviewInput input = new ReviewInput().reviewer(user.username);
    ReviewResult result = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state. Both admin and user should be REVIEWERs now,
    // because admin gets forced into REVIEWER state by virtue of being owner.
    c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, admin, user);
    assertReviewers(c, CC);
    label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(2);
    Map<Integer, Integer> approvals = new HashMap<>();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(admin.getId().get(), 0);
    assertThat(approvals).containsEntry(user.getId().get(), 0);
    // Comment as user without voting. This should delete the approval and
    // then replace it with the default value.
    input = new ReviewInput().message("hello");
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    // Verify reviewer state.
    c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, admin, user);
    assertReviewers(c, CC);
    label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(2);
    approvals.clear();
    for (ApprovalInfo approval : label.all) {
        approvals.put(approval._accountId, approval.value);
    }
    assertThat(approvals).containsEntry(admin.getId().get(), 0);
    assertThat(approvals).containsEntry(user.getId().get(), 0);
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) HashMap(java.util.HashMap) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) 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 18 with LabelInfo

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

the class ChangeReviewersIT method addSelfAsReviewer.

@Test
public void addSelfAsReviewer() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // user adds self as REVIEWER.
    ReviewInput input = new ReviewInput().reviewer(user.username);
    RestResponse resp = userRestSession.post("/changes/" + r.getChangeId() + "/revisions/" + r.getCommit().getName() + "/review", input);
    ReviewResult result = readContentFromJson(resp, 200, ReviewResult.class);
    assertThat(result.labels).isNull();
    assertThat(result.reviewers).isNotNull();
    assertThat(result.reviewers).hasSize(1);
    // Verify reviewer state.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    assertReviewers(c, REVIEWER, user);
    assertReviewers(c, CC);
    LabelInfo label = c.labels.get("Code-Review");
    assertThat(label).isNotNull();
    assertThat(label.all).isNotNull();
    assertThat(label.all).hasSize(1);
    ApprovalInfo approval = label.all.get(0);
    assertThat(approval._accountId).isEqualTo(user.getId().get());
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) ApprovalInfo(com.google.gerrit.extensions.common.ApprovalInfo) ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) ReviewResult(com.google.gerrit.extensions.api.changes.ReviewResult) 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 19 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 {
    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());
    LabelInfo q = c.labels.get(label.getName());
    assertThat(q.all).hasSize(1);
    ApprovalValues labelAttr = getApprovalValues(label);
    assertThat(labelAttr.oldValue).isEqualTo(0);
    assertThat(labelAttr.value).isEqualTo(-1);
    assertThat(lastCommentAddedEvent.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(lastCommentAddedEvent.getApprovals()).hasSize(3);
    // check the approvals that were not voted on
    ApprovalValues pLabelAttr = getApprovalValues(pLabel);
    assertThat(pLabelAttr.oldValue).isNull();
    assertThat(pLabelAttr.value).isEqualTo(0);
    LabelType crLabel = LabelType.withDefaultValues("Code-Review");
    ApprovalValues crlAttr = getApprovalValues(crLabel);
    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());
    q = c.labels.get(label.getName());
    assertThat(q.all).hasSize(1);
    pLabelAttr = getApprovalValues(pLabel);
    assertThat(pLabelAttr.oldValue).isEqualTo(0);
    assertThat(pLabelAttr.value).isEqualTo(1);
    assertThat(lastCommentAddedEvent.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);
    assertThat(labelAttr.oldValue).isNull();
    assertThat(labelAttr.value).isEqualTo(-1);
    crlAttr = getApprovalValues(crLabel);
    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) LabelType(com.google.gerrit.common.data.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)

Example 20 with LabelInfo

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

the class CustomLabelIT method customLabelAnyWithBlock_Addreviewer_ZeroVote.

@Test
public void customLabelAnyWithBlock_Addreviewer_ZeroVote() throws Exception {
    P.setFunctionName("AnyWithBlock");
    saveLabelConfig();
    PushOneCommit.Result r = createChange();
    AddReviewerInput in = new AddReviewerInput();
    in.reviewer = user.email;
    gApi.changes().id(r.getChangeId()).addReviewer(in);
    ReviewInput input = new ReviewInput().label(P.getName(), 0);
    input.message = "foo";
    revision(r).review(input);
    ChangeInfo c = get(r.getChangeId());
    LabelInfo q = c.labels.get(P.getName());
    assertThat(q.all).hasSize(2);
    assertThat(q.disliked).isNull();
    assertThat(q.rejected).isNull();
    assertThat(q.blocking).isNull();
    assertThat(lastCommentAddedEvent.getComment()).isEqualTo("Patch Set 1:\n\n" + input.message);
}
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) AddReviewerInput(com.google.gerrit.extensions.api.changes.AddReviewerInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

LabelInfo (com.google.gerrit.extensions.common.LabelInfo)24 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)21 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)19 Test (org.junit.Test)19 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)11 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)8 RestResponse (com.google.gerrit.acceptance.RestResponse)4 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)4 LabelType (com.google.gerrit.common.data.LabelType)3 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)3 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 RevCommit (org.eclipse.jgit.revwalk.RevCommit)3 SubmitRecord (com.google.gerrit.common.data.SubmitRecord)2 Account (com.google.gerrit.reviewdb.client.Account)2 HashMap (java.util.HashMap)2 TreeMap (java.util.TreeMap)2 AutoValue (com.google.auto.value.AutoValue)1 Joiner (com.google.common.base.Joiner)1