Search in sources :

Example 1 with RestResponse

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

the class EmailIT method getEmails.

private Set<String> getEmails() throws Exception {
    RestResponse r = adminRestSession.get("/accounts/self/emails");
    r.assertOK();
    List<EmailInfo> emails = newGson().fromJson(r.getReader(), new TypeToken<List<EmailInfo>>() {
    }.getType());
    return emails.stream().map(e -> e.email).collect(toSet());
}
Also used : List(java.util.List) TypeToken(com.google.gson.reflect.TypeToken) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) RestResponse(com.google.gerrit.acceptance.RestResponse) Set(java.util.Set) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Collectors.toSet(java.util.stream.Collectors.toSet) EmailInfo(com.google.gerrit.extensions.common.EmailInfo) RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) EmailInfo(com.google.gerrit.extensions.common.EmailInfo)

Example 2 with RestResponse

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

the class EmailIT method createEmail.

private void createEmail(String email) throws Exception {
    EmailInput input = new EmailInput();
    input.noConfirmation = true;
    RestResponse r = adminRestSession.put("/accounts/self/emails/" + email, input);
    r.assertCreated();
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput)

Example 3 with RestResponse

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

the class ExternalIdIT method getExternalIds.

@Test
public void getExternalIds() throws Exception {
    Collection<ExternalId> expectedIds = accountCache.get(user.getId()).getExternalIds();
    List<AccountExternalIdInfo> expectedIdInfos = toExternalIdInfos(expectedIds);
    RestResponse response = userRestSession.get("/accounts/self/external.ids");
    response.assertOK();
    List<AccountExternalIdInfo> results = newGson().fromJson(response.getReader(), new TypeToken<List<AccountExternalIdInfo>>() {
    }.getType());
    Collections.sort(expectedIdInfos);
    Collections.sort(results);
    assertThat(results).containsExactlyElementsIn(expectedIdInfos);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) ExternalId(com.google.gerrit.server.account.externalids.ExternalId) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 4 with RestResponse

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

the class CapabilitiesIT method capabilitiesAdmin.

@Test
public void capabilitiesAdmin() throws Exception {
    RestResponse r = adminRestSession.get("/accounts/self/capabilities");
    r.assertOK();
    CapabilityInfo info = (new Gson()).fromJson(r.getReader(), new TypeToken<CapabilityInfo>() {
    }.getType());
    for (String c : GlobalCapability.getAllNames()) {
        if (BATCH_CHANGES_LIMIT.equals(c)) {
            // It does not have default value for any user as it can override the
            // 'receive.batchChangesLimit'. It needs to be granted explicitly.
            assertThat(info.batchChangesLimit).isNull();
        } else if (PRIORITY.equals(c)) {
            assertThat(info.priority).isFalse();
        } else if (QUERY_LIMIT.equals(c)) {
            assert_().withFailureMessage("missing queryLimit").that(info.queryLimit).isNotNull();
            assertThat(info.queryLimit.min).isEqualTo((short) 0);
            assertThat(info.queryLimit.max).isEqualTo((short) DEFAULT_MAX_QUERY_LIMIT);
        } else if (ACCESS_DATABASE.equals(c)) {
            assertThat(info.accessDatabase).isFalse();
        } else if (RUN_AS.equals(c)) {
            assertThat(info.runAs).isFalse();
        } else {
            assert_().withFailureMessage(String.format("capability %s was not granted", c)).that((Boolean) CapabilityInfo.class.getField(c).get(info)).isTrue();
        }
    }
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) TypeToken(com.google.gson.reflect.TypeToken) Gson(com.google.gson.Gson) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with RestResponse

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

the class ChangeReviewersIT method removingReviewerRemovesTheirVote.

@Test
public void removingReviewerRemovesTheirVote() throws Exception {
    String crLabel = "Code-Review";
    PushOneCommit.Result r = createChange();
    ReviewInput input = ReviewInput.approve().reviewer(admin.email);
    ReviewResult addResult = review(r.getChangeId(), r.getCommit().name(), input);
    assertThat(addResult.reviewers).isNotNull();
    assertThat(addResult.reviewers).hasSize(1);
    Map<String, LabelInfo> changeLabels = getChangeLabels(r.getChangeId());
    assertThat(changeLabels.get(crLabel).all).hasSize(1);
    RestResponse deleteResult = deleteReviewer(r.getChangeId(), admin);
    deleteResult.assertNoContent();
    changeLabels = getChangeLabels(r.getChangeId());
    assertThat(changeLabels.get(crLabel).all).isNull();
    // Check that the vote is gone even after the reviewer is added back
    addReviewer(r.getChangeId(), admin.email);
    changeLabels = getChangeLabels(r.getChangeId());
    assertThat(changeLabels.get(crLabel).all).isNull();
}
Also used : LabelInfo(com.google.gerrit.extensions.common.LabelInfo) 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