directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r965116 - /directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
Date Sat, 17 Jul 2010 18:08:22 GMT
Author: elecharny
Date: Sat Jul 17 18:08:22 2010
New Revision: 965116

URL: http://svn.apache.org/viewvc?rev=965116&view=rev
Log:
o Redefined a AddSubentry test with a new hierarchy of objects for completness. 
o Added some helper methods.
o Used the API

Modified:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java?rev=965116&r1=965115&r2=965116&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
(original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/subtree/SubentryServiceIT.java
Sat Jul 17 18:08:22 2010
@@ -25,7 +25,6 @@ import static org.junit.Assert.assertFal
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
 
 import java.util.HashMap;
 import java.util.Map;
@@ -37,18 +36,31 @@ import javax.naming.directory.BasicAttri
 import javax.naming.directory.BasicAttributes;
 import javax.naming.directory.DirContext;
 import javax.naming.directory.ModificationItem;
-import javax.naming.directory.NoSuchAttributeException;
 import javax.naming.directory.SearchControls;
 import javax.naming.directory.SearchResult;
 import javax.naming.ldap.LdapContext;
 
+import org.apache.directory.ldap.client.api.LdapConnection;
+import org.apache.directory.ldap.client.api.message.AddResponse;
+import org.apache.directory.ldap.client.api.message.ModifyRequest;
+import org.apache.directory.ldap.client.api.message.SearchResponse;
+import org.apache.directory.ldap.client.api.message.SearchResultEntry;
+import org.apache.directory.server.core.annotations.ApplyLdifs;
 import org.apache.directory.server.core.annotations.CreateDS;
 import org.apache.directory.server.core.integ.AbstractLdapTestUnit;
 import org.apache.directory.server.core.integ.FrameworkRunner;
+import org.apache.directory.server.core.integ.IntegrationUtils;
 import org.apache.directory.shared.ldap.codec.search.controls.subentries.SubentriesControl;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.cursor.Cursor;
+import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
+import org.apache.directory.shared.ldap.filter.SearchScope;
 import org.apache.directory.shared.ldap.jndi.JndiUtils;
+import org.apache.directory.shared.ldap.ldif.LdifUtils;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
+import org.apache.directory.shared.ldap.name.DN;
 import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -61,6 +73,91 @@ import org.junit.runner.RunWith;
  */
 @RunWith ( FrameworkRunner.class )
 @CreateDS( name="SubentryServiceIT-class" )
+@ApplyLdifs(
+    {
+        // A test branch
+        "dn: dc=test,ou=system",
+        "objectClass: top",
+        "objectClass: domain",
+        "dc: test",
+        "",
+            // The first level AP
+            "dn: dc=AP-A,dc=test,ou=system",
+            "objectClass: top",
+            "objectClass: domain",
+            "administrativeRole: collectiveAttributeSpecificArea",
+            "dc: AP-A",
+            "",
+                // entry A1
+                "dn: cn=A1,dc=AP-A,dc=test,ou=system",
+                "objectClass: top",
+                "objectClass: person",
+                "cn: A1",
+                "sn: a1",
+                "",
+                    // entry A1-1
+                    "dn: cn=A1-1,cn=A1,dc=AP-A,dc=test,ou=system",
+                    "objectClass: top",
+                    "objectClass: person",
+                    "cn: A1-1",
+                    "sn: a1-1",
+                    "",
+                    // entry A1-2
+                    "dn: cn=A1-2,cn=A1,dc=AP-A,dc=test,ou=system",
+                    "objectClass: top",
+                    "objectClass: person",
+                    "cn: A1-2",
+                    "sn: a1-2",
+                    "",
+                // entry A2
+                "dn: cn=A2,dc=AP-A,dc=test,ou=system",
+                "objectClass: top",
+                "objectClass: person",
+                "cn: A2",
+                "sn: a2",
+                "",
+                    // entry A2-1
+                    "dn: cn=A2-1,cn=A2,dc=AP-A,dc=test,ou=system",
+                    "objectClass: top",
+                    "objectClass: person",
+                    "cn: A2-1",
+                    "sn: a2-1",
+                    "",
+                    // The second level AP
+                    "dn: dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+                    "objectClass: top",
+                    "objectClass: domain",
+                    "administrativeRole: collectiveAttributeSpecificArea",
+                    "dc: AP-B",
+                    "",
+                        // entry B1
+                        "dn: cn=B1,dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+                        "objectClass: top",
+                        "objectClass: person",
+                        "cn: B1",
+                        "sn: b1",
+                        "",
+                        // entry B2
+                        "dn: cn=B2,dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+                        "objectClass: top",
+                        "objectClass: person",
+                        "cn: B2",
+                        "sn: b2",
+                        "",
+            // The first level non AP
+            "dn: dc=not-AP,dc=test,ou=system",
+            "objectClass: top",
+            "objectClass: domain",
+            "dc: not-AP",
+            "",
+                // An entry under non-AP
+                "dn: cn=C,dc=not-AP,dc=test,ou=system",
+                "objectClass: top",
+                "objectClass: person",
+                "cn: C",
+                "sn: entry-C",
+                ""
+    })
 public class SubentryServiceIT extends AbstractLdapTestUnit
 {
 
@@ -92,6 +189,20 @@ public class SubentryServiceIT extends A
     }
 
 
+    public Entry getSubentry( String dn ) throws Exception
+    {
+        Entry subentry = LdifUtils.createEntry( new DN( dn ), 
+            "objectClass: top",
+            "objectClass: subentry",
+            "objectClass: collectiveAttributeSubentry",
+            "subtreeSpecification: { base \"ou=configuration\" }",
+            "c-o: Test Org",
+            "cn: testsubentry" );
+        
+        return subentry;
+    }
+
+
     public Attributes getTestSubentryWithExclusion()
     {
         Attributes subentry = new BasicAttributes( true );
@@ -119,6 +230,14 @@ public class SubentryServiceIT extends A
     }
 
 
+    private void addAdministrativeRole( LdapConnection connection, String dn, String role
) throws Exception
+    {
+        ModifyRequest modifyRequest = new ModifyRequest( new DN( dn ) );
+        modifyRequest.add( "administrativeRole", role );
+        connection.modify( modifyRequest );
+    }
+
+
     private Map<String, Attributes> getAllEntries() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
@@ -139,6 +258,28 @@ public class SubentryServiceIT extends A
     }
 
 
+    private Map<String, Entry> getAllEntries( LdapConnection connection, String dn
) throws Exception
+    {
+        Map<String, Entry> results = new HashMap<String, Entry>();
+
+        Cursor<SearchResponse> responses = connection.search( dn, "(objectClass=*)",
SearchScope.SUBTREE, "+", "*" );
+        
+        while ( responses.next() )
+        {
+            SearchResponse response = responses.get();
+            
+            if ( response instanceof SearchResultEntry )
+            {
+                Entry entry = ((SearchResultEntry)response).getEntry();
+                
+                results.put(  entry.getDn().getName(), entry );
+            }
+        }
+        
+        return results;
+    }
+
+
     @Test
     public void testEntryAdd() throws Exception
     {
@@ -168,75 +309,159 @@ public class SubentryServiceIT extends A
             .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
     }
 
+    
+    private void checkHasOpAttr( Entry entry, String opAttr, String subentryDn ) throws Exception
+    {
+        EntryAttribute attribute = entry.get( opAttr );
+        assertNotNull( attribute );
+        assertEquals( subentryDn, attribute.getString() );
+        assertEquals( 1, attribute.size() );
+    }
+
+    
+    private void checkDoesNotHaveOpAttr( Entry entry, String opAttr ) throws Exception
+    {
+        EntryAttribute attribute = entry.get( opAttr );
+        assertNull( attribute );
+    }
+
 
     @Test
+    /**
+     * Add a subentry under AP-A. 
+     * The following entries must be modified :
+     * A1 
+     *   A1-1 
+     *   A1-2 
+     * A2
+     *   A2-1
+     *   AP-B
+     *     B1
+     *     B2
+     * The following entries must not be be modified :
+     * AP-A
+     * not-AP
+     *   C
+     */
     public void testSubentryAdd() throws Exception
     {
-        LdapContext sysRoot = getSystemContext( service );
-        try
-        {
-            sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
-            fail( "should never get here: cannot create subentry under regular entries" );
-        }
-        catch ( NoSuchAttributeException e )
-        {
-        }
+        LdapConnection connection = IntegrationUtils.getAdminConnection( service );
 
-        addAdministrativeRole( "collectiveArributeSpecificArea" );
-        sysRoot.createSubcontext( "cn=testsubentry", getTestSubentry() );
-        Map<String, Attributes> results = getAllEntries();
+        // Add the subentry
+        Entry subEntry = LdifUtils.createEntry( new DN( "cn=testsubentry,dc=AP-A,dc=test,ou=system"
), 
+            "objectClass: top",
+            "objectClass: subentry",
+            "objectClass: collectiveAttributeSubentry",
+            "subtreeSpecification: {}",  // All the entry from the AP, including the AP
+            "c-o: Test Org",
+            "cn: testsubentry" );
 
-        // --------------------------------------------------------------------
-        // Make sure entries selected by the subentry do have the mark
-        // --------------------------------------------------------------------
+        AddResponse response = connection.add( subEntry );
 
-        Attributes configuration = results.get( "ou=configuration,ou=system" );
-        Attribute collectiveAttributeSubentries = configuration.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
);
-        assertNotNull( "ou=configuration,ou=system should be marked", collectiveAttributeSubentries
);
-        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get()
);
-        assertEquals( 1, collectiveAttributeSubentries.size() );
+        assertTrue( response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS );
 
-        Attributes interceptors = results.get( "ou=interceptors,ou=configuration,ou=system"
);
-        collectiveAttributeSubentries = interceptors.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
);
-        assertNotNull( "ou=interceptors,ou=configuration,ou=system should be marked", collectiveAttributeSubentries
);
-        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get()
);
-        assertEquals( 1, collectiveAttributeSubentries.size() );
+        // Check the resulting modifications
+        Map<String, Entry> results = getAllEntries( connection, "dc=test,ou=system"
);
 
-        Attributes partitions = results.get( "ou=partitions,ou=configuration,ou=system" );
-        collectiveAttributeSubentries = partitions.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
);
-        assertNotNull( "ou=partitions,ou=configuration,ou=system should be marked", collectiveAttributeSubentries
);
-        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get()
);
-        assertEquals( 1, collectiveAttributeSubentries.size() );
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+        String subEntryAPADn = "2.5.4.3=testsubentry,0.9.2342.19200300.100.1.25=ap-a,0.9.2342.19200300.100.1.25=test,2.5.4.11=system";
+        
+        String[] modifiedEntries = new String[]
+            {
+                "dc=AP-A,dc=test,ou=system",
+                  "cn=A1,dc=AP-A,dc=test,ou=system",
+                    "cn=A1-1,cn=A1,dc=AP-A,dc=test,ou=system",
+                    "cn=A1-2,cn=A1,dc=AP-A,dc=test,ou=system",
+                  "cn=A2,dc=AP-A,dc=test,ou=system",
+                    "cn=A2-1,cn=A2,dc=AP-A,dc=test,ou=system",
+                    "dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+                      "cn=B1,dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+                      "cn=B2,dc=AP-B,cn=A2,dc=AP-A,dc=test,ou=system",
+            };
 
-        Attributes services = results.get( "ou=services,ou=configuration,ou=system" );
-        collectiveAttributeSubentries = services.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
);
-        assertNotNull( "ou=services,ou=configuration,ou=system should be marked", collectiveAttributeSubentries
);
-        assertEquals( "2.5.4.3=testsubentry,2.5.4.11=system", collectiveAttributeSubentries.get()
);
-        assertEquals( 1, collectiveAttributeSubentries.size() );
+        for ( String dn : modifiedEntries )
+        {
+            checkHasOpAttr( results.get( dn ), "collectiveAttributeSubentries", subEntryAPADn
);
+        }
 
         // --------------------------------------------------------------------
         // Make sure entries not selected by subentry do not have the mark
         // --------------------------------------------------------------------
+        String[] unchangedEntries = new String[]
+            {
+                "dc=test,ou=system",
+                  "dc=not-AP,dc=test,ou=system",
+                    "cn=C,dc=not-AP,dc=test,ou=system",
+            };
 
-        Attributes system = results.get( "ou=system" );
-        assertNull( "ou=system should not be marked", system.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
) );
+        for ( String dn : unchangedEntries )
+        {
+            checkDoesNotHaveOpAttr( results.get( dn ), "collectiveAttributeSubentries" );
+        }
 
-        Attributes users = results.get( "ou=users,ou=system" );
-        assertNull( "ou=users,ou=system should not be marked", users.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
) );
+        connection.close();
+    }
 
-        Attributes groups = results.get( "ou=groups,ou=system" );
-        assertNull( "ou=groups,ou=system should not be marked", groups.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
) );
 
-        Attributes admin = results.get( "uid=admin,ou=system" );
-        assertNull( "uid=admin,ou=system should not be marked", admin.get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT
) );
+    public void testSubentryAddOld() throws Exception
+    {
+        LdapConnection connection = IntegrationUtils.getAdminConnection( service );
+        
+        Entry subEntry = getSubentry( "cn=testsubentry,ou=system" );
+        AddResponse response = connection.add( subEntry );
 
-        Attributes sysPrefRoot = results.get( "prefNodeName=sysPrefRoot,ou=system" );
-        assertNull( "prefNode=sysPrefRoot,ou=system should not be marked", sysPrefRoot
-            .get( SchemaConstants.COLLECTIVE_ATTRIBUTE_SUBENTRIES_AT ) );
+        assertTrue( "should never get here: cannot create subentry under regular entries",
response.getLdapResult().getResultCode() == ResultCodeEnum.NO_SUCH_ATTRIBUTE );
 
-    }
+        addAdministrativeRole( connection, "ou=system", "collectiveArributeSpecificArea"
);
+        connection.add( subEntry );
+        
+        // All the entries under ou=configuration,ou=system will have a 
+        // collectiveAttributeSubentries = "cn=testsubentry, ou=system"
+        // operational attribute
+        Map<String, Entry> results = getAllEntries( connection, "ou=system" );
 
+        // --------------------------------------------------------------------
+        // Make sure entries selected by the subentry do have the mark
+        // --------------------------------------------------------------------
+        String subEntryDn = "2.5.4.3=testsubentry,2.5.4.11=system";
+        
+        String[] modifiedEntries = new String[]
+            {
+                "ou=configuration,ou=system",
+                "ou=interceptors,ou=configuration,ou=system",
+                "ou=partitions,ou=configuration,ou=system",
+                "ou=configuration,ou=system",
+                "ou=services,ou=configuration,ou=system"
+            };
 
+        for ( String dn : modifiedEntries )
+        {
+            checkHasOpAttr( results.get( dn ), "collectiveAttributeSubentries", subEntryDn
);
+        }
+
+        // --------------------------------------------------------------------
+        // Make sure entries not selected by subentry do not have the mark
+        // --------------------------------------------------------------------
+        String[] unchangedEntries = new String[]
+            {
+                "ou=system",
+                "ou=users,ou=system",
+                "ou=groups,ou=system",
+                "uid=admin,ou=system",
+                "prefNodeName=sysPrefRoot,ou=system"
+            };
+
+        for ( String dn : unchangedEntries )
+        {
+            checkDoesNotHaveOpAttr( results.get( dn ), "collectiveAttributeSubentries" );
+        }
+
+        connection.close();
+    }
+
+    
     @Test
     public void testSubentryModify() throws Exception
     {
@@ -882,7 +1107,7 @@ public class SubentryServiceIT extends A
     public void testSubentriesControl() throws Exception
     {
         LdapContext sysRoot = getSystemContext( service );
-        addAdministrativeRole( "collectiveArributeSpecificArea" );
+        addAdministrativeRole( "collectiveAttributeSpecificArea" );
         sysRoot.createSubcontext( "cn=testsubentry", getTestSubentryWithExclusion() );
         SearchControls searchControls = new SearchControls();
         searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );



Mime
View raw message