Search in sources :

Example 6 with Searcher

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

the class AccountResolverTest method noShortCircuit.

@Test
public void noShortCircuit() throws Exception {
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newAccount(1)), new TestSearcher("bar", false, newAccount(2), newAccount(3)));
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.input()).isEqualTo("foo");
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1));
    result = search("bar", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.input()).isEqualTo("bar");
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(2, 3));
    result = search("baz", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.input()).isEqualTo("baz");
    assertThat(result.asIdSet()).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)

Example 7 with Searcher

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

Example 8 with Searcher

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

the class AccountResolverTest method dontFilterInactive.

@Test
public void dontFilterInactive() throws Exception {
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(new TestSearcher("foo", false, newInactiveAccount(1)), new TestSearcher("f.*", false, newInactiveAccount(2)));
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    // 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)

Example 9 with Searcher

use of com.google.gerrit.server.account.AccountResolver.Searcher 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 10 with Searcher

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

Searcher (com.google.gerrit.server.account.AccountResolver.Searcher)10 StringSearcher (com.google.gerrit.server.account.AccountResolver.StringSearcher)10 Test (org.junit.Test)10 Result (com.google.gerrit.server.account.AccountResolver.Result)8 UnresolvableAccountException (com.google.gerrit.server.account.AccountResolver.UnresolvableAccountException)2