use of com.google.gerrit.extensions.api.accounts.EmailInput 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());
}
use of com.google.gerrit.extensions.api.accounts.EmailInput 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();
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method addEmailSendsConfirmationEmail.
@Test
@GerritConfig(name = "auth.registerEmailPrivateKey", value = "HsOc6l_2lhS9G7sE_RsnS7Z6GJjdRDX14co=")
public void addEmailSendsConfirmationEmail() throws Exception {
String email = "new.email@example.com";
EmailInput input = newEmailInput(email, false);
gApi.accounts().self().addEmail(input);
assertThat(sender.getMessages()).hasSize(1);
Message m = sender.getMessages().get(0);
assertThat(m.rcpt()).containsExactly(Address.create(email));
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method cannotAddEmailAddressUsedByAnotherAccount.
@Test
public void cannotAddEmailAddressUsedByAnotherAccount() throws Exception {
String email = "new.email@example.com";
EmailInput input = newEmailInput(email);
gApi.accounts().self().addEmail(input);
ResourceConflictException thrown = assertThrows(ResourceConflictException.class, () -> gApi.accounts().id(user.username()).addEmail(input));
assertThat(thrown).hasMessageThat().contains("Identity 'mailto:" + email + "' in use by another account");
}
use of com.google.gerrit.extensions.api.accounts.EmailInput in project gerrit by GerritCodeReview.
the class AccountIT method deletePreferredEmail.
@Test
public void deletePreferredEmail() throws Exception {
AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
String previous = gApi.accounts().self().get().email;
String email = "foo.bar.baz@example.com";
EmailInput input = new EmailInput();
input.email = email;
input.noConfirmation = true;
input.preferred = true;
gApi.accounts().self().addEmail(input);
// Account is reindexed twice; once on adding the new email,
// and then again on setting the email preferred.
accountIndexedCounter.assertReindexOf(admin, 2);
// The new preferred email is set
assertThat(gApi.accounts().self().get().email).isEqualTo(email);
accountIndexedCounter.clear();
gApi.accounts().self().deleteEmail(input.email);
accountIndexedCounter.assertReindexOf(admin);
requestScopeOperations.resetCurrentApiUser();
assertThat(getEmails()).containsExactly(previous);
assertThat(gApi.accounts().self().get().email).isNull();
}
}
Aggregations