Search in sources :

Example 11 with Result

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

the class AccountResolverTest method shortCircuit.

@Test
public void shortCircuit() throws Exception {
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("f.*", true), new TestSearcher("foo|bar", false, newAccount(1)));
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.input()).isEqualTo("foo");
    assertThat(result.asIdSet()).isEmpty();
    result = search("bar", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.input()).isEqualTo("bar");
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 12 with Result

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

the class AccountResolverTest method exceptionMessageMe.

@Test
public void exceptionMessageMe() throws Exception {
    AccountResolver resolver = newAccountResolver();
    UnresolvableAccountException e = new UnresolvableAccountException(resolver.new Result("me", ImmutableList.of(), ImmutableList.of()));
    assertThat(e.isSelf()).isTrue();
    assertThat(e).hasMessageThat().isEqualTo("Resolving account 'me' requires login");
}
Also used : UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 13 with Result

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

the class AccountResolverTest method exceptionMessageSelf.

@Test
public void exceptionMessageSelf() throws Exception {
    AccountResolver resolver = newAccountResolver();
    UnresolvableAccountException e = new UnresolvableAccountException(resolver.new Result("self", ImmutableList.of(), ImmutableList.of()));
    assertThat(e.isSelf()).isTrue();
    assertThat(e).hasMessageThat().isEqualTo("Resolving account 'self' requires login");
}
Also used : UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 14 with Result

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

the class AccountResolverTest method exceptionMessageOnlyInactive.

@Test
public void exceptionMessageOnlyInactive() throws Exception {
    AccountResolver resolver = newAccountResolver();
    assertThat(new UnresolvableAccountException(resolver.new Result("foo", ImmutableList.of(), ImmutableList.of(newInactiveAccount(3), newInactiveAccount(1))))).hasMessageThat().isEqualTo("Account 'foo' only matches inactive accounts. To use an inactive account, retry" + " with one of the following exact account IDs:\n" + "1: Anonymous Name (1)\n" + "3: Anonymous Name (3)");
}
Also used : UnresolvableAccountException(com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Example 15 with Result

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

the class AccountResolverTest method shouldUseCustomAccountActivityPredicate.

@Test
public void shouldUseCustomAccountActivityPredicate() throws Exception {
    TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("f.*", false, newInactiveAccount(2));
    searcher2.setCallerShouldFilterOutInactiveCandidates();
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate, (a) -> true);
    // Searchers always short-circuit when finding a non-empty result list,
    // and this one didn't filter out inactive results,
    // so the second searcher never ran.
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
    assertThat(getOnlyElement(result.asList()).account().isActive()).isFalse();
    assertThat(filteredInactiveIds(result)).isEmpty();
}
Also used : Searcher(com.google.gerrit.server.account.AccountResolver.Searcher) StringSearcher(com.google.gerrit.server.account.AccountResolver.StringSearcher) Result(com.google.gerrit.server.account.AccountResolver.Result) Test(org.junit.Test)

Aggregations

Result (com.google.gerrit.server.account.AccountResolver.Result)17 Test (org.junit.Test)16 Searcher (com.google.gerrit.server.account.AccountResolver.Searcher)8 StringSearcher (com.google.gerrit.server.account.AccountResolver.StringSearcher)8 UnresolvableAccountException (com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)3 TestAccount (com.google.gerrit.acceptance.testsuite.account.TestAccount)1 Account (com.google.gerrit.entities.Account)1