Search in sources :

Example 41 with AccountIndexedCounter

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

the class AccountIT method addEmail.

@Test
public void addEmail() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        List<String> emails = ImmutableList.of("new.email@example.com", "new.email@example.systems");
        Set<String> currentEmails = getEmails();
        for (String email : emails) {
            assertThat(currentEmails).doesNotContain(email);
            EmailInput input = newEmailInput(email);
            gApi.accounts().self().addEmail(input);
            accountIndexedCounter.assertReindexOf(admin);
        }
        requestScopeOperations.resetCurrentApiUser();
        assertThat(getEmails()).containsAtLeastElementsIn(emails);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) EmailInput(com.google.gerrit.extensions.api.accounts.EmailInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 42 with AccountIndexedCounter

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

the class AccountIT method getByIntId.

@Test
public void getByIntId() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        AccountInfo info = gApi.accounts().id("admin").get();
        AccountInfo infoByIntId = gApi.accounts().id(info._accountId).get();
        assertThat(info.name).isEqualTo(infoByIntId.name);
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 43 with AccountIndexedCounter

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

the class AccountIT method self.

@Test
public void self() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        AccountInfo info = gApi.accounts().self().get();
        assertUser(info, admin);
        info = gApi.accounts().id("self").get();
        assertUser(info, admin);
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 44 with AccountIndexedCounter

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

the class AccountIT method suggestAccounts.

@Test
public void suggestAccounts() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        String adminUsername = "admin";
        List<AccountInfo> result = gApi.accounts().suggestAccounts().withQuery(adminUsername).get();
        assertThat(result).hasSize(1);
        assertThat(result.get(0).username).isEqualTo(adminUsername);
        List<AccountInfo> resultShortcutApi = gApi.accounts().suggestAccounts(adminUsername).get();
        assertThat(resultShortcutApi).hasSize(result.size());
        List<AccountInfo> emptyResult = gApi.accounts().suggestAccounts("unknown").get();
        assertThat(emptyResult).isEmpty();
        accountIndexedCounter.assertNoReindex();
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) PublicKeyStore.keyToString(com.google.gerrit.gpg.PublicKeyStore.keyToString) AccountInfo(com.google.gerrit.extensions.common.AccountInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 45 with AccountIndexedCounter

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

the class AccountIT method active.

@Test
public void active() throws Exception {
    AccountIndexedCounter accountIndexedCounter = new AccountIndexedCounter();
    try (Registration registration = extensionRegistry.newRegistration().add(accountIndexedCounter)) {
        int id = gApi.accounts().id("user").get()._accountId;
        assertThat(gApi.accounts().id("user").getActive()).isTrue();
        gApi.accounts().id("user").setActive(false);
        accountIndexedCounter.assertReindexOf(user);
        // Inactive users may only be resolved by ID.
        ResourceNotFoundException thrown = assertThrows(ResourceNotFoundException.class, () -> gApi.accounts().id("user"));
        assertThat(thrown).hasMessageThat().isEqualTo("Account 'user' only matches inactive accounts. To use an inactive account, retry" + " with one of the following exact account IDs:\n" + id + ": User1 <user1@example.com>");
        assertThat(gApi.accounts().id(id).getActive()).isFalse();
        gApi.accounts().id(id).setActive(true);
        assertThat(gApi.accounts().id("user").getActive()).isTrue();
        accountIndexedCounter.assertReindexOf(user);
    }
}
Also used : AccountIndexedCounter(com.google.gerrit.acceptance.AccountIndexedCounter) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) Fingerprint(com.google.gerrit.gpg.Fingerprint) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

AccountIndexedCounter (com.google.gerrit.acceptance.AccountIndexedCounter)47 Registration (com.google.gerrit.acceptance.ExtensionRegistry.Registration)47 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)44 Test (org.junit.Test)44 PublicKeyStore.keyToString (com.google.gerrit.gpg.PublicKeyStore.keyToString)18 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)18 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)16 TestAccount (com.google.gerrit.acceptance.TestAccount)13 AccountInfo (com.google.gerrit.extensions.common.AccountInfo)13 Config (org.eclipse.jgit.lib.Config)13 EmailInput (com.google.gerrit.extensions.api.accounts.EmailInput)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)5 TestKey (com.google.gerrit.gpg.testing.TestKey)5 Truth.assertWithMessage (com.google.common.truth.Truth.assertWithMessage)4 Message (com.google.gerrit.testing.FakeEmailSender.Message)4 UseSsh (com.google.gerrit.acceptance.UseSsh)3 Account (com.google.gerrit.entities.Account)3 GpgKeyInfo (com.google.gerrit.extensions.common.GpgKeyInfo)3 SshKeyInfo (com.google.gerrit.extensions.common.SshKeyInfo)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3