Search in sources :

Example 1 with UnresolvableAccountException

use of com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException in project gerrit by GerritCodeReview.

the class AccountResolverTest method asUniqueWithNoResults.

@Test
public void asUniqueWithNoResults() throws Exception {
    String input = "foo";
    ImmutableList<Searcher<?>> searchers = ImmutableList.of();
    UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> search(input, searchers, AccountResolverTest::allVisiblePredicate).asUnique());
    assertThat(thrown).hasMessageThat().isEqualTo("Account 'foo' not found");
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Test(org.junit.Test)

Example 2 with UnresolvableAccountException

use of com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException in project gerrit by GerritCodeReview.

the class AccountResolverIT method checkBySelfFails.

private void checkBySelfFails() throws Exception {
    for (String input : ImmutableList.of("self", "me")) {
        Result result = resolveAsResult(input);
        assertThat(result.asIdSet()).isEmpty();
        assertThat(result.isSelf()).isTrue();
        UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> result.asUnique());
        assertThat(thrown).hasMessageThat().isEqualTo(String.format("Resolving account '%s' requires login", input));
        assertThat(thrown.isSelf()).isTrue();
    }
}
Also used : UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Result(com.google.gerrit.server.account.AccountResolver.Result)

Example 3 with UnresolvableAccountException

use of com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException 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)

Example 4 with UnresolvableAccountException

use of com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException in project gerrit by GerritCodeReview.

the class AssigneeIT method setAssigneeToInactiveUser.

@Test
public void setAssigneeToInactiveUser() throws Exception {
    PushOneCommit.Result r = createChange();
    gApi.accounts().id(user.id().get()).setActive(false);
    UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> setAssignee(r, user.email()));
    assertThat(thrown).hasMessageThat().isEqualTo("Account '" + user.email() + "' only matches inactive accounts. To use an inactive account, retry with one" + " of the following exact account IDs:\n" + user.id() + ": User1 <user1@example.com>");
}
Also used : UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 5 with UnresolvableAccountException

use of com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException in project gerrit by GerritCodeReview.

the class AccountResolverTest method asUniqueWithMultipleResults.

@Test
public void asUniqueWithMultipleResults() throws Exception {
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newAccount(1), newAccount(2)));
    UnresolvableAccountException thrown = assertThrows(UnresolvableAccountException.class, () -> search("foo", searchers, AccountResolverTest::allVisiblePredicate).asUnique());
    assertThat(thrown).hasMessageThat().isEqualTo("Account 'foo' is ambiguous (at most 3 shown):\n1: Anonymous Name (1)\n2: Anonymous Name (2)");
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Test(org.junit.Test)

Aggregations

UnresolvableAccountException (com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException)10 Test (org.junit.Test)9 Result (com.google.gerrit.server.account.AccountResolver.Result)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)2 Searcher (com.google.gerrit.server.account.AccountResolver.Searcher)2 StringSearcher (com.google.gerrit.server.account.AccountResolver.StringSearcher)2 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)1 TestAccount (com.google.gerrit.acceptance.testsuite.account.TestAccount)1 Account (com.google.gerrit.entities.Account)1