You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/02/23 12:40:05 UTC

svn commit: r915289 - /directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java

Author: kayyagari
Date: Tue Feb 23 11:40:05 2010
New Revision: 915289

URL: http://svn.apache.org/viewvc?rev=915289&view=rev
Log:
o added a test case for searching with alais deref options
o modified the searchscope to one level to prevent changing the code when new entries are applied (as the test cases evolve)

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

Modified: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java?rev=915289&r1=915288&r2=915289&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java (original)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientSearchRequestTest.java Tue Feb 23 11:40:05 2010
@@ -29,14 +29,17 @@
 
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.future.SearchFuture;
+import org.apache.directory.ldap.client.api.message.SearchRequest;
 import org.apache.directory.ldap.client.api.message.SearchResponse;
 import org.apache.directory.ldap.client.api.message.SearchResultDone;
 import org.apache.directory.server.annotations.CreateLdapServer;
 import org.apache.directory.server.annotations.CreateTransport;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
 import org.apache.directory.shared.ldap.cursor.Cursor;
 import org.apache.directory.shared.ldap.filter.SearchScope;
+import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.junit.After;
 import org.junit.Before;
@@ -51,8 +54,27 @@
  * @version $Rev$, $Date$
  */
 @RunWith(FrameworkRunner.class)
-@CreateLdapServer(transports =
-    { @CreateTransport(protocol = "LDAP"), @CreateTransport(protocol = "LDAPS") })
+@CreateLdapServer(
+    transports = 
+        {
+          @CreateTransport(protocol = "LDAP"), 
+          @CreateTransport(protocol = "LDAPS") 
+        })
+@ApplyLdifs({
+    "dn: cn=user1,ou=users,ou=system",
+    "objectClass: person",
+    "objectClass: top",
+    "sn: user1 sn",
+    "cn: user1",
+    
+    // alias to the above entry
+    "dn: cn=user1-alias,ou=users,ou=system",
+    "objectClass: alias",
+    "objectClass: top",
+    "objectClass: extensibleObject",
+    "aliasedObjectName: cn=user1,ou=users,ou=system",
+    "cn: user1-alias"
+})
 public class ClientSearchRequestTest extends AbstractLdapTestUnit
 {
     private LdapConnection connection;
@@ -89,7 +111,7 @@
     @Test
     public void testSearch() throws Exception
     {
-        Cursor<SearchResponse> cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.SUBTREE, "*",
+        Cursor<SearchResponse> cursor = connection.search( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL, "*",
             "+" );
         int count = 0;
         while ( cursor.next() )
@@ -98,14 +120,14 @@
             count++;
         }
 
-        assertEquals( 10, count );
+        assertEquals( 5, count );
     }
     
 
     @Test
     public void testAsyncSearch() throws Exception
     {
-        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.SUBTREE, "*",
+        SearchFuture searchFuture = connection.searchAsync( "ou=system", "(objectclass=*)", SearchScope.ONELEVEL, "*",
             "+" );
         int count = 0;
         SearchResponse searchResponse = null;
@@ -120,7 +142,37 @@
         }
         while ( !( searchResponse instanceof SearchResultDone ) );
 
-        assertEquals( 10, count );
+        assertEquals( 5, count );
     }
 
+    
+    @Test
+    public void testSearchWithDerefAlias() throws Exception
+    {
+        SearchRequest searchRequest = new SearchRequest();
+        searchRequest.setBaseDn( "ou=users,ou=system" );
+        searchRequest.setFilter( "(objectClass=*)" );
+        searchRequest.setScope( SearchScope.ONELEVEL );
+        searchRequest.addAttributes( "*" );
+        
+        int count = 0;
+        Cursor<SearchResponse> cursor = connection.search( searchRequest );
+        while( cursor.next() )
+        {
+            count++;
+        }
+        
+        // due to dereferencing of aliases we get only one entry
+        assertEquals( 1, count );
+
+        count = 0;
+        searchRequest.setDerefAliases( AliasDerefMode.NEVER_DEREF_ALIASES );
+        cursor = connection.search( searchRequest );
+        while( cursor.next() )
+        {
+            count++;
+        }
+        
+        assertEquals( 2, count );
+    }
 }