directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r702434 [1/5] - in /directory: apacheds/trunk/ apacheds/trunk/all/ apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/ apached...
Date Tue, 07 Oct 2008 11:27:01 GMT
Author: elecharny
Date: Tue Oct  7 04:26:55 2008
New Revision: 702434

URL: http://svn.apache.org/viewvc?rev=702434&view=rev
Log:
o Modified the way referrals are handled, to move the handling into the CoreSession
o Added Referral tests for all the operations, covering (hopefully) all the different cases (we can
now handle referrals using the JNDI layer and the Core-API)
o Added a ReferralInterceptor in charge to update the referralManager table in memory
o Reworked the Partion tree to use a common structure shared with the referralManager table
o Fixed a small bug in the LdapURL toString() method
o Fixed some old referral tests which were not correctly built the resulting URL
o The ReferralAwareRequestHandler class now handle only the search request (and will be removed
soon)
o Added some javadoc, fixing some typoes
o Fixed the core-integ AbstractState handling of multiple entries in the Ldif file annotation (no
more than one entry was read and injected)
o Added an equals() method into the ClonedServerEntry class
o Added the throwReferral(), isReferralThrown(), ignoreReferral() and isReferralIgnored() methods in
the OperationContext interface, implemented those methods in all the implementing classes
o Added methods for all the operations in the CoreSession to exlicitely handle the ManageDSAIt flag
o The PartitionNexus.listSuffixes() method now returns a List of String instead of an iterator


Added:
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/AddReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/CompareReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/DeleteReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/ModifyReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/MoveAndRenameReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/MoveReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/RenameReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/SearchReferralIT.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/referral/ReferralInterceptor.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/controls/PagedSearchCookie.java
Modified:
    directory/apacheds/trunk/all/pom.xml
    directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
    directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java
    directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/schema/MetaSyntaxHandlerIT.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerContext.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerDirContext.java
    directory/apacheds/trunk/core-jndi/src/main/java/org/apache/directory/server/core/jndi/ServerLdapContext.java
    directory/apacheds/trunk/core/pom.xml
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/CoreSession.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultCoreSession.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/DirectoryService.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/OperationManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/ReferralManager.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/ReferralManagerImpl.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authn/AuthenticationInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/GroupCache.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/authz/TupleCache.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/BaseInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/Interceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/NextInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AbstractOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/AddOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/BindOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/CompareOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/DeleteOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/ModifyOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveAndRenameOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/MoveOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/OperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/RenameOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/interceptor/context/SearchOperationContext.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/operational/OperationalAttributeInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexus.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/PartitionNexusProxy.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/sp/LdapClassLoader.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/trigger/TriggerSpecCache.java
    directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/authz/support/MaxImmSubFilterTest.java
    directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/InterceptorChainTest.java
    directory/apacheds/trunk/core/src/test/java/org/apache/directory/server/core/interceptor/MockInterceptor.java
    directory/apacheds/trunk/interceptor-kerberos/src/main/java/org/apache/directory/server/core/kerberos/KeyDerivationInterceptor.java
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/apacheds/trunk/pom.xml
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/LdapRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ReferralAwareRequestHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
    directory/apacheds/trunk/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/extended/LaunchDiagnosticUiHandler.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/add/AddIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/delete/DeleteIT.java
    directory/apacheds/trunk/server-integ/src/test/java/org/apache/directory/server/operations/modifydn/ModifyDnReferralIT.java
    directory/installers/trunk/apacheds-noarch/pom.xml
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/entry/client/DefaultClientEntry.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/LdapURL.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnBranchNode.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnLeafNode.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/util/tree/DnNode.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/util/tree/TestDnNode.java
    directory/shared/trunk/pom.xml

Modified: directory/apacheds/trunk/all/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/all/pom.xml?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/all/pom.xml (original)
+++ directory/apacheds/trunk/all/pom.xml Tue Oct  7 04:26:55 2008
@@ -68,11 +68,6 @@
             <configuration>
               <promoteTransitiveDependencies>true</promoteTransitiveDependencies>
               <shadedArtifactAttached>false</shadedArtifactAttached>
-              <artifactSet>
-                <excludes>
-                  <exclude>bouncycastle:bcprov-jdk15</exclude>
-                </excludes>
-              </artifactSet>
             </configuration>
           </execution>
         </executions>

Modified: directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java (original)
+++ directory/apacheds/trunk/core-entry/src/main/java/org/apache/directory/server/core/entry/ClonedServerEntry.java Tue Oct  7 04:26:55 2008
@@ -448,6 +448,36 @@
     }
     
     
+    /**
+	 * @see Object#equals(Object);
+	 */
+    public boolean equals( Object obj )
+    {
+        // Short circuit
+        if ( this == obj )
+        {
+            return true;
+        }
+        
+        Entry other;
+        
+        if ( obj instanceof ClonedServerEntry )
+        {
+            other = ((ClonedServerEntry)obj).getClonedEntry();
+        }
+        else if ( obj instanceof ServerEntry )
+        {
+            other = (ServerEntry)obj;
+        }
+        else 
+        {
+            return false;
+        }
+
+        return clonedEntry.equals( other );
+    }
+    
+    
     public String toString()
     {
         return clonedEntry.toString();

Modified: directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java (original)
+++ directory/apacheds/trunk/core-integ/src/main/java/org/apache/directory/server/core/integ/state/AbstractState.java Tue Oct  7 04:26:55 2008
@@ -188,10 +188,13 @@
                 {
                     StringReader in = new StringReader( ldif );
                     LdifReader ldifReader = new LdifReader( in );
-                    LdifEntry entry = ldifReader.next();
                     
-                    service.getAdminSession().add( 
-                        new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) );
+                    for ( LdifEntry entry : ldifReader )
+                    {
+                        service.getAdminSession().add( 
+                            new DefaultServerEntry( service.getRegistries(), entry.getEntry() ) ); 
+                        LOG.debug( "Successfully injected LDIF enry for test {}: {}", settings.getDescription(), entry );
+                    }
                 }
                 catch ( Exception e )
                 {

Modified: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java?rev=702434&r1=702433&r2=702434&view=diff
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java (original)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/ReferralIT.java Tue Oct  7 04:26:55 2008
@@ -22,11 +22,13 @@
 
 import org.apache.directory.server.core.DirectoryService;
 import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
 import org.apache.directory.server.core.integ.CiRunner;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getSystemContext;
 import static org.apache.directory.server.core.integ.IntegrationUtils.getUserAddLdif;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
 import org.apache.directory.shared.ldap.exception.LdapNamingException;
+import org.apache.directory.shared.ldap.exception.LdapReferralException;
 import org.apache.directory.shared.ldap.ldif.LdifEntry;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.LdapDN;
@@ -45,6 +47,7 @@
 import javax.naming.NameNotFoundException;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.PartialResultException;
 import javax.naming.ReferralException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
@@ -101,7 +104,7 @@
 
         LdifEntry akarasulu = getUserAddLdif();
         service.getAdminSession().add( 
-            new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ) ); 
+            new DefaultServerEntry( service.getRegistries(), akarasulu.getEntry() ), true ); 
 
         // -------------------------------------------------------------------
         // Adds a referral entry regardless of referral handling settings
@@ -150,22 +153,22 @@
 
     private void checkAncestorReferrals( ReferralException e ) throws Exception
     {
-        assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
+        assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
         assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=apache,ou=users,dc=example,dc=com", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
+        assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=apache,ou=users,ou=system", e.getReferralInfo() );
         assertFalse( e.skipReferral() );
     }
 
 
     private void checkParentReferrals( ReferralException e ) throws Exception
     {
-        assertEquals( "ldap://fermi:10389", e.getReferralInfo() );
+        assertEquals( "ldap://fermi:10389/cn=alex%20karasulu,ou=users,ou=system", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
         assertEquals( "ldap://hertz:10389/cn=alex%20karasulu,ou=users,dc=example,dc=com", e.getReferralInfo() );
         assertTrue( e.skipReferral() );
-        assertEquals( "ldap://maxwell:10389", e.getReferralInfo() );
+        assertEquals( "ldap://maxwell:10389/cn=alex%20karasulu,ou=users,ou=system", e.getReferralInfo() );
         assertFalse( e.skipReferral() );
     }
 
@@ -239,6 +242,113 @@
 
 
     /**
+     * Checks for correct core behavior when Context.REFERRAL is set to <b>ignore</b>
+     * for an add operation with an ancestor context being a referral.
+     * 
+     * @throws Exception if something goes wrong.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorJNDIIgnore() throws Exception
+    {
+        addReferralEntry();
+
+        // -------------------------------------------------------------------
+        // Attempt to add a normal entry below the referral ancestor. We should
+        // encounter referral errors with referral setting set to throw.
+        // -------------------------------------------------------------------
+
+        td.refCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+        
+        Attributes userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "karasulu" );
+        userEntry.put( "cn", "alex karasulu" );
+
+        try
+        {
+            td.refCtx.createSubcontext( "cn=alex karasulu,ou=apache", userEntry );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( PartialResultException pre )
+        {
+            assertEquals( "cn=alex karasulu,ou=apache", ((LdapDN)pre.getRemainingName()).getUpName() );
+            assertEquals( LdapDN.EMPTY_LDAPDN, pre.getResolvedName() );
+        }
+    }
+
+
+    /**
+     * Checks for correct core behavior when Context.REFERRAL is set to <b>throw</b>
+     * for an add operation with an ancestor context being a referral.
+     * 
+     * @throws Exception if something goes wrong.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorJNDIThrow() throws Exception
+    {
+        addReferralEntry();
+
+        // -------------------------------------------------------------------
+        // Attempt to add a normal entry below the referral ancestor. We should
+        // encounter referral errors with referral setting set to throw.
+        // -------------------------------------------------------------------
+
+        td.refCtx.addToEnvironment( Context.REFERRAL, "throw" );
+        
+        Attributes userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "karasulu" );
+        userEntry.put( "cn", "alex karasulu" );
+
+        try
+        {
+            td.refCtx.createSubcontext( "cn=alex karasulu,ou=apache", userEntry );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( LdapReferralException lre )
+        {
+            assertEquals( "cn=alex karasulu,ou=apache", ((LdapDN)lre.getRemainingName()).getUpName() );
+            assertEquals( "ou=users,ou=system", ((LdapDN)lre.getResolvedName()).getUpName() );
+        }
+    }
+
+
+    /**
+     * Checks for correct core behavior when Context.REFERRAL is set to <b>ignore</b>
+     * for an add operation with an ancestor context being a referral.
+     * 
+     * @throws Exception if something goes wrong.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorProtocolWithManageDSAIT() throws Exception
+    {
+        addReferralEntry();
+
+        // -------------------------------------------------------------------
+        // Attempt to add a normal entry below the referral ancestor. We should
+        // encounter referral errors with referral setting set to throw.
+        // -------------------------------------------------------------------
+        LdapDN userDN = new LdapDN( "cn=alex karasulu,ou=apache,ou=users,ou=system" );
+        ServerEntry userEntry = new DefaultServerEntry( service.getRegistries(), userDN );
+        
+        userEntry.add(  "ObjectClass", "top", "person" );
+        userEntry.add( "sn", "karasulu" );
+        userEntry.add( "cn", "alex karasulu" );
+
+        try
+        {
+            service.getAdminSession().add( userEntry );
+            fail( "Should fail here throwing a ReferralException" );
+        }
+        catch ( PartialResultException pre )
+        {
+            assertEquals( "cn=alex karasulu,ou=apache", ((LdapDN)pre.getRemainingName()).getUpName() );
+            assertEquals( LdapDN.EMPTY_LDAPDN, pre.getResolvedName() );
+        }
+    }
+
+
+    /**
      * Checks for correct core behavoir when Context.REFERRAL is set to <b>throw</b>
      * for an delete operation with the parent context being a referral.
      * 
@@ -328,7 +438,8 @@
                 // abort the test because we're using the sun jdni provider
                 return;
             }
-            fail( "Should fail here throwing a ReferralException" );
+            
+            fail( "Should fail here throwing a PartialResultException" );
         }
         catch ( ReferralException e )
         {
@@ -338,7 +449,7 @@
 
 
     /**
-     * Checks for correct core behavoir when Context.REFERRAL is set to <b>throw</b>
+     * Checks for correct core behavior when Context.REFERRAL is set to <b>throw</b>
      * for a compare operation with an ancestor context being a referral.
      * 
      * @throws Exception if something goes wrong.
@@ -634,7 +745,7 @@
      * @throws Exception if something goes wrong.
      */
     @Test
-    public void testMoveWithReferralParent2() throws Exception
+    public void testMoveAndRenameWithReferralParent2() throws Exception
     {
         addReferralEntry();
 
@@ -665,7 +776,7 @@
      * @throws Exception if something goes wrong.
      */
     @Test
-    public void testMoveWithReferralAncestor2() throws Exception
+    public void testMoveAndRenameWithReferralAncestor2() throws Exception
     {
         addReferralEntry();
 
@@ -689,7 +800,7 @@
 
 
     /**
-     * Checks for correct core behavoir when Context.REFERRAL is set to <b>throw</b>
+     * Checks for correct core behavior when Context.REFERRAL is set to <b>throw</b>
      * for a move interceptor operation (corresponds to a subset of the modify 
      * dn operation) with the parent context being a referral.
      * 
@@ -705,8 +816,8 @@
         // resides below an parent which is a referral. We should encounter 
         // referral errors when referral setting is set to throw.
         // -------------------------------------------------------------------
-
         createLocalUser();
+
         td.rootCtx.addToEnvironment( Context.REFERRAL, "throw" );
         try
         {
@@ -760,7 +871,7 @@
      * @throws Exception if something goes wrong.
      */
     @Test
-    public void testMoveWithReferralParent2Dest() throws Exception
+    public void testMoveAndRenameWithReferralParent2Dest() throws Exception
     {
         addReferralEntry();
 
@@ -792,7 +903,7 @@
      * @throws Exception if something goes wrong.
      */
     @Test
-    public void testMoveWithReferralAncestor2Dest() throws Exception
+    public void testMoveAndRenameWithReferralAncestor2Dest() throws Exception
     {
         addReferralEntry();
 
@@ -818,7 +929,7 @@
 
     private void createLocalUser() throws Exception
     {
-        addReferralEntry();
+        //addReferralEntry();
 
         LdapContext userCtx;
         Attributes referral = new BasicAttributes( "objectClass", "top", true );
@@ -852,7 +963,7 @@
 
     private void createDeepLocalUser() throws Exception
     {
-        addReferralEntry();
+        //addReferralEntry();
 
         LdapContext userCtx = null;
         Attributes referral = new BasicAttributes( "objectClass", "top", true );
@@ -1065,9 +1176,7 @@
         oc.add( "referral" );
         attrs.put( oc );
         
-        Attribute ref = new BasicAttribute( "ref", "ldap://" );
-        attrs.put( ref );
-
+        attrs.put( "ref", "ldap://" );
         attrs.put( "cn", "refWithEmptyDN" );
 
         String base = "cn=refWithEmptyDN";

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/AddReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/AddReferralIT.java?rev=702434&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/AddReferralIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/AddReferralIT.java Tue Oct  7 04:26:55 2008
@@ -0,0 +1,318 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.jndi.referral;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
+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 java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.PartialResultException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the referral handling functionality for the Add operation 
+ * within the server's core.
+ * 
+ * All the tests are described on this page :
+ * http://cwiki.apache.org/confluence/display/DIRxSRVx11/Referral+Handling+Changes
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 691179 $
+ */
+@RunWith ( CiRunner.class )
+@CleanupLevel ( Level.CLASS )
+@ApplyLdifs( {
+    // Root
+    "dn: c=WW,ou=system\n" +
+    "objectClass: country\n" +
+    "objectClass: top\n" +
+    "c: WW\n\n" +
+    
+    // Sub-root
+    "dn: o=MNN,c=WW,ou=system\n" +
+    "objectClass: organization\n" +
+    "objectClass: top\n" +
+    "o: MNN\n\n" +
+    
+    // Referral #1
+    "dn: ou=Roles,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: Roles\n" +
+    "ref: ldap://hostd/ou=Roles,dc=apache,dc=org\n\n" +
+    
+    // Referral #2
+    "dn: ou=People,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: People\n" +
+    "ref: ldap://hostb/OU=People,DC=example,DC=com\n" +
+    "ref: ldap://hostc/OU=People,O=MNN,C=WW\n\n" +
+    
+    // Entry # 1
+    "dn: cn=Alex Karasulu,o=MNN,c=WW,ou=system\n" +
+    "objectClass: person\n" +
+    "objectClass: top\n" +
+    "cn: Alex Karasulu\n" +
+    "sn: akarasulu\n\n"
+    }
+)
+public class AddReferralIT
+{
+    /** The directory service */
+    public static DirectoryService service;
+
+    /** The Context we are using to inject entries with JNDI */
+    LdapContext MNNCtx;
+    
+    /** The entries we are using to do the tests */
+    Attributes userEntry;
+    ServerEntry serverEntry;
+    
+    @Before
+    public void setUp() throws Exception
+    {
+        MNNCtx = getContext( ServerDNConstants.ADMIN_SYSTEM_DN, service, "o=MNN,c=WW,ou=system" );
+
+        // JNDI entry
+        userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "elecharny" );
+        userEntry.put( "cn", "Emmanuel Lecharny" );
+        
+        // Core API entry
+        LdapDN dn = new LdapDN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
+        serverEntry = new DefaultServerEntry( service.getRegistries(), dn );
+
+        serverEntry.put( "ObjectClass", "top", "person" );
+        serverEntry.put( "sn", "elecharny" );
+        serverEntry.put( "cn", "Emmanuel Lecharny" );
+    }
+
+    
+    /**
+     * Test addition of a new entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testAddNewEntryNoReferralAncestorJNDI() throws Exception
+    {
+        DirContext eleCtx = MNNCtx.createSubcontext( "cn=Emmanuel Lecharny", userEntry );
+        
+        assertNotNull( eleCtx );
+        
+        Attributes attrs = eleCtx.getAttributes( "" );
+        assertNotNull( attrs );
+        
+        assertEquals( "Emmanuel Lecharny", attrs.get( "cn" ).get() );
+        assertEquals( "elecharny", attrs.get( "sn" ).get() );
+        Attribute attribute = attrs.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "person" ) );
+    }
+
+
+    /**
+     * Test addition of a new entry (not a referral), with a referral 
+     * in its ancestor, using JNDI 'ignore'.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorJNDIIgnore() throws Exception
+    {
+        // Set to 'ignore'
+        MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+        
+        try
+        {
+            MNNCtx.createSubcontext( "cn=Emmanuel Lecharny, ou=apache, ou=people", userEntry );
+            fail();
+        }
+        catch ( PartialResultException pre )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test addition of a new entry (not a referral), with a referral 
+     * in its ancestor, using the Core API with the ManageDsaIt flag set to true.
+     *   
+     * @throws Exception if something goes wrong.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorCoreAPImanageDsaIT() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            session.add( serverEntry, true );
+            fail();
+        }
+        catch ( PartialResultException pre )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test addition of a new entry (not a referral), with a referral 
+     * in its ancestor, using JNDI throw.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorJNDIThrow() throws Exception
+    {
+        // Set to 'throw'
+        MNNCtx.addToEnvironment( Context.REFERRAL, "throw" );
+        
+        try
+        {
+            MNNCtx.createSubcontext( "cn=Emmanuel Lecharny, ou=apache, ou=people", userEntry );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            assertTrue( true );
+            
+            int nbRefs = 0;
+            Set<String> peopleRefs = new HashSet<String>();
+            peopleRefs.add( "ldap://hostb/cn=Emmanuel%20Lecharny,%20ou=apache,OU=People,DC=example,DC=com" );
+            peopleRefs.add( "ldap://hostc/cn=Emmanuel%20Lecharny,%20ou=apache,OU=People,O=MNN,C=WW" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( peopleRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 2, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test addition of a new entry (not a referral), with a referral 
+     * in its ancestor, without the ManageDsaIt flag.
+     */
+    @Test
+    public void testAddNewEntryWithReferralAncestorCoreAPINoManageDsaIT() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+
+        try
+        {
+            session.add( serverEntry, false );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            assertTrue( true );
+            
+            int nbRefs = 0;
+            Set<String> peopleRefs = new HashSet<String>();
+            peopleRefs.add( "ldap://hostb/cn=Emmanuel%20Lecharny,%20ou=apache,OU=People,DC=example,DC=com" );
+            peopleRefs.add( "ldap://hostc/cn=Emmanuel%20Lecharny,%20ou=apache,OU=People,O=MNN,C=WW" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( peopleRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 2, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test addition of an existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testAddExistingEntryNoReferralAncestorJNDI() throws Exception
+    {
+        Attributes userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "elecharny" );
+        userEntry.put( "cn", "Emmanuel Lecharny" );
+
+        DirContext eleCtx = MNNCtx.createSubcontext( "cn=Emmanuel Lecharny", userEntry );
+        
+        assertNotNull( eleCtx );
+        
+        Attributes attributes = eleCtx.getAttributes( "" );
+        assertNotNull( attributes );
+        
+        assertEquals( "Emmanuel Lecharny", attributes.get( "cn" ).get() );
+        assertEquals( "elecharny", attributes.get( "sn" ).get() );
+        Attribute attribute = attributes.get( "objectClass" );
+        assertNotNull( attribute );
+        assertTrue( attribute.contains( "top" ) );
+        assertTrue( attribute.contains( "person" ) );
+
+        try
+        {
+            MNNCtx.createSubcontext( "cn=Emmanuel Lecharny", userEntry );
+            fail();
+        }
+        catch ( NameAlreadyBoundException nabe )
+        {
+            assertTrue( true );
+        }
+    }
+}

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/CompareReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/CompareReferralIT.java?rev=702434&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/CompareReferralIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/CompareReferralIT.java Tue Oct  7 04:26:55 2008
@@ -0,0 +1,427 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.jndi.referral;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingEnumeration;
+import javax.naming.PartialResultException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.directory.SearchControls;
+import javax.naming.directory.SearchResult;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the referral handling functionality for the Compare operation 
+ * within the server's core.
+ * 
+ * All the tests are described on this page :
+ * http://cwiki.apache.org/confluence/display/DIRxSRVx11/Referral+Handling+Changes
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 691179 $
+ */
+@RunWith ( CiRunner.class )
+@CleanupLevel ( Level.CLASS )
+@ApplyLdifs( {
+    // Root
+    "dn: c=WW,ou=system\n" +
+    "objectClass: country\n" +
+    "objectClass: top\n" +
+    "c: WW\n\n" +
+    
+    // Sub-root
+    "dn: o=MNN,c=WW,ou=system\n" +
+    "objectClass: organization\n" +
+    "objectClass: top\n" +
+    "o: MNN\n\n" +
+    
+    // Referral #1
+    "dn: ou=Roles,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: Roles\n" +
+    "ref: ldap://hostd/ou=Roles,dc=apache,dc=org\n\n" +
+    
+    // Referral #2
+    "dn: ou=People,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: People\n" +
+    "ref: ldap://hostb/OU=People,DC=example,DC=com\n" +
+    "ref: ldap://hostc/OU=People,O=MNN,C=WW\n\n" +
+    
+    // Entry # 1
+    "dn: cn=Alex Karasulu,o=MNN,c=WW,ou=system\n" +
+    "objectClass: person\n" +
+    "objectClass: top\n" +
+    "cn: Alex Karasulu\n" +
+    "sn: akarasulu\n\n"
+    }
+)
+public class CompareReferralIT
+{
+    /** The directory service */
+    public static DirectoryService service;
+
+    /** The Context we are using to inject entries with JNDI */
+    LdapContext MNNCtx;
+    
+    /** The entries we are using to do the tests */
+    Attributes userEntry;
+    ServerEntry serverEntry;
+    
+    /** The search controls used globally */
+    SearchControls ctls;
+    
+    @Before
+    public void setUp() throws Exception
+    {
+        MNNCtx = getContext( ServerDNConstants.ADMIN_SYSTEM_DN, service, "o=MNN,c=WW,ou=system" );
+
+        // JNDI entry
+        userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "elecharny" );
+        userEntry.put( "cn", "Emmanuel Lecharny" );
+        
+        // Core API entry
+        LdapDN dn = new LdapDN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
+        serverEntry = new DefaultServerEntry( service.getRegistries(), dn );
+
+        serverEntry.put( "ObjectClass", "top", "person" );
+        serverEntry.put( "sn", "elecharny" );
+        serverEntry.put( "cn", "Emmanuel Lecharny" );
+        
+        // Set up the search controls
+        ctls = new SearchControls();
+        ctls.setReturningAttributes( new String[0] );       // Return no attrs
+        ctls.setSearchScope( SearchControls.OBJECT_SCOPE ); // Search object only
+    }
+
+    
+    /**
+     * Test a compare on a non existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testCompareNonExistingEntry() throws Exception
+    {
+        try
+        {
+            // This is a compare operation, not a search, thanks to JNDI !
+            MNNCtx.search( "cn=Emmanuel Lecharny", "(cn=Emmanuel Lecharny)", ctls );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test a Compare on an entry with an ancestor referral, using JNDI,
+     * with 'throw'
+     */
+    @Test
+    public void testCompareEntryWithAncestorJNDIThrow() throws Exception
+    {
+        try
+        {
+            // Set to 'throw'
+            MNNCtx.addToEnvironment( Context.REFERRAL, "throw" );
+
+            // This is a compare operation, not a search, thanks to JNDI !
+            MNNCtx.search( "cn=Emmanuel Lecharny,ou=Roles", "(cn=Emmanuel Lecharny)", ctls );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test a Compare on an entry with an ancestor referral, using JNDI,
+     * with 'ignore'
+     */
+    @Test
+    public void testCompareEntryWithAncestorJNDIIgnore() throws Exception
+    {
+        try
+        {
+            // Set to 'throw'
+            MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+
+            // This is a compare operation, not a search, thanks to JNDI !
+            MNNCtx.search( "cn=Emmanuel Lecharny,ou=Roles", "(cn=Emmanuel Lecharny)", ctls );
+            fail();
+        }
+        catch ( PartialResultException pre )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test a compare on an entry with an ancestor referral, using the core API,
+     * without a ManageDsaIT.
+     */
+    @Test
+    public void testCompareEntryWithAncestorCoreAPIWithoutManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            session.compare( new LdapDN( "cn=Emmanuel Lecharny,ou=Roles,o=MNN,c=WW,ou=system" ), "cn", "Emmanuel Lecharny", false );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test a compare on an entry with an ancestor referral, using the core API,
+     * with a ManageDsaIT.
+     */
+    @Test
+    public void testCompareEntryWithAncestorCoreAPIWithManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            session.compare( new LdapDN( "cn=Emmanuel Lecharny,ou=Roles,o=MNN,c=WW,ou=system" ), "cn", "Emmanuel Lecharny", true );
+            fail();
+        }
+        catch ( PartialResultException pre )
+        {
+            assertTrue( true );
+        }
+    }
+
+    
+    /**
+     * Test a compare on an existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testCompareExistingEntryNoReferral() throws Exception
+    {
+        // This is a compare operation, not a search, thanks to JNDI !
+        NamingEnumeration<SearchResult> result = MNNCtx.search( "cn=Alex Karasulu", "(sn=akarasulu)", ctls );
+        
+        assertNotNull( result );
+
+        int nbResult = 0;
+        
+        while ( result.hasMore() )
+        {
+            SearchResult sr = ( SearchResult ) result.next();
+            
+            // The name should be empty
+            assertEquals( "", sr.getName() );
+            
+            // It should not have any attribute
+            assertEquals( 0, sr.getAttributes().size() );
+            nbResult++;
+        }
+        
+        // We should have only one result
+        assertEquals( 1, nbResult );
+    }
+
+    
+    /**
+     * Test a compare on an existing referral entry, using JNDI "throw".
+     */
+    @Test
+    public void testCompareExistingEntryReferralJNDIThrow() throws Exception
+    {
+        // Set to 'throw'
+        MNNCtx.addToEnvironment( DirContext.REFERRAL, "throw" );
+
+        try
+        {
+            // This is a compare operation, not a search, thanks to JNDI !
+            MNNCtx.search( "ou=roles", "(ou=roles)", ctls );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+    
+    /**
+     * Test a compare on an existing referral entry, using JNDI "ignore".
+     */
+    @Test
+    public void testCompareExistingEntryReferralJNDIIgnore() throws Exception
+    {
+        // Set to 'throw'
+        MNNCtx.addToEnvironment( DirContext.REFERRAL, "ignore" );
+
+        // This is a compare operation, not a search, thanks to JNDI !
+        NamingEnumeration<SearchResult> result = MNNCtx.search( "ou=roles", "(ou=roles)", ctls );
+
+        assertNotNull( result );
+
+        int nbResult = 0;
+        
+        while ( result.hasMore() )
+        {
+            SearchResult sr = ( SearchResult ) result.next();
+            
+            // The name should be empty
+            assertEquals( "", sr.getName() );
+            
+            // It should not have any attribute
+            assertEquals( 0, sr.getAttributes().size() );
+            nbResult++;
+        }
+        
+        // We should have only one result
+        assertEquals( 1, nbResult );
+    }
+
+    
+    /**
+     * Test a compare on an existing referral entry, using The core API
+     * and no ManageDsaIt flag.
+     */
+    @Test
+    public void testCompareExistingEntryReferralCoreAPIWithoutManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            session.compare( new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" ), "ou", "roles", false );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+    
+    /**
+     * Test a compare on an existing referral entry, using The core API
+     * with the ManageDsaIt flag.
+     */
+    @Test
+    public void testCompareExistingEntryReferralCoreAPIWithManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        assertTrue( session.compare( new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" ), "ou", "roles", true ) );
+    }
+}

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/DeleteReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/DeleteReferralIT.java?rev=702434&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/DeleteReferralIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/DeleteReferralIT.java Tue Oct  7 04:26:55 2008
@@ -0,0 +1,350 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.jndi.referral;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the referral handling functionality for the Delete operation 
+ * within the server's core.
+ * 
+ * All the tests are described on this page :
+ * http://cwiki.apache.org/confluence/display/DIRxSRVx11/Referral+Handling+Changes
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 691179 $
+ */
+@RunWith ( CiRunner.class )
+@CleanupLevel ( Level.CLASS )
+@ApplyLdifs( {
+    // Root
+    "dn: c=WW,ou=system\n" +
+    "objectClass: country\n" +
+    "objectClass: top\n" +
+    "c: WW\n\n" +
+    
+    // Sub-root
+    "dn: o=MNN,c=WW,ou=system\n" +
+    "objectClass: organization\n" +
+    "objectClass: top\n" +
+    "o: MNN\n\n" +
+    
+    // Referral #1
+    "dn: ou=Roles,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: Roles\n" +
+    "ref: ldap://hostd/ou=Roles,dc=apache,dc=org\n\n" +
+    
+    // Referral #2
+    "dn: ou=People,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: People\n" +
+    "ref: ldap://hostb/OU=People,DC=example,DC=com\n" +
+    "ref: ldap://hostc/OU=People,O=MNN,C=WW\n\n" +
+    
+    // Entry # 1
+    "dn: cn=Alex Karasulu,o=MNN,c=WW,ou=system\n" +
+    "objectClass: person\n" +
+    "objectClass: top\n" +
+    "cn: Alex Karasulu\n" +
+    "sn: akarasulu\n\n"
+    }
+)
+public class DeleteReferralIT
+{
+    /** The directory service */
+    public static DirectoryService service;
+
+    /** The Context we are using to inject entries with JNDI */
+    LdapContext MNNCtx;
+    
+    /** The entries we are using to do the tests */
+    Attributes userEntry;
+    ServerEntry serverEntry;
+    
+    @Before
+    public void setUp() throws Exception
+    {
+        MNNCtx = getContext( ServerDNConstants.ADMIN_SYSTEM_DN, service, "o=MNN,c=WW,ou=system" );
+
+        // JNDI entry
+        userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "elecharny" );
+        userEntry.put( "cn", "Emmanuel Lecharny" );
+        
+        // Core API entry
+        LdapDN dn = new LdapDN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
+        serverEntry = new DefaultServerEntry( service.getRegistries(), dn );
+
+        serverEntry.put( "ObjectClass", "top", "person" );
+        serverEntry.put( "sn", "elecharny" );
+        serverEntry.put( "cn", "Emmanuel Lecharny" );
+    }
+
+    
+    /**
+     * Test deletion of a non existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testDeleteNonExistingEntry() throws Exception
+    {
+        try
+        {
+            MNNCtx.destroySubcontext( "cn=Emmanuel Lecharny" );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry with an ancestor referral, using JNDI.
+     */
+    @Test
+    public void testDeleteEntryWithAncestorJNDI() throws Exception
+    {
+        try
+        {
+            MNNCtx.destroySubcontext( "cn=Emmanuel Lecharny,ou=Roles" );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry with an ancestor referral, using the core api.
+     */
+    @Test
+    public void testDeleteEntryWithAncestorCoreAPI() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            session.delete( new LdapDN( "cn=Emmanuel Lecharny,ou=Roles" ) );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test deletion of an existing entry with no ancestor referral, using the core api.
+     */
+    @Test
+    public void testDeleteExistingEntryNotReferral() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        LdapDN dn = new LdapDN( "cn=Alex Karasulu,o=MNN,c=WW,ou=system" );
+        
+        session.delete( dn );
+        
+        try
+        {
+            session.lookup( dn, new String[]{} );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry which is a referral an ancestor referral, 
+     * using JNDI, with 'throw'.
+     */
+    @Test
+    public void testDeleteExistingEntryReferralJNDIThrow() throws Exception
+    {
+        try
+        {
+            // Set to 'throw'
+            MNNCtx.addToEnvironment( Context.REFERRAL, "throw" );
+
+            MNNCtx.destroySubcontext( "ou=Roles" );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry which is a referral an ancestor referral, 
+     * using JNDI, with 'ignore'.
+     */
+    @Test
+    public void testDeleteExistingEntryReferralJNDIIgnore() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+
+        // Set to 'throw'
+        MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+
+        MNNCtx.destroySubcontext( "ou=Roles" );
+
+        LdapDN dn = new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" );
+        
+        // We should not find the entry
+        try
+        {
+            session.lookup( dn, new String[]{} );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry which is a referral an ancestor referral, 
+     * using the CoreAPI, without the ManageDsaIT control.
+     */
+    @Test
+    public void testDeleteExistingEntryReferralCoreAPINoManageDSAIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        LdapDN dn = new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" );
+
+        try
+        {
+            session.delete( dn, false );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test deletion of an entry which is a referral an ancestor referral, 
+     * using the CoreAPI, with the ManageDsaIT control.
+     */
+    @Test
+    public void testDeleteExistingEntryReferralCoreAPIManageDSAIT() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        LdapDN dn = new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" );
+
+        session.delete( dn, true );
+
+        // We should not find the entry
+        try
+        {
+            session.lookup( dn, new String[]{} );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+}

Added: directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/ModifyReferralIT.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/ModifyReferralIT.java?rev=702434&view=auto
==============================================================================
--- directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/ModifyReferralIT.java (added)
+++ directory/apacheds/trunk/core-integ/src/test/java/org/apache/directory/server/core/jndi/referral/ModifyReferralIT.java Tue Oct  7 04:26:55 2008
@@ -0,0 +1,437 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *  
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *  
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License. 
+ *  
+ */
+package org.apache.directory.server.core.jndi.referral;
+
+import static org.apache.directory.server.core.integ.IntegrationUtils.getContext;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.naming.Context;
+import javax.naming.NameNotFoundException;
+import javax.naming.PartialResultException;
+import javax.naming.ReferralException;
+import javax.naming.directory.Attribute;
+import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.BasicAttributes;
+import javax.naming.directory.DirContext;
+import javax.naming.ldap.LdapContext;
+
+import org.apache.directory.server.constants.ServerDNConstants;
+import org.apache.directory.server.core.CoreSession;
+import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.entry.DefaultServerEntry;
+import org.apache.directory.server.core.entry.ServerEntry;
+import org.apache.directory.server.core.integ.CiRunner;
+import org.apache.directory.server.core.integ.Level;
+import org.apache.directory.server.core.integ.annotations.ApplyLdifs;
+import org.apache.directory.server.core.integ.annotations.CleanupLevel;
+import org.apache.directory.shared.ldap.entry.Modification;
+import org.apache.directory.shared.ldap.entry.ModificationOperation;
+import org.apache.directory.shared.ldap.entry.client.ClientAttribute;
+import org.apache.directory.shared.ldap.entry.client.ClientModification;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
+import org.apache.directory.shared.ldap.name.LdapDN;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+
+/**
+ * Tests the referral handling functionality for the Modify operation 
+ * within the server's core.
+ * 
+ * All the tests are described on this page :
+ * http://cwiki.apache.org/confluence/display/DIRxSRVx11/Referral+Handling+Changes
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 691179 $
+ */
+@RunWith ( CiRunner.class )
+@CleanupLevel ( Level.CLASS )
+@ApplyLdifs( {
+    // Root
+    "dn: c=WW,ou=system\n" +
+    "objectClass: country\n" +
+    "objectClass: top\n" +
+    "c: WW\n\n" +
+    
+    // Sub-root
+    "dn: o=MNN,c=WW,ou=system\n" +
+    "objectClass: organization\n" +
+    "objectClass: top\n" +
+    "o: MNN\n\n" +
+    
+    // Referral #1
+    "dn: ou=Roles,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: Roles\n" +
+    "ref: ldap://hostd/ou=Roles,dc=apache,dc=org\n\n" +
+    
+    // Referral #2
+    "dn: ou=People,o=MNN,c=WW,ou=system\n" +
+    "objectClass: extensibleObject\n" +
+    "objectClass: referral\n" +
+    "objectClass: top\n" +
+    "ou: People\n" +
+    "ref: ldap://hostb/OU=People,DC=example,DC=com\n" +
+    "ref: ldap://hostc/OU=People,O=MNN,C=WW\n\n" +
+    
+    // Entry # 1
+    "dn: cn=Alex Karasulu,o=MNN,c=WW,ou=system\n" +
+    "objectClass: person\n" +
+    "objectClass: top\n" +
+    "cn: Alex Karasulu\n" +
+    "sn: akarasulu\n\n"
+    }
+)
+public class ModifyReferralIT
+{
+    /** The directory service */
+    public static DirectoryService service;
+
+    /** The Context we are using to inject entries with JNDI */
+    LdapContext MNNCtx;
+    
+    /** The entries we are using to do the tests */
+    Attributes userEntry;
+    ServerEntry serverEntry;
+    
+    @Before
+    public void setUp() throws Exception
+    {
+        MNNCtx = getContext( ServerDNConstants.ADMIN_SYSTEM_DN, service, "o=MNN,c=WW,ou=system" );
+
+        // JNDI entry
+        userEntry = new BasicAttributes( "objectClass", "top", true );
+        userEntry.get( "objectClass" ).add( "person" );
+        userEntry.put( "sn", "elecharny" );
+        userEntry.put( "cn", "Emmanuel Lecharny" );
+        
+        // Core API entry
+        LdapDN dn = new LdapDN( "cn=Emmanuel Lecharny, ou=apache, ou=people, o=MNN, c=WW, ou=system" );
+        serverEntry = new DefaultServerEntry( service.getRegistries(), dn );
+
+        serverEntry.put( "ObjectClass", "top", "person" );
+        serverEntry.put( "sn", "elecharny" );
+        serverEntry.put( "cn", "Emmanuel Lecharny" );
+    }
+
+    
+    /**
+     * Test modification of a non existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testModifyNonExistingEntry() throws Exception
+    {
+        try
+        {
+            Attribute description = new BasicAttribute( "description", "This is a description" );
+            Attributes attrs = new BasicAttributes( true );
+            attrs.put( description );
+            
+            MNNCtx.modifyAttributes( "cn=Emmanuel Lecharny", DirContext.ADD_ATTRIBUTE, attrs );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test a modification of an entry with an ancestor referral, using JNDI,
+     * with 'throw'
+     */
+    @Test
+    public void testModifyEntryWithAncestorJNDIThrow() throws Exception
+    {
+        try
+        {
+            // Set to 'throw'
+            MNNCtx.addToEnvironment( Context.REFERRAL, "throw" );
+
+            Attribute description = new BasicAttribute( "description", "This is a description" );
+            Attributes attrs = new BasicAttributes( true );
+            attrs.put( description );
+
+            MNNCtx.modifyAttributes( "cn=Emmanuel Lecharny,ou=Roles", DirContext.ADD_ATTRIBUTE, attrs );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/cn=Emmanuel%20Lecharny,ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+
+    /**
+     * Test a modification of an entry with an ancestor referral, using JNDI,
+     * with 'ignore'
+     */
+    @Test
+    public void testModifyEntryWithAncestorJNDIIgnore() throws Exception
+    {
+        try
+        {
+            // Set to 'throw'
+            MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+
+            Attribute description = new BasicAttribute( "description", "This is a description" );
+            Attributes attrs = new BasicAttributes( true );
+            attrs.put( description );
+
+            MNNCtx.modifyAttributes( "cn=Emmanuel Lecharny,ou=Roles", DirContext.ADD_ATTRIBUTE, attrs );
+            fail();
+        }
+        catch ( PartialResultException pre )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test the modification of an entry with an ancestor referral, using the core API,
+     * without a ManageDsaIT.
+     */
+    @Test
+    public void testModifyEntryWithAncestorCoreAPIWithoutManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            ClientAttribute attr = new DefaultClientAttribute( "Description", "this is a test" );
+            Modification mod = new ClientModification(
+                ModificationOperation.ADD_ATTRIBUTE, attr );
+            List<Modification> mods = new ArrayList<Modification>();
+            
+            mods.add( mod );
+            
+            session.modify( new LdapDN( "cn=Emmanuel Lecharny,ou=Roles,c=MNN,o=WW,ou=system" ), mods );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test the modification of an entry with an ancestor referral, using the core API,
+     * with a ManageDsaIT flag.
+     */
+    @Test
+    public void testModifyEntryWithAncestorCoreAPIWithManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            ClientAttribute attr = new DefaultClientAttribute( "Description", "this is a test" );
+            Modification mod = new ClientModification(
+                ModificationOperation.ADD_ATTRIBUTE, attr );
+            List<Modification> mods = new ArrayList<Modification>();
+            
+            mods.add( mod );
+            
+            session.modify( new LdapDN( "cn=Emmanuel Lecharny,ou=Roles,c=MNN,o=WW,ou=system" ), mods, true );
+            fail();
+        }
+        catch ( NameNotFoundException nnfe )
+        {
+            assertTrue( true );
+        }
+    }
+    
+    
+    /**
+     * Test modification of an existing entry (not a referral), with no referral 
+     * in its ancestor, using JNDI.
+     */
+    @Test
+    public void testModifyExistingEntryNoReferral() throws Exception
+    {
+        Attribute description = new BasicAttribute( "description", "This is a description" );
+        Attributes attrs = new BasicAttributes( true );
+        attrs.put( description );
+        
+        MNNCtx.modifyAttributes( "cn=Alex Karasulu", DirContext.ADD_ATTRIBUTE, attrs );
+        
+        // Now try to retrieve this attribute
+        Attributes result = MNNCtx.getAttributes( "cn=Alex Karasulu", new String[]{ "description" } );
+        
+        assertNotNull( result );
+        assertEquals( 1, result.size() );
+        assertEquals( "This is a description", result.get( "description" ).get() );
+    }
+
+    
+    /**
+     * Test modification of an existing referral entry, using JNDI "throw".
+     */
+    @Test
+    public void testModifyExistingEntryReferralJNDIThrow() throws Exception
+    {
+        Attribute description = new BasicAttribute( "description", "This is a description" );
+        Attributes attrs = new BasicAttributes( true );
+        attrs.put( description );
+        
+        try
+        {
+            MNNCtx.modifyAttributes( "ou=Roles", DirContext.ADD_ATTRIBUTE, attrs );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+    
+    /**
+     * Test modification of an existing referral entry, using JNDI "ignore".
+     */
+    @Test
+    public void testModifyExistingEntryReferralJNDIIgnore() throws Exception
+    {
+        Attribute description = new BasicAttribute( "description", "This is a description" );
+        Attributes attrs = new BasicAttributes( true );
+        attrs.put( description );
+        
+        MNNCtx.addToEnvironment( Context.REFERRAL, "ignore" );
+        
+        MNNCtx.modifyAttributes( "ou=Roles", DirContext.ADD_ATTRIBUTE, attrs );
+        
+        // Now try to retrieve this attribute
+        Attributes result = MNNCtx.getAttributes( "ou=Roles", new String[]{ "description" } );
+        
+        assertNotNull( result );
+        assertEquals( 1, result.size() );
+        assertEquals( "This is a description", result.get( "description" ).get() );
+    }
+
+    
+    /**
+     * Test modification of an existing referral entry, using the Core API 
+     * and no ManageDsaIT flag
+     */
+    @Test
+    public void testModifyExistingEntryReferralCoreAPIWithoutManageDsaIt() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        try
+        {
+            ClientAttribute attr = new DefaultClientAttribute( "Description", "this is a test" );
+            Modification mod = new ClientModification(
+                ModificationOperation.ADD_ATTRIBUTE, attr );
+            List<Modification> mods = new ArrayList<Modification>();
+            
+            mods.add( mod );
+            
+            session.modify( new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" ), mods, false );
+            fail();
+        }
+        catch ( ReferralException re )
+        {
+            int nbRefs = 0;
+            Set<String> expectedRefs = new HashSet<String>();
+            expectedRefs.add( "ldap://hostd/ou=Roles,dc=apache,dc=org" );
+            
+            do 
+            {
+                String ref = (String)re.getReferralInfo();
+                
+                assertTrue( expectedRefs.contains( ref ) );
+                nbRefs ++;
+            }
+            while ( re.skipReferral() );
+            
+            assertEquals( 1, nbRefs );
+        }
+    }
+
+    
+    /**
+     * Test modification of an existing referral entry, using the Core API 
+     * and the ManageDsaIT flag
+     */
+    @Test
+    public void testModifyExistingEntryReferralCoreAPIManageDsaIT() throws Exception
+    {
+        CoreSession session = service.getAdminSession();
+        
+        ClientAttribute attr = new DefaultClientAttribute( "Description", "This is a description" );
+        Modification mod = new ClientModification(
+            ModificationOperation.ADD_ATTRIBUTE, attr );
+        List<Modification> mods = new ArrayList<Modification>();
+        
+        mods.add( mod );
+        
+        session.modify( new LdapDN( "ou=Roles,o=MNN,c=WW,ou=system" ), mods, true );
+        
+        // Now try to retrieve this attribute
+        Attributes result = MNNCtx.getAttributes( "ou=Roles", new String[]{ "description" } );
+        
+        assertNotNull( result );
+        assertEquals( 1, result.size() );
+        assertEquals( "This is a description", result.get( "description" ).get() );
+    }
+}



Mime
View raw message