PrincipalManagerImpl implements PrincipalQueryManager, PrincipalManager { @Override @NotNull public PrincipalIterator findPrincipals(@Nullable String simpleFilter) { return findPrincipals(simpleFilter, PrincipalManager.SEARCH_TYPE_ALL); } PrincipalManagerImpl(@NotNull PrincipalProvider principalProvider); @Override boolean hasPrincipal(@NotNull String principalName); @Override @Nullable Principal getPrincipal(@NotNull String principalName); @Override @NotNull PrincipalIterator findPrincipals(@Nullable String simpleFilter); @Override @NotNull PrincipalIterator findPrincipals(@Nullable String simpleFilter, int searchType); @Override @NotNull PrincipalIterator getPrincipals(int searchType); @Override @NotNull PrincipalIterator getGroupMembership(@NotNull Principal principal); @Override @NotNull Principal getEveryone(); @NotNull @Override PrincipalIterator findPrincipals(@Nullable String simpleFilter, boolean fullText, int searchType, long offset, long limit);  }
@Test public void testFindPrincipal() { for (Principal pcpl : testPrincipals) { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName()); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } }
@Test public void testFindPrincipalByTypeGroup() { for (Principal pcpl : testPrincipals) { if (isGroup(pcpl)) { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_GROUP); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } else { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_NOT_GROUP); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } } }
@Test public void testFindPrincipalByType() { for (Principal pcpl : testPrincipals) { if (isGroup(pcpl)) { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_GROUP); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } else { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_NOT_GROUP); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } } }
@Test public void testFindPrincipalByTypeAll() { for (Principal pcpl : testPrincipals) { PrincipalIterator it = principalMgr.findPrincipals(pcpl.getName(), PrincipalManager.SEARCH_TYPE_ALL); assertTrue("findPrincipals does not find principal with filter '" + pcpl.getName() + '\'', Iterators.contains(it, pcpl)); } }
@Test public void testFindEveryone() { PrincipalIterator it = principalMgr.findPrincipals(EveryonePrincipal.NAME); assertTrue("findPrincipals does not find principal with filter '" + EveryonePrincipal.NAME + '\'', Iterators.contains(it, EveryonePrincipal.getInstance())); }
@Test public void testFindEveryoneTypeGroup() { PrincipalIterator it = principalMgr.findPrincipals(EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_GROUP); assertTrue("findPrincipals does not find principal with filter '" + EveryonePrincipal.NAME + '\'', Iterators.contains(it, EveryonePrincipal.getInstance())); }
@Test public void testFindEveryoneTypeNonGroup() { PrincipalIterator it = principalMgr.findPrincipals(EveryonePrincipal.NAME, PrincipalManager.SEARCH_TYPE_NOT_GROUP); assertFalse("findPrincipals did find principal with filter '" + EveryonePrincipal.NAME + '\'', Iterators.contains(it, EveryonePrincipal.getInstance())); }
@Test public void testFindUnknownByTypeAll() { String unknownHint = TestPrincipalProvider.UNKNOWN.getName().substring(0, 4); assertFalse(principalMgr.findPrincipals(unknownHint, PrincipalManager.SEARCH_TYPE_ALL).hasNext()); }
@Test public void testFindUnknownByTypeGroup() { String unknownHint = TestPrincipalProvider.UNKNOWN.getName().substring(0, 4); assertFalse(principalMgr.findPrincipals(unknownHint, PrincipalManager.SEARCH_TYPE_GROUP).hasNext()); }
@Test public void testFindUnknownByTypeNotGroup() { String unknownHint = TestPrincipalProvider.UNKNOWN.getName().substring(0, 4); assertFalse(principalMgr.findPrincipals(unknownHint, PrincipalManager.SEARCH_TYPE_NOT_GROUP).hasNext()); }
@Test public void testFindPrincipalsWithOffsetLimit() { PrincipalProvider pp = when(mock(PrincipalProvider.class).findPrincipals(any(), anyBoolean(), anyInt(), anyInt(), anyInt())).thenReturn(Collections.emptyIterator()).getMock(); PrincipalQueryManager pm = new PrincipalManagerImpl(pp); PrincipalIterator it = pm.findPrincipals("filter", true, PrincipalManager.SEARCH_TYPE_ALL, 5, 2); assertTrue(it instanceof PrincipalIteratorAdapter); verify(pp, times(1)).findPrincipals("filter", true, PrincipalManager.SEARCH_TYPE_ALL, 5, 2); }