Search in sources :

Example 46 with RestResponse

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

the class ExternalIdIT method deleteExternalIds_Conflict.

@Test
public void deleteExternalIds_Conflict() throws Exception {
    List<String> toDelete = new ArrayList<>();
    String externalIdStr = "username:" + user.username;
    toDelete.add(externalIdStr);
    RestResponse response = userRestSession.post("/accounts/self/external.ids:delete", toDelete);
    response.assertConflict();
    assertThat(response.getEntityContent()).isEqualTo(String.format("External id %s cannot be deleted", externalIdStr));
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ArrayList(java.util.ArrayList) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 47 with RestResponse

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

the class ExternalIdIT method deleteExternalIds.

@Test
public void deleteExternalIds() throws Exception {
    setApiUser(user);
    List<AccountExternalIdInfo> externalIds = gApi.accounts().self().getExternalIds();
    List<String> toDelete = new ArrayList<>();
    List<AccountExternalIdInfo> expectedIds = new ArrayList<>();
    for (AccountExternalIdInfo id : externalIds) {
        if (id.canDelete != null && id.canDelete) {
            toDelete.add(id.identity);
            continue;
        }
        expectedIds.add(id);
    }
    assertThat(toDelete).hasSize(1);
    RestResponse response = userRestSession.post("/accounts/self/external.ids:delete", toDelete);
    response.assertNoContent();
    List<AccountExternalIdInfo> results = gApi.accounts().self().getExternalIds();
    // The external ID in WebSession will not be set for tests, resulting that
    // "mailto:user@example.com" can be deleted while "username:user" can't.
    assertThat(results).hasSize(1);
    assertThat(results).containsExactlyElementsIn(expectedIds);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ArrayList(java.util.ArrayList) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 48 with RestResponse

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

the class EmailIT method deleteEmail.

@Test
public void deleteEmail() throws Exception {
    String email = "foo.baz@example.com";
    assertThat(getEmails()).doesNotContain(email);
    createEmail(email);
    assertThat(getEmails()).contains(email);
    RestResponse r = adminRestSession.delete("/accounts/self/emails/" + email);
    r.assertNoContent();
    assertThat(getEmails()).doesNotContain(email);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 49 with RestResponse

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

the class EmailIT method deleteUrlEncodedEmail.

@Test
public void deleteUrlEncodedEmail() throws Exception {
    String email = "foo.baz2@example.com";
    assertThat(getEmails()).doesNotContain(email);
    createEmail(email);
    assertThat(getEmails()).contains(email);
    RestResponse r = adminRestSession.delete("/accounts/self/emails/" + email.replace("@", "%40"));
    r.assertNoContent();
    assertThat(getEmails()).doesNotContain(email);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 50 with RestResponse

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

the class ExternalIdIT method deleteExternalIdsOfOtherUserWithAccessDatabase.

@Test
public void deleteExternalIdsOfOtherUserWithAccessDatabase() throws Exception {
    allowGlobalCapabilities(REGISTERED_USERS, GlobalCapability.ACCESS_DATABASE);
    List<AccountExternalIdInfo> externalIds = gApi.accounts().self().getExternalIds();
    List<String> toDelete = new ArrayList<>();
    List<AccountExternalIdInfo> expectedIds = new ArrayList<>();
    for (AccountExternalIdInfo id : externalIds) {
        if (id.canDelete != null && id.canDelete) {
            toDelete.add(id.identity);
            continue;
        }
        expectedIds.add(id);
    }
    assertThat(toDelete).hasSize(1);
    setApiUser(user);
    RestResponse response = userRestSession.post("/accounts/" + admin.id + "/external.ids:delete", toDelete);
    response.assertNoContent();
    List<AccountExternalIdInfo> results = gApi.accounts().id(admin.id.get()).getExternalIds();
    // The external ID in WebSession will not be set for tests, resulting that
    // "mailto:user@example.com" can be deleted while "username:user" can't.
    assertThat(results).hasSize(1);
    assertThat(results).containsExactlyElementsIn(expectedIds);
}
Also used : RestResponse(com.google.gerrit.acceptance.RestResponse) ArrayList(java.util.ArrayList) AccountExternalIdInfo(com.google.gerrit.extensions.common.AccountExternalIdInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

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