Search in sources :

Example 51 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class DeleteVoteIT method deleteVote.

private void deleteVote(boolean onRevisionLevel) throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.changes().id(r.getChangeId()).revision(r.getCommit().name()).review(ReviewInput.approve());
    PushOneCommit.Result r2 = amendChange(r.getChangeId());
    setApiUser(user);
    recommend(r.getChangeId());
    sender.clear();
    String endPoint = "/changes/" + r.getChangeId() + (onRevisionLevel ? ("/revisions/" + r2.getCommit().getName()) : "") + "/reviewers/" + user.getId().toString() + "/votes/Code-Review";
    RestResponse response = adminRestSession.delete(endPoint);
    response.assertNoContent();
    List<FakeEmailSender.Message> messages = sender.getMessages();
    assertThat(messages).hasSize(1);
    FakeEmailSender.Message msg = messages.get(0);
    assertThat(msg.rcpt()).containsExactly(user.emailAddress);
    assertThat(msg.body()).contains(admin.fullName + " has removed a vote on this change.\n");
    assertThat(msg.body()).contains("Removed Code-Review+1 by " + user.fullName + " <" + user.email + ">\n");
    endPoint = "/changes/" + r.getChangeId() + (onRevisionLevel ? ("/revisions/" + r2.getCommit().getName()) : "") + "/reviewers/" + user.getId().toString() + "/votes";
    response = adminRestSession.get(endPoint);
    response.assertOK();
    Map<String, Short> m = newGson().fromJson(response.getReader(), new TypeToken<Map<String, Short>>() {
    }.getType());
    assertThat(m).containsExactly("Code-Review", Short.valueOf((short) 0));
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    ChangeMessageInfo message = Iterables.getLast(c.messages);
    assertThat(message.author._accountId).isEqualTo(admin.getId().get());
    assertThat(message.message).isEqualTo("Removed Code-Review+1 by User <user@example.com>\n");
    assertThat(getReviewers(c.reviewers.get(REVIEWER))).containsExactlyElementsIn(ImmutableSet.of(admin.getId(), user.getId()));
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) FakeEmailSender(com.google.gerrit.testutil.FakeEmailSender) ChangeMessageInfo(com.google.gerrit.extensions.common.ChangeMessageInfo) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) TypeToken(com.google.gson.reflect.TypeToken)

Example 52 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class CorsIT method putWithOriginRefused.

@Test
public void putWithOriginRefused() throws Exception {
    Result change = createChange();
    String origin = "http://example.com";
    RestResponse r = adminRestSession.putWithHeader("/changes/" + change.getChangeId() + "/topic", new BasicHeader(ORIGIN, origin), "A");
    r.assertOK();
    checkCors(r, false, origin);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) BasicHeader(org.apache.http.message.BasicHeader) Result(com.google.gerrit.acceptance.PushOneCommit.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 53 with RestResponse

use of com.google.gerrit.acceptance.RestResponse in project gerrit by GerritCodeReview.

the class ChangeReviewersIT method driveByComment.

@Test
public void driveByComment() throws Exception {
    // Create change owned by admin.
    PushOneCommit.Result r = createChange();
    // Post drive-by message as user.
    ReviewInput input = new ReviewInput().message("hello");
    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).isNull();
    // Verify user is added to CC list.
    ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
    if (notesMigration.readChanges()) {
        assertReviewers(c, REVIEWER);
        assertReviewers(c, CC, user);
    } else {
        // If we aren't reading from NoteDb, the user will appear as a
        // reviewer.
        assertReviewers(c, REVIEWER, user);
        assertReviewers(c, CC);
    }
}
Also used : 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 54 with RestResponse

use of com.google.gerrit.acceptance.RestResponse 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 55 with RestResponse

use of com.google.gerrit.acceptance.RestResponse 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)

Aggregations

RestResponse (com.google.gerrit.acceptance.RestResponse)79 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Test (org.junit.Test)67 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)17 TypeToken (com.google.gson.reflect.TypeToken)15 ReviewInput (com.google.gerrit.extensions.api.changes.ReviewInput)9 CacheInfo (com.google.gerrit.server.config.ListCaches.CacheInfo)6 TaskInfo (com.google.gerrit.server.config.ListTasks.TaskInfo)6 ReviewResult (com.google.gerrit.extensions.api.changes.ReviewResult)5 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)5 Result (com.google.gerrit.acceptance.PushOneCommit.Result)4 AccountExternalIdInfo (com.google.gerrit.extensions.common.AccountExternalIdInfo)4 LabelInfo (com.google.gerrit.extensions.common.LabelInfo)4 ArrayList (java.util.ArrayList)4 ApprovalInfo (com.google.gerrit.extensions.common.ApprovalInfo)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 TestProjectInput (com.google.gerrit.acceptance.TestProjectInput)2 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)2 AddReviewerInput (com.google.gerrit.extensions.api.changes.AddReviewerInput)2 PublishChangeEditInput (com.google.gerrit.extensions.api.changes.PublishChangeEditInput)2