use of com.google.gerrit.server.account.AccountResolver.Result 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();
}
}
use of com.google.gerrit.server.account.AccountResolver.Result 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();
}
}
use of com.google.gerrit.server.account.AccountResolver.Result 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();
}
use of com.google.gerrit.server.account.AccountResolver.Result 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();
}
use of com.google.gerrit.server.account.AccountResolver.Result in project gerrit by GerritCodeReview.
the class AccountResolverTest method exceptionMessageNotFound.
@Test
public void exceptionMessageNotFound() throws Exception {
AccountResolver resolver = newAccountResolver();
assertThat(new UnresolvableAccountException(resolver.new Result("foo", ImmutableList.of(), ImmutableList.of()))).hasMessageThat().isEqualTo("Account 'foo' not found");
}
Aggregations