From commits-return-34526-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Sep 28 05:46:17 2012 Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id DD820D2A6 for ; Fri, 28 Sep 2012 05:46:17 +0000 (UTC) Received: (qmail 85667 invoked by uid 500); 28 Sep 2012 05:46:17 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 85494 invoked by uid 500); 28 Sep 2012 05:46:13 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 85453 invoked by uid 99); 28 Sep 2012 05:46:11 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Sep 2012 05:46:11 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 28 Sep 2012 05:46:03 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id CFB2A23888CD for ; Fri, 28 Sep 2012 05:45:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1391309 - /directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java Date: Fri, 28 Sep 2012 05:45:18 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120928054518.CFB2A23888CD@eris.apache.org> Author: elecharny Date: Fri Sep 28 05:45:18 2012 New Revision: 1391309 URL: http://svn.apache.org/viewvc?rev=1391309&view=rev Log: Removed the @Ignore test : it's now passing Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java Modified: directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java?rev=1391309&r1=1391308&r2=1391309&view=diff ============================================================================== --- directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java (original) +++ directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/search/PagedSearchIT.java Fri Sep 28 05:45:18 2012 @@ -210,976 +210,975 @@ import org.junit.runner.RunWith; }) public class PagedSearchIT extends AbstractLdapTestUnit { -@Rule -public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE ); - -private LdapApiService codec = LdapApiServiceFactory.getSingleton(); - - -/** - * Create the searchControls with a paged size - * @throws EncoderException on codec failures - */ -private SearchControls createSearchControls( DirContext ctx, int sizeLimit, int pagedSize ) - throws NamingException, EncoderException -{ - SearchControls controls = new SearchControls(); - controls.setCountLimit( sizeLimit ); - controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); - PagedResultsDecorator pagedSearchControl = new PagedResultsDecorator( codec ); - pagedSearchControl.setSize( pagedSize ); - - ( ( LdapContext ) ctx ).setRequestControls( JndiUtils.toJndiControls( codec, new Control[] - { pagedSearchControl } ) ); - - return controls; -} - - -/** - * Create the searchControls with a paged size - * @throws EncoderException on codec failures - */ -private void createNextSearchControls( DirContext ctx, byte[] cookie, int pagedSize ) - throws NamingException, EncoderException -{ - PagedResultsDecorator pagedSearchControl = new PagedResultsDecorator( codec ); - pagedSearchControl.setCookie( cookie ); - pagedSearchControl.setSize( pagedSize ); - ( ( LdapContext ) ctx ).setRequestControls( JndiUtils.toJndiControls( codec, new Control[] - { pagedSearchControl } ) ); -} - - -/** - * Check that we got the correct result set - */ -private void checkResults( List results, int expectedSize ) throws NamingException -{ - assertEquals( expectedSize, results.size() ); - Set expected = new HashSet(); - - for ( int i = 0; i < 10; i++ ) - { - expected.add( "user" + i ); - } - - // check that we have correctly read all the entries - for ( int i = 0; i < expectedSize; i++ ) - { - SearchResult entry = results.get( i ); - String user = ( String ) entry.getAttributes().get( "cn" ).get(); - assertTrue( expected.contains( user ) ); - - expected.remove( user ); - } - - assertEquals( 10 - expectedSize, expected.size() ); -} - - -/** - * Do the loop over the entries, until we can't get any more, or until we - * reach a limit. It will check that we have got all the expected entries. - * @throws EncoderException on codec failures - */ -private void doLoop( DirContext ctx, SearchControls controls, int pagedSizeLimit, - int expectedLoop, int expectedNbEntries, boolean expectedException ) throws NamingException, EncoderException -{ - // Loop over all the elements - int loop = 0; - boolean hasSizeLimitException = false; - List results = new ArrayList(); - - while ( true ) - { - loop++; - NamingEnumeration list = null; - - try - { - list = ctx.search( "dc=users,ou=system", "(cn=*)", controls ); - - while ( list.hasMore() ) + @Rule + public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( MultiThreadedMultiInvoker.NOT_THREADSAFE ); + + private LdapApiService codec = LdapApiServiceFactory.getSingleton(); + + + /** + * Create the searchControls with a paged size + * @throws EncoderException on codec failures + */ + private SearchControls createSearchControls( DirContext ctx, int sizeLimit, int pagedSize ) + throws NamingException, EncoderException + { + SearchControls controls = new SearchControls(); + controls.setCountLimit( sizeLimit ); + controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); + PagedResultsDecorator pagedSearchControl = new PagedResultsDecorator( codec ); + pagedSearchControl.setSize( pagedSize ); + + ( ( LdapContext ) ctx ).setRequestControls( JndiUtils.toJndiControls( codec, new Control[] + { pagedSearchControl } ) ); + + return controls; + } + + + /** + * Create the searchControls with a paged size + * @throws EncoderException on codec failures + */ + private void createNextSearchControls( DirContext ctx, byte[] cookie, int pagedSize ) + throws NamingException, EncoderException + { + PagedResultsDecorator pagedSearchControl = new PagedResultsDecorator( codec ); + pagedSearchControl.setCookie( cookie ); + pagedSearchControl.setSize( pagedSize ); + ( ( LdapContext ) ctx ).setRequestControls( JndiUtils.toJndiControls( codec, new Control[] + { pagedSearchControl } ) ); + } + + + /** + * Check that we got the correct result set + */ + private void checkResults( List results, int expectedSize ) throws NamingException + { + assertEquals( expectedSize, results.size() ); + Set expected = new HashSet(); + + for ( int i = 0; i < 10; i++ ) + { + expected.add( "user" + i ); + } + + // check that we have correctly read all the entries + for ( int i = 0; i < expectedSize; i++ ) + { + SearchResult entry = results.get( i ); + String user = ( String ) entry.getAttributes().get( "cn" ).get(); + assertTrue( expected.contains( user ) ); + + expected.remove( user ); + } + + assertEquals( 10 - expectedSize, expected.size() ); + } + + + /** + * Do the loop over the entries, until we can't get any more, or until we + * reach a limit. It will check that we have got all the expected entries. + * @throws EncoderException on codec failures + */ + private void doLoop( DirContext ctx, SearchControls controls, int pagedSizeLimit, + int expectedLoop, int expectedNbEntries, boolean expectedException ) throws NamingException, EncoderException + { + // Loop over all the elements + int loop = 0; + boolean hasSizeLimitException = false; + List results = new ArrayList(); + + while ( true ) + { + loop++; + NamingEnumeration list = null; + + try { - SearchResult result = list.next(); - results.add( result ); + list = ctx.search( "dc=users,ou=system", "(cn=*)", controls ); + + while ( list.hasMore() ) + { + SearchResult result = list.next(); + results.add( result ); + } } - } - catch ( SizeLimitExceededException e ) - { - hasSizeLimitException = true; - break; - } - finally - { - // Close the NamingEnumeration - if ( list != null ) + catch ( SizeLimitExceededException e ) + { + hasSizeLimitException = true; + break; + } + finally { - list.close(); + // Close the NamingEnumeration + if ( list != null ) + { + list.close(); + } } - } - - // Now read the next ones - javax.naming.ldap.Control[] responseControls = ( ( LdapContext ) ctx ).getResponseControls(); - - PagedResultsResponseControl responseControl = - ( PagedResultsResponseControl ) responseControls[0]; - assertEquals( 0, responseControl.getResultSize() ); - - // check if this is over - byte[] cookie = responseControl.getCookie(); - - if ( Strings.isEmpty( cookie ) ) - { - // If so, exit the loop - break; - } - - // Prepare the next iteration - createNextSearchControls( ctx, responseControl.getCookie(), pagedSizeLimit ); - } - - assertEquals( expectedException, hasSizeLimitException ); - assertEquals( expectedLoop, loop ); - checkResults( results, expectedNbEntries ); - - // And close the connection - closeConnection( ctx ); -} - - -/** - * Close a connection, and wait a bit to be sure it's done - */ -private void closeConnection( DirContext ctx ) throws NamingException -{ - if ( ctx != null ) + + // Now read the next ones + javax.naming.ldap.Control[] responseControls = ( ( LdapContext ) ctx ).getResponseControls(); + + PagedResultsResponseControl responseControl = + ( PagedResultsResponseControl ) responseControls[0]; + assertEquals( 0, responseControl.getResultSize() ); + + // check if this is over + byte[] cookie = responseControl.getCookie(); + + if ( Strings.isEmpty( cookie ) ) + { + // If so, exit the loop + break; + } + + // Prepare the next iteration + createNextSearchControls( ctx, responseControl.getCookie(), pagedSizeLimit ); + } + + assertEquals( expectedException, hasSizeLimitException ); + assertEquals( expectedLoop, loop ); + checkResults( results, expectedNbEntries ); + + // And close the connection + closeConnection( ctx ); + } + + + /** + * Close a connection, and wait a bit to be sure it's done + */ + private void closeConnection( DirContext ctx ) throws NamingException { - ctx.close(); - - try - { - Thread.sleep( 10 ); - } - catch ( Exception e ) + if ( ctx != null ) { + ctx.close(); + + try + { + Thread.sleep( 10 ); + } + catch ( Exception e ) + { + } } } -} - - -/** - * Admin = yes
- * SL = none
- * RL = none
- * PL = 3
- * expected exception : no
- * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
- */ -@Test -public void testPagedSearchtest1() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); - - doLoop( ctx, controls, 3, 4, 10, false ); -} - - -/** - * Admin = yes
- * SL = none
- * RL = none
- * PL = 5
- * expected exception : no
- * expected number of entries returned : 10 ( 5 + 5 )
- */ -@Test -public void testPagedSearchtest2() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 2, 10, false ); -} - - -/** - * Admin = yes
- * SL = 3
- * RL = none
- * PL = 5
- * expected exception : no
- * expected number of entries returned : 10 ( 5 + 5 )
- */ -@Test -public void testPagedSearchTest3() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 2, 10, false ); -} - - -/** - * Admin = yes
- * SL = none
- * RL = 3
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchTest4() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 3, 5 ); - - doLoop( ctx, controls, 5, 1, 3, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = none
- * PL = 3
- * expected exception : no
- * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
- */ -@Test -public void testPagedSearchtest5() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); - - doLoop( ctx, controls, 3, 4, 10, false ); -} - - -/** - * Admin = yes
- * SL = none
- * RL = 9
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 9 ( 5 + 4 )
- */ -@Test -public void testPagedSearchTest6() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 9, 5 ); - - doLoop( ctx, controls, 5, 2, 9, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = none
- * PL = 5
- * expected exception : no
- * expected number of entries returned : 10 ( 5 + 5 )
- */ -@Test -public void testPagedSearchtest7() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 2, 10, false ); -} - - -/** - * Admin = yes
- * SL = none
- * RL = 5
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 5
- */ -@Test -public void testPagedSearchTest8() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 5, 5 ); - - doLoop( ctx, controls, 5, 1, 5, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = 4
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 2 ( 3 + 1 )
- */ -@Test -public void testPagedSearchTest9() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 4, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = yes
- * SL = 4
- * RL = 5
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 5 ( 3 + 2 )
- */ -@Test -public void testPagedSearchtest10() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 5, 3 ); - - doLoop( ctx, controls, 3, 2, 5, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = 3
- * PL = 4
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest11() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 3, 4 ); - - doLoop( ctx, controls, 4, 1, 3, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = 4
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 4 ( 3 + 1 )
- */ -@Test -public void testPagedSearchtest12() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 4, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = yes
- * SL = 4
- * RL = 5
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 5 ( 3 + 2 )
- */ -@Test -public void testPagedSearchtest13() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 5, 3 ); - - doLoop( ctx, controls, 3, 2, 5, true ); -} - - -/** - * Admin = yes
- * SL = 4
- * RL = 3
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest14() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 3, 5 ); - - doLoop( ctx, controls, 5, 1, 3, true ); -} - - -/** - * Admin = yes
- * SL = 3
- * RL = 5
- * PL = 4
- * expected exception : yes
- * expected number of entries returned : 5 ( 4 + 1 )
- */ -@Test -public void testPagedSearchtest15() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 5, 4 ); - - doLoop( ctx, controls, 4, 2, 5, true ); -} - - -/** - * Admin = yes
- * SL = 3
- * RL = 4
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 4
- */ -@Test -public void testPagedSearchtest16() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 4, 5 ); - - doLoop( ctx, controls, 5, 1, 4, true ); -} - - -/** - * Admin = yes
- * SL = 5
- * RL = 5
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 5
- */ -@Test -public void testPagedSearchtest17() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer() ); - SearchControls controls = createSearchControls( ctx, 5, 5 ); - - doLoop( ctx, controls, 5, 1, 5, true ); -} - - -/** - * Admin = no
- * SL = none
- * RL = none
- * PL = 3
- * expected exception : no
- * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
- */ -@Test -public void testPagedSearchtest18() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); - - doLoop( ctx, controls, 3, 4, 10, false ); -} - - -/** - * Admin = no
- * SL = none
- * RL = none
- * PL = 5
- * expected exception : no
- * expected number of entries returned : 10 ( 5 + 5 )
- */ -@Test -public void testPagedSearchtest19() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 2, 10, false ); -} - - -/** - * Admin = no
- * SL = 3
- * RL = none
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchTest20() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = none
- * RL = 3
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchTest21() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 3, 5 ); - - doLoop( ctx, controls, 5, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = none
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 5 ( 3 + 2 )
- */ -@Test -public void testPagedSearchtest22() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); - - doLoop( ctx, controls, 3, 2, 5, true ); -} - - -/** - * Admin = no
- * SL = none
- * RL = 9
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 9 ( 5 + 4 )
- */ -@Test -public void testPagedSearchTest23() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 9, 5 ); - - doLoop( ctx, controls, 5, 2, 9, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = none
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 5
- */ -@Test -public void testPagedSearchtest24() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); - - doLoop( ctx, controls, 5, 1, 5, true ); -} - - -/** - * Admin = no
- * SL = none
- * RL = 5
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 5
- */ -@Test -public void testPagedSearchTest25() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 5, 5 ); - - doLoop( ctx, controls, 5, 1, 5, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = 4
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 2 ( 3 + 1 )
- */ -@Test -public void testPagedSearchTest26() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 4, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = no
- * SL = 4
- * RL = 5
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 4 ( 3 + 1 )
- */ -@Test -public void testPagedSearchtest27() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 5, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = 3
- * PL = 4
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest28() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 3, 4 ); - - doLoop( ctx, controls, 4, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = 4
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 4 ( 3 + 1 )
- */ -@Test -public void testPagedSearchtest29() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 4, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = no
- * SL = 4
- * RL = 5
- * PL = 3
- * expected exception : yes
- * expected number of entries returned : 4 ( 3 + 1 )
- */ -@Test -public void testPagedSearchtest30() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 5, 3 ); - - doLoop( ctx, controls, 3, 2, 4, true ); -} - - -/** - * Admin = no
- * SL = 4
- * RL = 3
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest31() throws Exception -{ - getLdapServer().setMaxSizeLimit( 4 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 3, 5 ); - - doLoop( ctx, controls, 3, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = 3
- * RL = 5
- * PL = 4
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest32() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 5, 4 ); - - doLoop( ctx, controls, 3, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = 3
- * RL = 4
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 3
- */ -@Test -public void testPagedSearchtest33() throws Exception -{ - getLdapServer().setMaxSizeLimit( 3 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 4, 5 ); - - doLoop( ctx, controls, 3, 1, 3, true ); -} - - -/** - * Admin = no
- * SL = 5
- * RL = 5
- * PL = 5
- * expected exception : yes
- * expected number of entries returned : 5
- */ -@Test -public void testPagedSearchtest34() throws Exception -{ - getLdapServer().setMaxSizeLimit( 5 ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, 5, 5 ); - - doLoop( ctx, controls, 5, 1, 5, true ); -} - - -/** - * Admin = no
- * SL = none
- * RL = none
- * PL = -2
- * expected exception : no
- * expected number of entries returned : 10
- */ -@Test -public void testPagedSearchWithNegativePL() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, -2 ); - - doLoop( ctx, controls, -2, 1, 10, false ); -} - - -/** - * Do a test with a paged search and send a wrong cookie in the middle - */ -@Ignore -@Test -public void testPagedSearchWrongCookie() throws Exception -{ - LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() ); - connection.bind( "uid=admin,ou=system", "secret" ); - - SearchControls controls = new SearchControls(); - controls.setCountLimit( ( int ) LdapServer.NO_SIZE_LIMIT ); - controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); - PagedResults pagedSearchControl = new PagedResultsDecorator( codec ); - pagedSearchControl.setSize( 3 ); - - // Loop over all the elements - int loop = 0; - List results = new ArrayList(); - boolean hasUnwillingToPerform = false; - - while ( true ) - { - loop++; - - EntryCursor cursor = null; - - try - { - SearchRequest searchRequest = new SearchRequestImpl(); - searchRequest.setBase( new Dn( "ou=system" ) ); - searchRequest.setFilter( "(ObjectClass=*)" ); - searchRequest.setScope( SearchScope.SUBTREE ); - searchRequest.addAttributes( "*" ); - searchRequest.addControl( pagedSearchControl ); - - cursor = new EntryCursorImpl( connection.search( searchRequest ) ); - - int i = 0; - - while ( cursor.next() ) + + + /** + * Admin = yes
+ * SL = none
+ * RL = none
+ * PL = 3
+ * expected exception : no
+ * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
+ */ + @Test + public void testPagedSearchtest1() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); + + doLoop( ctx, controls, 3, 4, 10, false ); + } + + + /** + * Admin = yes
+ * SL = none
+ * RL = none
+ * PL = 5
+ * expected exception : no
+ * expected number of entries returned : 10 ( 5 + 5 )
+ */ + @Test + public void testPagedSearchtest2() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 2, 10, false ); + } + + + /** + * Admin = yes
+ * SL = 3
+ * RL = none
+ * PL = 5
+ * expected exception : no
+ * expected number of entries returned : 10 ( 5 + 5 )
+ */ + @Test + public void testPagedSearchTest3() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 2, 10, false ); + } + + + /** + * Admin = yes
+ * SL = none
+ * RL = 3
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchTest4() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 3, 5 ); + + doLoop( ctx, controls, 5, 1, 3, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = none
+ * PL = 3
+ * expected exception : no
+ * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
+ */ + @Test + public void testPagedSearchtest5() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); + + doLoop( ctx, controls, 3, 4, 10, false ); + } + + + /** + * Admin = yes
+ * SL = none
+ * RL = 9
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 9 ( 5 + 4 )
+ */ + @Test + public void testPagedSearchTest6() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 9, 5 ); + + doLoop( ctx, controls, 5, 2, 9, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = none
+ * PL = 5
+ * expected exception : no
+ * expected number of entries returned : 10 ( 5 + 5 )
+ */ + @Test + public void testPagedSearchtest7() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 2, 10, false ); + } + + + /** + * Admin = yes
+ * SL = none
+ * RL = 5
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 5
+ */ + @Test + public void testPagedSearchTest8() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 5, 5 ); + + doLoop( ctx, controls, 5, 1, 5, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = 4
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 2 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchTest9() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 4, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = yes
+ * SL = 4
+ * RL = 5
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 5 ( 3 + 2 )
+ */ + @Test + public void testPagedSearchtest10() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 5, 3 ); + + doLoop( ctx, controls, 3, 2, 5, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = 3
+ * PL = 4
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest11() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 3, 4 ); + + doLoop( ctx, controls, 4, 1, 3, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = 4
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 4 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchtest12() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 4, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = yes
+ * SL = 4
+ * RL = 5
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 5 ( 3 + 2 )
+ */ + @Test + public void testPagedSearchtest13() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 5, 3 ); + + doLoop( ctx, controls, 3, 2, 5, true ); + } + + + /** + * Admin = yes
+ * SL = 4
+ * RL = 3
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest14() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 3, 5 ); + + doLoop( ctx, controls, 5, 1, 3, true ); + } + + + /** + * Admin = yes
+ * SL = 3
+ * RL = 5
+ * PL = 4
+ * expected exception : yes
+ * expected number of entries returned : 5 ( 4 + 1 )
+ */ + @Test + public void testPagedSearchtest15() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 5, 4 ); + + doLoop( ctx, controls, 4, 2, 5, true ); + } + + + /** + * Admin = yes
+ * SL = 3
+ * RL = 4
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 4
+ */ + @Test + public void testPagedSearchtest16() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 4, 5 ); + + doLoop( ctx, controls, 5, 1, 4, true ); + } + + + /** + * Admin = yes
+ * SL = 5
+ * RL = 5
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 5
+ */ + @Test + public void testPagedSearchtest17() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer() ); + SearchControls controls = createSearchControls( ctx, 5, 5 ); + + doLoop( ctx, controls, 5, 1, 5, true ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = none
+ * PL = 3
+ * expected exception : no
+ * expected number of entries returned : 10 ( 3 + 3 + 3 + 1 )
+ */ + @Test + public void testPagedSearchtest18() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); + + doLoop( ctx, controls, 3, 4, 10, false ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = none
+ * PL = 5
+ * expected exception : no
+ * expected number of entries returned : 10 ( 5 + 5 )
+ */ + @Test + public void testPagedSearchtest19() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 2, 10, false ); + } + + + /** + * Admin = no
+ * SL = 3
+ * RL = none
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchTest20() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = 3
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchTest21() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 3, 5 ); + + doLoop( ctx, controls, 5, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = none
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 5 ( 3 + 2 )
+ */ + @Test + public void testPagedSearchtest22() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 3 ); + + doLoop( ctx, controls, 3, 2, 5, true ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = 9
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 9 ( 5 + 4 )
+ */ + @Test + public void testPagedSearchTest23() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 9, 5 ); + + doLoop( ctx, controls, 5, 2, 9, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = none
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 5
+ */ + @Test + public void testPagedSearchtest24() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 5 ); + + doLoop( ctx, controls, 5, 1, 5, true ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = 5
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 5
+ */ + @Test + public void testPagedSearchTest25() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 5, 5 ); + + doLoop( ctx, controls, 5, 1, 5, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = 4
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 2 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchTest26() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 4, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = no
+ * SL = 4
+ * RL = 5
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 4 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchtest27() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 5, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = 3
+ * PL = 4
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest28() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 3, 4 ); + + doLoop( ctx, controls, 4, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = 4
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 4 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchtest29() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 4, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = no
+ * SL = 4
+ * RL = 5
+ * PL = 3
+ * expected exception : yes
+ * expected number of entries returned : 4 ( 3 + 1 )
+ */ + @Test + public void testPagedSearchtest30() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 5, 3 ); + + doLoop( ctx, controls, 3, 2, 4, true ); + } + + + /** + * Admin = no
+ * SL = 4
+ * RL = 3
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest31() throws Exception + { + getLdapServer().setMaxSizeLimit( 4 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 3, 5 ); + + doLoop( ctx, controls, 3, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = 3
+ * RL = 5
+ * PL = 4
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest32() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 5, 4 ); + + doLoop( ctx, controls, 3, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = 3
+ * RL = 4
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 3
+ */ + @Test + public void testPagedSearchtest33() throws Exception + { + getLdapServer().setMaxSizeLimit( 3 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 4, 5 ); + + doLoop( ctx, controls, 3, 1, 3, true ); + } + + + /** + * Admin = no
+ * SL = 5
+ * RL = 5
+ * PL = 5
+ * expected exception : yes
+ * expected number of entries returned : 5
+ */ + @Test + public void testPagedSearchtest34() throws Exception + { + getLdapServer().setMaxSizeLimit( 5 ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, 5, 5 ); + + doLoop( ctx, controls, 5, 1, 5, true ); + } + + + /** + * Admin = no
+ * SL = none
+ * RL = none
+ * PL = -2
+ * expected exception : no
+ * expected number of entries returned : 10
+ */ + @Test + public void testPagedSearchWithNegativePL() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, -2 ); + + doLoop( ctx, controls, -2, 1, 10, false ); + } + + + /** + * Do a test with a paged search and send a wrong cookie in the middle + */ + @Test + public void testPagedSearchWrongCookie() throws Exception + { + LdapNetworkConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() ); + connection.bind( "uid=admin,ou=system", "secret" ); + + SearchControls controls = new SearchControls(); + controls.setCountLimit( ( int ) LdapServer.NO_SIZE_LIMIT ); + controls.setSearchScope( SearchControls.SUBTREE_SCOPE ); + PagedResults pagedSearchControl = new PagedResultsDecorator( codec ); + pagedSearchControl.setSize( 3 ); + + // Loop over all the elements + int loop = 0; + List results = new ArrayList(); + boolean hasUnwillingToPerform = false; + + while ( true ) + { + loop++; + + EntryCursor cursor = null; + + try { - Entry result = cursor.get(); - results.add( result ); - ++i; + SearchRequest searchRequest = new SearchRequestImpl(); + searchRequest.setBase( new Dn( "ou=system" ) ); + searchRequest.setFilter( "(ObjectClass=*)" ); + searchRequest.setScope( SearchScope.SUBTREE ); + searchRequest.addAttributes( "*" ); + searchRequest.addControl( pagedSearchControl ); + + cursor = new EntryCursorImpl( connection.search( searchRequest ) ); + + int i = 0; + + while ( cursor.next() ) + { + Entry result = cursor.get(); + results.add( result ); + ++i; + } + + SearchResultDone result = cursor.getSearchResultDone(); + pagedSearchControl = ( PagedResults ) result.getControl( PagedResults.OID ); + + if ( result.getLdapResult().getResultCode() == ResultCodeEnum.UNWILLING_TO_PERFORM ) + { + hasUnwillingToPerform = true; + break; + } } - - SearchResultDone result = cursor.getSearchResultDone(); - pagedSearchControl = ( PagedResults ) result.getControl( PagedResults.OID ); - - if ( result.getLdapResult().getResultCode() == ResultCodeEnum.UNWILLING_TO_PERFORM ) + finally { - hasUnwillingToPerform = true; + if ( cursor != null ) + { + cursor.close(); + } + } + + // Now read the next ones + assertEquals( 0, pagedSearchControl.getSize() ); + + // check if this is over + byte[] cookie = pagedSearchControl.getCookie(); + + if ( Strings.isEmpty( cookie ) ) + { + // If so, exit the loop break; } - } - finally - { - if ( cursor != null ) + + // Prepare the next iteration, sending a bad cookie + pagedSearchControl.setCookie( "test".getBytes( "UTF-8" ) ); + pagedSearchControl.setSize( 3 ); + } + + assertTrue( hasUnwillingToPerform ); + + // Cleanup the session + connection.unBind(); + connection.close(); + } + + + /** + * Do a test with a paged search, changing the number of entries to + * return in the middle of the loop + */ + @Test + public void testPagedSearchModifyingPagedLimit() throws Exception + { + getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); + DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); + SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 4 ); + + // Loop over all the elements + int loop = 0; + List results = new ArrayList(); + + // The expected size after each loop. + int[] expectedSize = new int[] + { 4, 7, 9, 10 }; + + while ( true ) + { + loop++; + + NamingEnumeration list = + ctx.search( "dc=users,ou=system", "(cn=*)", controls ); + + while ( list.hasMore() ) { - cursor.close(); + SearchResult result = list.next(); + results.add( result ); } - } - - // Now read the next ones - assertEquals( 0, pagedSearchControl.getSize() ); - - // check if this is over - byte[] cookie = pagedSearchControl.getCookie(); - - if ( Strings.isEmpty( cookie ) ) - { - // If so, exit the loop - break; - } - - // Prepare the next iteration, sending a bad cookie - pagedSearchControl.setCookie( "test".getBytes( "UTF-8" ) ); - pagedSearchControl.setSize( 3 ); + + list.close(); + + // Now read the next ones + javax.naming.ldap.Control[] responseControls = ( ( LdapContext ) ctx ).getResponseControls(); + + PagedResultsResponseControl responseControl = + ( PagedResultsResponseControl ) responseControls[0]; + assertEquals( 0, responseControl.getResultSize() ); + + // check if this is over + byte[] cookie = responseControl.getCookie(); + + if ( Strings.isEmpty( cookie ) ) + { + // If so, exit the loop + break; + } + + // Prepare the next iteration, sending a bad cookie + createNextSearchControls( ctx, responseControl.getCookie(), 4 - loop ); + + assertEquals( expectedSize[loop - 1], results.size() ); + } + + assertEquals( 4, loop ); + checkResults( results, 10 ); } - - assertTrue( hasUnwillingToPerform ); - - // Cleanup the session - connection.unBind(); - connection.close(); -} - - -/** - * Do a test with a paged search, changing the number of entries to - * return in the middle of the loop - */ -@Test -public void testPagedSearchModifyingPagedLimit() throws Exception -{ - getLdapServer().setMaxSizeLimit( LdapServer.NO_SIZE_LIMIT ); - DirContext ctx = getWiredContext( getLdapServer(), "cn=user,ou=system", "secret" ); - SearchControls controls = createSearchControls( ctx, ( int ) LdapServer.NO_SIZE_LIMIT, 4 ); - - // Loop over all the elements - int loop = 0; - List results = new ArrayList(); - - // The expected size after each loop. - int[] expectedSize = new int[] - { 4, 7, 9, 10 }; - - while ( true ) - { - loop++; - - NamingEnumeration list = - ctx.search( "dc=users,ou=system", "(cn=*)", controls ); - - while ( list.hasMore() ) - { - SearchResult result = list.next(); - results.add( result ); - } - - list.close(); - - // Now read the next ones - javax.naming.ldap.Control[] responseControls = ( ( LdapContext ) ctx ).getResponseControls(); - - PagedResultsResponseControl responseControl = - ( PagedResultsResponseControl ) responseControls[0]; - assertEquals( 0, responseControl.getResultSize() ); - - // check if this is over - byte[] cookie = responseControl.getCookie(); - - if ( Strings.isEmpty( cookie ) ) - { - // If so, exit the loop - break; - } - - // Prepare the next iteration, sending a bad cookie - createNextSearchControls( ctx, responseControl.getCookie(), 4 - loop ); - - assertEquals( expectedSize[loop - 1], results.size() ); - } - - assertEquals( 4, loop ); - checkResults( results, 10 ); -} } \ No newline at end of file