Search in sources :

Example 1 with Searcher

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

the class AccountResolverTest method shortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList.

@Test
public void shortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList() throws Exception {
    AccountState account1 = newAccount(1);
    AccountState account2 = newInactiveAccount(2);
    TestSearcher searcher1 = new TestSearcher("foo", true, account2);
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("foo", false, account1, account2);
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    // searcher1 matched and then filtered out all candidates because account2 is inactive, but
    // still short-circuited.
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.asIdSet()).isEmpty();
    assertThat(filteredInactiveIds(result)).containsExactlyElementsIn(ids(2));
}
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 2 with Searcher

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

the class AccountResolverTest method filterInactiveEventuallyFindingNoResults.

@Test
public void filterInactiveEventuallyFindingNoResults() 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);
    assertThat(result.asIdSet()).isEmpty();
    assertThat(filteredInactiveIds(result)).containsExactlyElementsIn(ids(1, 2));
}
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 3 with Searcher

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

the class AccountResolverTest method filterInactiveEventuallyFindingResults.

@Test
public void filterInactiveEventuallyFindingResults() throws Exception {
    TestSearcher searcher1 = new TestSearcher("foo", false, newInactiveAccount(1));
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("f.*", false, newAccount(2));
    searcher2.setCallerShouldFilterOutInactiveCandidates();
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(search("foo", searchers, AccountResolverTest::allVisiblePredicate).asIdSet()).containsExactlyElementsIn(ids(2));
    // No info about inactive results exposed if there was at least one active result.
    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 4 with Searcher

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

the class AccountResolverTest method dontShortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList.

@Test
public void dontShortCircuitAfterFilteringInactiveCandidatesResultsInEmptyList() throws Exception {
    AccountState account1 = newAccount(1);
    AccountState account2 = newInactiveAccount(2);
    TestSearcher searcher1 = new TestSearcher("foo", false, account2);
    searcher1.setCallerShouldFilterOutInactiveCandidates();
    TestSearcher searcher2 = new TestSearcher("foo", false, account1, account2);
    ImmutableList<Searcher<?>> searchers = ImmutableList.of(searcher1, searcher2);
    // searcher1 matched, but filtered out all candidates because account2 is inactive. Actual
    // result came from searcher2 instead.
    Result result = search("foo", searchers, AccountResolverTest::allVisiblePredicate);
    assertThat(result.asIdSet()).containsExactlyElementsIn(ids(1, 2));
}
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 5 with Searcher

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

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