directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1055069 - /directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java
Date Tue, 04 Jan 2011 14:53:12 GMT
Author: elecharny
Date: Tue Jan  4 14:53:12 2011
New Revision: 1055069

URL: http://svn.apache.org/viewvc?rev=1055069&view=rev
Log:
Some tests for the search operation applied to subentries

Modified:
    directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java

Modified: directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java?rev=1055069&r1=1055068&r2=1055069&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java
(original)
+++ directory/apacheds/branches/apacheds-AP/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentrySearchOperationIT.java
Tue Jan  4 14:53:12 2011
@@ -20,22 +20,21 @@
 package org.apache.directory.server.core.subtree;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
 
 import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.shared.ldap.codec.search.controls.subentries.SubentriesControl;
 import org.apache.directory.shared.ldap.cursor.SearchCursor;
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.filter.SearchScope;
-import org.apache.directory.shared.ldap.ldif.LdifUtils;
-import org.apache.directory.shared.ldap.message.AddResponse;
-import org.apache.directory.shared.ldap.message.DeleteResponse;
-import org.apache.directory.shared.ldap.message.ResultCodeEnum;
+import org.apache.directory.shared.ldap.message.SearchRequest;
+import org.apache.directory.shared.ldap.message.SearchRequestImpl;
 import org.apache.directory.shared.ldap.message.SearchResultEntry;
+import org.apache.directory.shared.ldap.name.DN;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -169,47 +168,88 @@ public class SubentrySearchOperationIT e
     }
 
     
-
-    
     // ===================================================================
-    // Test the Lookup operation on Subentries
+    // Test the Search operation on Subentries
     // -------------------------------------------------------------------
     /**
-     * Test the lookup of a subentry. Subentries can be read directly as it's 
-     * a OBJECT search.
+     * Test the search of a subentry with a non admin user, and a SUBTREE scope.
+     * It should fail, as such a search is not allowed by the RFC
      */
     @Test
-    public void testLookupSubentry() throws Exception
+    public void testSearchSubentryNotAdminScopeSubtree() throws Exception
     {
         createAAP( "ou=AAP, ou=system" );
         createCaSubentry( "cn=test, ou=AAP, ou=system", "{}" );
         
-        Entry aap = adminConnection.lookup( "ou=AAP, ou=system", "+" );
+        SearchCursor results = userConnection.search( "ou=system", "(ObjectClass=subentry)",
SearchScope.SUBTREE, "+" );
         
-        assertNotNull( aap );
-        long acSN = Long.parseLong( aap.get( "AccessControlSeqNumber" ).getString() );
-        long caSN = Long.parseLong( aap.get( "CollectiveAttributeSeqNumber" ).getString()
);
-        long ssSN = Long.parseLong( aap.get( "SubSchemaSeqNumber" ).getString() );
-        long teSN = Long.parseLong( aap.get( "TriggerExecutionSeqNumber" ).getString() );
+        assertNotNull( results );
         
-        assertEquals( -1L, acSN );
-        assertNotSame( -1L, caSN );
-        assertEquals( -1L, ssSN );
-        assertEquals( -1L, teSN );
+        // the results should contain no entry
+        assertFalse( results.available() );
+    }
+
+
+    /**
+     * Test the search of a subentry with an admin user, and a SUBTREE scope.
+     * It should fail, as such a search is not allowed by the RFC
+     */
+    @Test
+    public void testSearchSubentryAdminScopeSubtree() throws Exception
+    {
+        createAAP( "ou=AAP, ou=system" );
+        createCaSubentry( "cn=test, ou=AAP, ou=system", "{}" );
         
-        Entry subentry = adminConnection.lookup( "cn=test, ou=AAP, ou=system", "+" );
-        assertNotNull( subentry );
-        assertNull( subentry.get( "AccessControlSeqNumber" ) );
-        assertNull( subentry.get( "CollectiveAttributeSeqNumber" ) );
-        assertNull( subentry.get( "SubSchemaSeqNumber" ) );
-        assertNull( subentry.get( "TriggerExecutionSeqNumber" ) );
+        SearchCursor results = adminConnection.search( "ou=system", "(ObjectClass=subentry)",
SearchScope.SUBTREE, "+" );
+        
+        assertNotNull( results );
+        
+        // the results should contain no entry
+        assertFalse( results.available() );
+    }
+
+
+    /**
+     * Test the search of a subentry with a admin user, and a SUBTREE scope.
+     * It should succeed if we use the subentries control
+     */
+    @Test
+    public void testSearchSubentryScopeSubtreeWithControl() throws Exception
+    {
+        createAAP( "ou=AAP, ou=system" );
+        createCaSubentry( "cn=test, ou=AAP, ou=system", "{}" );
+        
+        SearchRequest searchRequest = new SearchRequestImpl();
+        searchRequest.setBase( new DN( "ou=system" ) );
+        searchRequest.setFilter( "(ObjectClass=subentry)" );
+        searchRequest.setScope( SearchScope.SUBTREE );
+        searchRequest.addAttributes( "+" );
+        SubentriesControl control = new SubentriesControl();
+        control.setVisibility( true );
+        searchRequest.addControl( control );
+        SearchCursor results = adminConnection.search( searchRequest );
+        
+        assertNotNull( results );
+        //assertTrue( results.available() );
+        
+        int nbEntry = 0;
+        
+        while ( results.next() )
+        {
+            Entry entry = ( ( SearchResultEntry ) results.get() ).getEntry();
+            
+            assertEquals( "cn=test,ou=AAP,ou=system", entry.getDn().toString() );
+            nbEntry++;
+        }
+        
+        assertEquals( 1, nbEntry );
     }
 
 
     /**
      * Test the lookup of a subentry. Subentries can be read directly as it's 
      * a OBJECT search. We don't use the admin in this test
-     */
+     *
     @Test
     public void testLookupSubentryNotAdmin() throws Exception
     {
@@ -239,12 +279,12 @@ public class SubentrySearchOperationIT e
     
     
     // ===================================================================
-    // Test the Lookup operation on Entries
+    // Test the Search operation on Entries
     // -------------------------------------------------------------------
     /**
      * Test the lookup of a entry with no APs. The entry should not have
      * any SN
-     */
+     *
     @Test
     public void testLookupEntryNoAp() throws Exception
     {
@@ -266,7 +306,7 @@ public class SubentrySearchOperationIT e
     /**
      * Test the lookup of a entry added under an AP with no subentry. All
      * the entry SN must be set to -1, and not have any subentries reference
-     */
+     *
     @Test
     public void testLookupEntryUnderApNoSubentry() throws Exception
     {
@@ -293,7 +333,7 @@ public class SubentrySearchOperationIT e
      * Test the lookup of a entry added under an AP with a subentry. 
      * The entry is part of the subtreeSpecification.
      * All the entry SN must be set to the AP SN, and have any subentries reference
-     */
+     *
     @Test
     public void testLookupEntryUnderApWithSubentrySelected() throws Exception
     {
@@ -324,7 +364,7 @@ public class SubentrySearchOperationIT e
      * Test the lookup of a entry when an AP with a subentry is added. 
      * The entry is not part of the subtreeSpecification.
      * All the entry SN must be set to the AP SN, and have no subentries reference
-     */
+     *
     @Test
     public void testLookupEntryAfterApAdditionWithSubentrySelected() throws Exception
     {
@@ -355,7 +395,7 @@ public class SubentrySearchOperationIT e
      * Test the lookup of a entry when the subentry it referes has been 
      * removed. The entry's reference to the subentry must be removed, the 
      * SN must be the new AP SN
-     */
+     *
     @Test
     public void testLookupEntryAfterSubentryDeletion() throws Exception
     {
@@ -392,5 +432,5 @@ public class SubentrySearchOperationIT e
         // Now, check the entry 
         assertEquals( seqNumber2, getCaSeqNumber( "cn=e1,ou=SAP,ou=system" ) );
         assertNull( getCaUuidRef( "cn=e1,ou=AAP,ou=system" ) );
-    }
+    } */
 }



Mime
View raw message