Code example for SearchControls

Methods: setReturningAttributessetSearchScope

0
     */ 
    @Test
    public void testThrowOnReferralWithJndi() throws ExceptionLdapContext ctx = getWiredContextThrowOnRefferal( getLdapServer() );
        SearchControls controls = new SearchControls();
        controls.setReturningAttributes( new String[0] );
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        // comparison success 
        NamingEnumeration<SearchResult> answer = ctx.search( "uid=akarasulu,ou=users,ou=system", "(uid=akarasulu)",
            controls );
        assertTrue( answer.hasMore() );
        SearchResult result = answer.next();
        assertEquals( "", result.getName() );
        assertEquals( 0, result.getAttributes().size() );
        assertFalse( answer.hasMore() );
        answer.close();
 
        // referrals failure 
        try 
        { 
            answer = ctx.search( "uid=akarasuluref,ou=users,ou=system", "(uid=akarasuluref)", controls );
            fail( "Should never get here" ); 
        } 
        catch ( ReferralException e )
        { 
            // seems JNDI only returns the first referral URL and not all so we test for it