directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1484631 - /directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
Date Tue, 21 May 2013 01:01:02 GMT
Author: elecharny
Date: Tue May 21 01:01:02 2013
New Revision: 1484631

URL: http://svn.apache.org/r1484631
Log:
Made the test working by correctly trying to read all the results.

Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java?rev=1484631&r1=1484630&r2=1484631&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
(original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/ClientSearchRequestTest.java
Tue May 21 01:01:02 2013
@@ -22,6 +22,7 @@ package org.apache.directory.shared.clie
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 
@@ -90,297 +91,303 @@ import org.junit.runner.RunWith;
 })
 public class ClientSearchRequestTest extends AbstractLdapTestUnit
 {
-    private LdapNetworkConnection connection;
-    
-    
-    @Before
-    public void setup() throws Exception
-    {
-        connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
-    }
-    
-    
-    @After
-    public void shutdown() throws Exception
+private LdapNetworkConnection connection;
+
+
+@Before
+public void setup() throws Exception
+{
+    connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection(
getLdapServer() );
+}
+
+
+@After
+public void shutdown() throws Exception
+{
+    LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer() );
+}
+
+
+@Test
+public void testSimpleSearch() throws Exception
+{
+    EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
+    int count = 0;
+
+    while ( cursor.next() )
     {
-        LdapApiIntegrationUtils.releasePooledAdminConnection( connection, getLdapServer()
);
+        Entry entry = cursor.get();
+        assertNotNull( entry );
+        count++;
     }
-    
-    
-    @Test
-    public void testSimpleSearch() throws Exception
+
+    SearchResultDone done = cursor.getSearchResultDone();
+
+    assertNotNull( done );
+    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+    assertEquals( 5, count );
+    cursor.close();
+}
+
+
+@Test
+public void testSimpleSearchWithControl() throws Exception
+{
+    SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn( "ou=system" )
)
+        .setFilter( "(objectclass=*)" )
+        .setScope( SearchScope.ONELEVEL ).addControl( new ManageDsaITImpl() );
+    SearchCursor cursor = connection.search( searchRequest );
+    int count = 0;
+
+    while ( cursor.next() )
     {
-        EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL
);
-        int count = 0;
-    
-        while ( cursor.next() )
+        Response response = cursor.get();
+        assertNotNull( response );
+
+        if ( response instanceof SearchResultEntry )
         {
-            Entry entry = cursor.get();
+            Entry entry = ( ( SearchResultEntry ) response ).getEntry();
             assertNotNull( entry );
-            count++;
         }
-    
-        SearchResultDone done = cursor.getSearchResultDone();
-    
-        assertNotNull( done );
-        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-        assertEquals( 5, count );
-        cursor.close();
+
+        count++;
     }
-    
-    
-    @Test
-    public void testSimpleSearchWithControl() throws Exception
+
+    SearchResultDone done = cursor.getSearchResultDone();
+
+    assertNotNull( done );
+    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+    assertEquals( 5, count );
+    cursor.close();
+}
+
+
+@Test
+public void testSearch() throws Exception
+{
+    EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)",
+        SearchScope.ONELEVEL,
+        "*", "+" );
+    int count = 0;
+
+    while ( cursor.next() )
     {
-        SearchRequest searchRequest = new SearchRequestImpl().setBase( new Dn( "ou=system"
) )
-            .setFilter( "(objectclass=*)" )
-            .setScope( SearchScope.ONELEVEL ).addControl( new ManageDsaITImpl() );
-        SearchCursor cursor = connection.search( searchRequest );
-        int count = 0;
-    
-        while ( cursor.next() )
-        {
-            Response response = cursor.get();
-            assertNotNull( response );
-    
-            if ( response instanceof SearchResultEntry )
-            {
-                Entry entry = ( ( SearchResultEntry ) response ).getEntry();
-                assertNotNull( entry );
-            }
-    
-            count++;
-        }
-    
-        SearchResultDone done = cursor.getSearchResultDone();
-    
-        assertNotNull( done );
-        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-        assertEquals( 5, count );
-        cursor.close();
+        assertNotNull( cursor.get() );
+        count++;
     }
-    
-    
-    @Test
-    public void testSearch() throws Exception
+
+    SearchResultDone done = cursor.getSearchResultDone();
+
+    assertNotNull( done );
+    assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
+    assertEquals( 5, count );
+    cursor.close();
+}
+
+
+@Test
+public void testSearchEquality() throws Exception
+{
+    EntryCursor cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
+        SearchScope.ONELEVEL, "*", "+" );
+    int count = 0;
+
+    while ( cursor.next() )
     {
-        EntryCursor cursor = connection.search( "ou=system", "(objectclass=*)",
-            SearchScope.ONELEVEL,
-            "*", "+" );
-        int count = 0;
-    
-        while ( cursor.next() )
+        Entry entry = cursor.get();
+        assertNotNull( entry );
+        count++;
+    }
+
+    assertEquals( 4, count );
+    cursor.close();
+}
+
+
+@Test
+public void testAsyncSearch() throws Exception
+{
+    SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL,
"*",
+        "+" );
+    int count = 0;
+    Response searchResponse = null;
+
+    do
+    {
+        searchResponse = searchFuture.get( 1000, TimeUnit.MILLISECONDS );
+        assertNotNull( searchResponse );
+        if ( !( searchResponse instanceof SearchResultDone ) )
         {
-            assertNotNull( cursor.get() );
             count++;
         }
-    
-        SearchResultDone done = cursor.getSearchResultDone();
-    
-        assertNotNull( done );
-        assertEquals( ResultCodeEnum.SUCCESS, done.getLdapResult().getResultCode() );
-        assertEquals( 5, count );
-        cursor.close();
     }
-    
-    
-    @Test
-    public void testSearchEquality() throws Exception
+    while ( !( searchResponse instanceof SearchResultDone ) );
+
+    assertEquals( 5, count );
+}
+
+
+/**
+ * Test a search with a Substring filter
+ * @throws Exception
+ */
+@Test
+public void testSearchPersonSubstring() throws Exception
+{
+    SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*ers*)",
SearchScope.SUBTREE,
+        "*", "+" );
+    int count = 0;
+    Response searchResponse = null;
+
+    do
     {
-        EntryCursor cursor = connection.search( "ou=system", "(objectclass=organizationalUnit)",
-            SearchScope.ONELEVEL, "*", "+" );
-        int count = 0;
-    
-        while ( cursor.next() )
+        searchResponse = searchFuture.get( 100000, TimeUnit.MILLISECONDS );
+        assertNotNull( searchResponse );
+
+        if ( !( searchResponse instanceof SearchResultDone ) )
         {
-            Entry entry = cursor.get();
-            assertNotNull( entry );
             count++;
         }
-    
-        assertEquals( 4, count );
-        cursor.close();
     }
-    
-    
-    @Test
-    public void testAsyncSearch() throws Exception
+    while ( !( searchResponse instanceof SearchResultDone ) );
+
+    assertEquals( 3, count );
+}
+
+
+@Test
+public void testSearchWithDerefAlias() throws Exception
+{
+    SearchRequest searchRequest = new SearchRequestImpl();
+    searchRequest.setBase( new Dn( "ou=users,ou=system" ) );
+    searchRequest.setFilter( "(objectClass=*)" );
+    searchRequest.setScope( SearchScope.ONELEVEL );
+    searchRequest.addAttributes( "*" );
+
+    int count = 0;
+    Cursor<Response> cursor = connection.search( searchRequest );
+
+    while ( cursor.next() )
     {
-        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)",
SearchScope.ONELEVEL, "*",
-            "+" );
-        int count = 0;
-        Response searchResponse = null;
-    
-        do
-        {
-            searchResponse = searchFuture.get( 1000, TimeUnit.MILLISECONDS );
-            assertNotNull( searchResponse );
-            if ( !( searchResponse instanceof SearchResultDone ) )
-            {
-                count++;
-            }
-        }
-        while ( !( searchResponse instanceof SearchResultDone ) );
-    
-        assertEquals( 5, count );
+        count++;
     }
-    
-    
-    /**
-     * Test a search with a Substring filter
-     * @throws Exception
-     */
-    @Test
-    public void testSearchPersonSubstring() throws Exception
+    cursor.close();
+
+    // due to dereferencing of aliases we get only one entry
+    assertEquals( 2, count );
+
+    count = 0;
+    searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
+    cursor = connection.search( searchRequest );
+
+    while ( cursor.next() )
     {
-        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*ers*)",
SearchScope.SUBTREE,
-            "*", "+" );
-        int count = 0;
-        Response searchResponse = null;
-    
-        do
-        {
-            searchResponse = searchFuture.get( 100000, TimeUnit.MILLISECONDS );
-            assertNotNull( searchResponse );
-    
-            if ( !( searchResponse instanceof SearchResultDone ) )
-            {
-                count++;
-            }
-        }
-        while ( !( searchResponse instanceof SearchResultDone ) );
-    
-        assertEquals( 3, count );
+        count++;
     }
-    
-    
-    @Test
-    public void testSearchWithDerefAlias() throws Exception
+    cursor.close();
+
+    assertEquals( 3, count );
+}
+
+
+@Test
+public void testSearchUTF8() throws Exception
+{
+    EntryCursor cursor = connection.search( "ou=users,ou=system", "(sn=Emmanuel L\u00E9charny)",
SearchScope.ONELEVEL,
+        "*", "+" );
+
+    assertTrue( cursor.next() );
+
+    Entry entry = cursor.get();
+    assertNotNull( entry );
+    assertTrue( entry.contains( "cn", "elecharny" ) );
+    assertTrue( entry.contains( "sn", "Emmanuel L\u00E9charny" ) );
+
+    cursor.close();
+}
+
+
+@Test
+public void testSearchBinary() throws Exception
+{
+    connection.loadSchema();
+    EntryCursor cursor = connection
+        .search(
+            "ou=system",
+            "(publicKey=\\30\\5C\\30\\0D\\06\\09\\2A\\86\\48\\86\\F7\\0D\\01\\01\\01\\05\\00\\03\\4B\\00\\30\\48\\02\\41\\00\\A6\\C7\\9C\\B1\\6C\\E4\\DD\\8F\\1E\\4D\\20\\93\\22\\3F\\83\\75\\DE\\21\\D8\\F1\\9D\\63\\80\\5B\\94\\55\\6A\\9E\\33\\59\\9B\\8D\\63\\88\\0D\\18\\7D\\4C\\85\\F1\\CF\\54\\77\\32\\E9\\61\\0C\\A2\\8F\\B3\\6B\\15\\34\\5E\\1F\\88\\BF\\A0\\73\\AC\\86\\BB\\D0\\85\\02\\03\\01\\00\\01)",
+            SearchScope.SUBTREE, "publicKey" );
+
+    assertTrue( cursor.next() );
+
+    Entry entry = cursor.get();
+    assertNotNull( entry.get( "publicKey" ) );
+
+    cursor.close();
+}
+
+
+@Test
+public void testSubDn() throws Exception
+{
+    connection.loadSchema();
+    EntryCursor cursor = connection.search( "ou=system", "(cn=user1)", SearchScope.SUBTREE,
"publicKey" );
+
+    assertTrue( cursor.next() );
+
+    Entry entry = cursor.get();
+    assertEquals( "cn=user1,ou=users,ou=system", entry.getDn().getName() );
+
+    cursor.close();
+
+    SearchRequest req = new SearchRequestImpl();
+    req.setScope( SearchScope.SUBTREE );
+    req.addAttributes( "*" );
+    req.setTimeLimit( 0 );
+    req.setBase( new Dn( "ou=system" ) );
+    req.setFilter( "(cn=user1)" );
+
+    SearchCursor searchCursor = connection.search( req );
+
+    assertTrue( searchCursor.next() );
+
+    Response response = searchCursor.get();
+
+    Entry resultEntry = ( ( SearchResultEntry ) response ).getEntry();
+    assertEquals( "cn=user1,ou=users,ou=system", resultEntry.getDn().getName() );
+
+    searchCursor.close();
+}
+
+
+/**
+ * Test to demonstrate https://issues.apache.org/jira/browse/DIRAPI-140
+ * Fixed to demonstrate that it works, if we loop until we don't have anymore results
+ */
+@Test
+public void test_DIRAPI140() throws Exception
+{
+    for ( int i = 0; i < 1000; i++ )
     {
-        SearchRequest searchRequest = new SearchRequestImpl();
-        searchRequest.setBase( new Dn( "ou=users,ou=system" ) );
-        searchRequest.setFilter( "(objectClass=*)" );
-        searchRequest.setScope( SearchScope.ONELEVEL );
-        searchRequest.addAttributes( "*" );
-    
-        int count = 0;
-        Cursor<Response> cursor = connection.search( searchRequest );
-    
-        while ( cursor.next() )
+        if ( i % 100 == 0 )
         {
-            count++;
-        }
-        cursor.close();
-    
-        // due to dereferencing of aliases we get only one entry
-        assertEquals( 2, count );
-    
-        count = 0;
-        searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
-        cursor = connection.search( searchRequest );
-    
-        while ( cursor.next() )
-        {
-            count++;
+            System.out.println( "Loop " + i );
         }
-        cursor.close();
-    
-        assertEquals( 3, count );
-    }
-    
-    
-    @Test
-    public void testSearchUTF8() throws Exception
-    {
-        EntryCursor cursor = connection.search( "ou=users,ou=system", "(sn=Emmanuel L\u00E9charny)",
SearchScope.ONELEVEL,
-            "*", "+" );
-    
-        assertTrue( cursor.next() );
-    
-        Entry entry = cursor.get();
-        assertNotNull( entry );
-        assertTrue( entry.contains( "cn", "elecharny" ) );
-        assertTrue( entry.contains( "sn", "Emmanuel L\u00E9charny" ) );
-    
-        cursor.close();
-    }
-    
-    
-    @Test
-    public void testSearchBinary() throws Exception
-    {
-        connection.loadSchema();
-        EntryCursor cursor = connection
-            .search(
-                "ou=system",
-                "(publicKey=\\30\\5C\\30\\0D\\06\\09\\2A\\86\\48\\86\\F7\\0D\\01\\01\\01\\05\\00\\03\\4B\\00\\30\\48\\02\\41\\00\\A6\\C7\\9C\\B1\\6C\\E4\\DD\\8F\\1E\\4D\\20\\93\\22\\3F\\83\\75\\DE\\21\\D8\\F1\\9D\\63\\80\\5B\\94\\55\\6A\\9E\\33\\59\\9B\\8D\\63\\88\\0D\\18\\7D\\4C\\85\\F1\\CF\\54\\77\\32\\E9\\61\\0C\\A2\\8F\\B3\\6B\\15\\34\\5E\\1F\\88\\BF\\A0\\73\\AC\\86\\BB\\D0\\85\\02\\03\\01\\00\\01)",
-                SearchScope.SUBTREE, "publicKey" );
-    
-        assertTrue( cursor.next() );
-    
-        Entry entry = cursor.get();
-        assertNotNull( entry.get( "publicKey" ) );
-    
-        cursor.close();
-    }
-    
-    
-    @Test
-    public void testSubDn() throws Exception
-    {
-        connection.loadSchema();
-        EntryCursor cursor = connection.search( "ou=system", "(cn=user1)", SearchScope.SUBTREE,
"publicKey" );
-    
-        assertTrue( cursor.next() );
-    
-        Entry entry = cursor.get();
-        assertEquals( "cn=user1,ou=users,ou=system", entry.getDn().getName() );
-    
-        cursor.close();
-    
+
         SearchRequest req = new SearchRequestImpl();
         req.setScope( SearchScope.SUBTREE );
         req.addAttributes( "*" );
         req.setTimeLimit( 0 );
         req.setBase( new Dn( "ou=system" ) );
         req.setFilter( "(cn=user1)" );
-    
-        SearchCursor searchCursor = connection.search( req );
-    
-        assertTrue( searchCursor.next() );
-    
-        Response response = searchCursor.get();
-    
-        Entry resultEntry = ( ( SearchResultEntry ) response ).getEntry();
-        assertEquals( "cn=user1,ou=users,ou=system", resultEntry.getDn().getName() );
-    
-        searchCursor.close();
-    }
-
 
-    /**
-     * Test to demonstrate https://issues.apache.org/jira/browse/DIRAPI-140
-     */
-    @Test
-    public void test_DIRAPI140() throws Exception
-    {
-        for ( int i = 0; i < 100; i++ )
-        {
-            System.out.println( "Loop " + i );
-
-            SearchRequest req = new SearchRequestImpl();
-            req.setScope( SearchScope.SUBTREE );
-            req.addAttributes( "*" );
-            req.setTimeLimit( 0 );
-            req.setBase( new Dn( "ou=system" ) );
-            req.setFilter( "(cn=user1)" );
-
-            SearchCursor searchCursor = connection.search( req );
+        SearchCursor searchCursor = connection.search( req );
 
-            assertTrue( searchCursor.next() );
+        // We should have only one entry
+        assertTrue( searchCursor.next() );
+        assertFalse( searchCursor.next() );
 
-            searchCursor.close();
-        }
+        searchCursor.close();
     }
+}
 
 }



Mime
View raw message