UserPrincipalProvider implements PrincipalProvider { @NotNull @Override public Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final int searchType) { return findPrincipals(nameHint, false, searchType, 0, -1); } UserPrincipalProvider(@NotNull Root root,
                          @NotNull UserConfiguration userConfiguration,
                          @NotNull NamePathMapper namePathMapper); @Override Principal getPrincipal(@NotNull String principalName); @Nullable @Override ItemBasedPrincipal getItemBasedPrincipal(@NotNull String principalOakPath); @NotNull @Override Set<Principal> getMembershipPrincipals(@NotNull Principal principal); @NotNull @Override Set<? extends Principal> getPrincipals(@NotNull String userID); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final int searchType); @NotNull @Override Iterator<? extends Principal> findPrincipals(@Nullable final String nameHint, final boolean fullText, final int searchType, long offset,
            long limit); @NotNull @Override Iterator<? extends Principal> findPrincipals(int searchType);  }
@Test public void testFindFullTextWithAndWithoutWildcard() { Iterator<? extends Principal> i1 = principalProvider.findPrincipals("testGroup", true, SEARCH_TYPE_GROUP, 0, -1); Iterator<? extends Principal> i2 = principalProvider.findPrincipals("testGroup*", true, SEARCH_TYPE_GROUP, 0, -1); assertTrue(Iterators.elementsEqual(i1, i2)); }
@Test public void testFindFiltersDuplicateEveryone() throws Exception { Group everyoneGroup = null; try { UserManager userMgr = getUserManager(root); everyoneGroup = userMgr.createGroup(EveryonePrincipal.NAME); root.commit(); Iterator<? extends Principal> principals = principalProvider.findPrincipals(null, SEARCH_TYPE_GROUP); Iterator filtered = Iterators.filter(principals, (Predicate<Principal>) principal -> EveryonePrincipal.NAME.equals(principal.getName())); assertEquals(1, Iterators.size(filtered)); } finally { if (everyoneGroup != null) { everyoneGroup.remove(); root.commit(); } } List<String> expected = Arrays.asList(groupId, groupId2, groupId3); Collections.sort(expected); for (int limit = -1; limit < expected.size() + 2; limit++) { Iterator<? extends Principal> i1 = principalProvider.findPrincipals("testGroup", true, SEARCH_TYPE_GROUP, 0, limit); Iterator<? extends Principal> i2 = principalProvider.findPrincipals("testGroup*", true, SEARCH_TYPE_GROUP, 0, limit); assertTrue(Iterators.elementsEqual(i1, i2)); } }
@Test public void testFindPrincipalsQueryFails() throws ParseException { QueryEngine qe = mock(QueryEngine.class); when(qe.executeQuery(anyString(), anyString(), anyLong(), anyLong(), any(Map.class), any(Map.class))).thenThrow(new ParseException("err",0)); Root r = when(mock(Root.class).getQueryEngine()).thenReturn(qe).getMock(); UserPrincipalProvider upp = new UserPrincipalProvider(r, getUserConfiguration(), NamePathMapper.DEFAULT); Iterator<? extends Principal> it = upp.findPrincipals("a", false, PrincipalManager.SEARCH_TYPE_ALL, -1, -1); assertNotNull(it); assertFalse(it.hasNext()); }