Search in sources :

Example 1 with EmailApi

use of com.google.gerrit.extensions.api.accounts.EmailApi in project gerrit by GerritCodeReview.

the class EmailIT method emailApi.

@Test
public void emailApi() throws Exception {
    String email = "foo@example.com";
    assertThat(getEmails()).doesNotContain(email);
    // Create email
    EmailInput emailInput = new EmailInput();
    emailInput.email = email;
    emailInput.noConfirmation = true;
    gApi.accounts().self().createEmail(emailInput);
    assertThat(getEmails()).contains(email);
    assertThat(gApi.accounts().self().get().email).isNotEqualTo(email);
    // Get email
    requestScopeOperations.resetCurrentApiUser();
    EmailApi emailApi = gApi.accounts().self().email(email);
    EmailInfo emailInfo = emailApi.get();
    assertThat(emailInfo.email).isEqualTo(email);
    assertThat(emailInfo.preferred).isNull();
    assertThat(emailInfo.pendingConfirmation).isNull();
    // Set as preferred email
    emailApi.setPreferred();
    assertThat(gApi.accounts().self().get().email).isEqualTo(email);
    // Get email again (now it's the preferred email)
    requestScopeOperations.resetCurrentApiUser();
    emailApi = gApi.accounts().self().email(email);
    emailInfo = emailApi.get();
    assertThat(emailInfo.email).isEqualTo(email);
    assertThat(emailInfo.preferred).isTrue();
    assertThat(emailInfo.pendingConfirmation).isNull();
    // Delete email
    emailApi.delete();
    assertThat(getEmails()).doesNotContain(email);
    // Now the email is no longer found
    requestScopeOperations.resetCurrentApiUser();
    assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().self().email(email).get());
}
Also used : EmailApi(com.google.gerrit.extensions.api.accounts.EmailApi) EmailInfo(com.google.gerrit.extensions.common.EmailInfo) IdString(com.google.gerrit.extensions.restapi.IdString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)1 EmailApi (com.google.gerrit.extensions.api.accounts.EmailApi)1 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)1 EmailInfo (com.google.gerrit.extensions.common.EmailInfo)1 IdString (com.google.gerrit.extensions.restapi.IdString)1 Test (org.junit.Test)1