directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r926066 - /directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
Date Mon, 22 Mar 2010 13:22:19 GMT
Author: elecharny
Date: Mon Mar 22 13:22:18 2010
New Revision: 926066

URL: http://svn.apache.org/viewvc?rev=926066&view=rev
Log:
Added extensive tests on the returning attributes search

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

Modified: directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java?rev=926066&r1=926065&r2=926066&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/search/SearchRequestReturningAttributesTest.java
Mon Mar 22 13:22:18 2010
@@ -23,16 +23,19 @@ package org.apache.directory.shared.clie
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import org.apache.directory.ldap.client.api.LdapConnection;
 import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
 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.entry.Entry;
 import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.name.DN;
 import org.junit.After;
@@ -42,7 +45,7 @@ import org.junit.runner.RunWith;
 
 
 /**
- * TODO ClientSearchRequestTest.
+ * A class to test the search operation with a returningAttributes parameter
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
@@ -113,14 +116,398 @@ public class SearchRequestReturningAttri
         Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, "*",
             "+" );
         int count = 0;
+        SearchResponse response = null;
         
         while ( cursor.next() )
         {
-            SearchResponse response = cursor.get();
+            response = cursor.get();
             assertNotNull( response );
             count++;
         }
 
         assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 7, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the user attributes (*)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, "*" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 3, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the operational attributes (+)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllOperationals() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, "+" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the user attributes plus a couple of operational
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllUsersAndSomeOperationals() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, "*",
+            "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 5, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting all the operational attributes and a couple of users attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchAllOperationalAndSomeUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, "+",
+            "cn", "sn" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 6, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some user and Operational attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchSomeOpsAndUsers() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "entryUUID", "sn", "entryCSN" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes which appear more than one
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithDuplicatedAttrs() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "entryUUID", "cn", "sn", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes using text and OID, and duplicated
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithOIDAndtext() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "1.3.6.1.1.16.4", "surName", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 4, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting some attributes which are not present
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchWithMissingAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "cn", "1.3.6.1.1.16.4", "gn", "entryCSN", "entryUUID" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 3, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "1.1" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 0, entry.size() );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1) and some attributes
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributesAndAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "1.1", "cn" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        assertEquals( 1, entry.size() );
+        assertTrue( entry.containsAttribute( "cn" ) );
+    }
+
+
+    /**
+     * Test a search requesting no attributes (1.1) and all attributes (*, +)
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testSearchNoAttributesAllAttributes() throws Exception
+    {
+        Cursor<SearchResponse> cursor = connection.search( "cn=user1,ou=users,ou=system",
"(objectclass=*)", SearchScope.OBJECT, 
+            "1.1", "*", "+" );
+        int count = 0;
+        SearchResponse response = null;
+        
+        while ( cursor.next() )
+        {
+            response = cursor.get();
+            assertNotNull( response );
+            count++;
+        }
+
+        assertEquals( 1, count );
+        assertNotNull( response );
+        assertTrue( response instanceof SearchResultEntry );
+        SearchResultEntry resultEntry = (SearchResultEntry)response;
+        Entry entry = resultEntry.getEntry();
+        
+        
+        assertEquals( 7, entry.size() );
+        assertTrue( entry.containsAttribute( "objectClass" ) );
+        assertTrue( entry.containsAttribute( "cn" ) );
+        assertTrue( entry.containsAttribute( "sn" ) );
+        assertTrue( entry.containsAttribute( "creatorsName" ) );
+        assertTrue( entry.containsAttribute( "createTimestamp" ) );
+        assertTrue( entry.containsAttribute( "entryUUID" ) );
+        assertTrue( entry.containsAttribute( "entryCSN" ) );
     }
 }



Mime
View raw message