Search in sources :

Example 1 with TestAccount

use of com.google.gerrit.acceptance.testsuite.account.TestAccount in project gerrit by GerritCodeReview.

the class RequestScopeOperationsImplTest method setApiUserToExistingUserByTestAccount.

@Test
public void setApiUserToExistingUserByTestAccount() throws Exception {
    fastCheckCurrentUser(admin.id());
    TestAccount testAccount = accountOperations.account(accountOperations.newAccount().username("tester").create()).get();
    AcceptanceTestRequestScope.Context oldCtx = requestScopeOperations.setApiUser(testAccount);
    assertThat(oldCtx.getUser().getAccountId()).isEqualTo(admin.id());
    checkCurrentUser(testAccount.accountId());
}
Also used : AcceptanceTestRequestScope(com.google.gerrit.acceptance.AcceptanceTestRequestScope) TestAccount(com.google.gerrit.acceptance.testsuite.account.TestAccount) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with TestAccount

use of com.google.gerrit.acceptance.testsuite.account.TestAccount in project gerrit by GerritCodeReview.

the class AccountResolverIT method onlyExactIdReturnsInactiveAccounts.

@Test
public void onlyExactIdReturnsInactiveAccounts() throws Exception {
    TestAccount account = accountOperations.account(accountOperations.newAccount().fullname("Inactiveuser Name").preferredEmail("inactiveuser@example.com").username("inactiveusername").create()).get();
    Account.Id id = account.accountId();
    String nameEmail = account.fullname().get() + " <" + account.preferredEmail().get() + ">";
    ImmutableList<String> inputs = ImmutableList.of(account.fullname().get() + " (" + account.accountId() + ")", account.fullname().get(), account.preferredEmail().get(), nameEmail, Splitter.on(' ').splitToList(account.fullname().get()).get(0));
    assertThat(resolve(account.accountId())).containsExactly(id);
    for (String input : inputs) {
        assertWithMessage("results for %s (active)", input).that(resolve(input)).containsExactly(id);
    }
    gApi.accounts().id(id.get()).setActive(false);
    assertThat(resolve(account.accountId())).containsExactly(id);
    for (String input : inputs) {
        Result result = accountResolver.resolve(input);
        assertWithMessage("results for %s (inactive)", input).that(result.asIdSet()).isEmpty();
        UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> result.asUnique());
        assertThat(thrown).hasMessageThat().isEqualTo("Account '" + input + "' only matches inactive accounts. To use an inactive account, retry" + " with one of the following exact account IDs:\n" + id + ": " + nameEmail);
        assertWithMessage("results by name or email for %s (inactive)", input).that(resolveByNameOrEmail(input)).isEmpty();
    }
}
Also used : Account(com.google.gerrit.entities.Account) TestAccount(com.google.gerrit.acceptance.testsuite.account.TestAccount) UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) TestAccount(com.google.gerrit.acceptance.testsuite.account.TestAccount) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 TestAccount (com.google.gerrit.acceptance.testsuite.account.TestAccount)2 Test (org.junit.Test)2 AcceptanceTestRequestScope (com.google.gerrit.acceptance.AcceptanceTestRequestScope)1 Account (com.google.gerrit.entities.Account)1 Result (com.google.gerrit.server.account.AccountResolver.Result)1 UnresolvableAccountException (com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException)1