directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r264048 - in /directory/apacheds/trunk: core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java main/src/test/org/apache/ldap/server/ModifyRdnTest.java
Date Mon, 29 Aug 2005 03:53:25 GMT
Author: akarasulu
Date: Sun Aug 28 20:53:17 2005
New Revision: 264048

URL: http://svn.apache.org/viewcvs?rev=264048&view=rev
Log:
Adding Stefan's test case from JIRA issue DIREVE-173 here:

http://issues.apache.org/jira/browse/DIREVE-173

As well as the fix for it.  Thanks Stefan!!!!

Modified:
    directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java
    directory/apacheds/trunk/main/src/test/org/apache/ldap/server/ModifyRdnTest.java

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java?rev=264048&r1=264047&r2=264048&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/ldap/server/partition/impl/btree/jdbm/JdbmContextPartition.java
Sun Aug 28 20:53:17 2005
@@ -1298,7 +1298,13 @@
         {
             rdnAttr = new LockableAttributeImpl( newRdnAttr );
         }
-        rdnAttr.add( newRdnValue );
+
+        // add the new Rdn value only if it is not already present in the entry
+        if ( ! rdnAttr.contains( newRdnValue ) )
+        {
+            rdnAttr.add( newRdnValue );
+        }
+
         entry.put( rdnAttr );
         
         if ( hasUserIndexOn( newRdnAttr ) )

Modified: directory/apacheds/trunk/main/src/test/org/apache/ldap/server/ModifyRdnTest.java
URL: http://svn.apache.org/viewcvs/directory/apacheds/trunk/main/src/test/org/apache/ldap/server/ModifyRdnTest.java?rev=264048&r1=264047&r2=264048&view=diff
==============================================================================
--- directory/apacheds/trunk/main/src/test/org/apache/ldap/server/ModifyRdnTest.java (original)
+++ directory/apacheds/trunk/main/src/test/org/apache/ldap/server/ModifyRdnTest.java Sun Aug
28 20:53:17 2005
@@ -28,10 +28,12 @@
 import javax.naming.ldap.InitialLdapContext;
 import javax.naming.ldap.LdapContext;
 
+import junit.framework.TestCase;
+
 /**
- * Testcase for DIREVE-173. Different modify DN operations on a person entry.
+ * Testcase with different modify DN operations on a person entry.
+ * Originally created to demonstrate DIREVE-173.
  * 
- * @author szoerner
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
@@ -40,6 +42,9 @@
 
     private LdapContext ctx = null;
 
+    /**
+     * Create attributes for a person entry.
+     */
     protected Attributes getPersonAttributes(String sn, String cn)
     {
         Attributes attributes = new BasicAttributes();
@@ -55,7 +60,7 @@
     }
 
     /**
-     * Create an entry for a person.
+     * Create context
      */
     public void setUp() throws Exception
     {
@@ -85,7 +90,7 @@
     }
 
     /**
-     * Just a little test to check wether opening the connection succeds.
+     * Just a little test to check wether opening the connection succeeds.
      */
     public void testSetUpTearDown() throws NamingException
     {
@@ -127,7 +132,7 @@
         // Check values of cn
         Attribute cn = tori.getAttributes("").get("cn");
         assertTrue(cn.contains(newCn));
-        assertTrue(!cn.contains(oldCn)); // old vaue is gone
+        assertTrue(!cn.contains(oldCn)); // old value is gone
         assertEquals(1, cn.size());
 
         // Remove entry (use new rdn)
@@ -169,7 +174,7 @@
         // Check values of cn
         Attribute cn = tori.getAttributes("").get("cn");
         assertTrue(cn.contains(newCn));
-        assertTrue(cn.contains(oldCn)); // old vaue is still there
+        assertTrue(cn.contains(oldCn)); // old value is still there
         assertEquals(2, cn.size());
 
         // Remove entry (use new rdn)
@@ -223,6 +228,50 @@
         assertTrue(cn.contains(alternateCn)); // alternate value is still available
         assertEquals(2, cn.size());
 
+        // Remove entry (use new rdn)
+        ctx.unbind(newRdn);
+    }
+    
+    /**
+     * Modify DN of an entry, changing RDN from cn to sn.
+     * 
+     * @throws NamingException
+     */
+    public void testModifyRdnDifferentAttribute() throws NamingException {
+
+        // Create a person, cn value is rdn
+        String cnVal = "Tori Amos";
+        String snVal = "Amos";
+        String oldRdn = "cn=" + cnVal;
+        Attributes attributes = this.getPersonAttributes(snVal, cnVal);
+        ctx.createSubcontext(oldRdn, attributes);
+
+        // modify Rdn from cn=... to sn=...
+        String newRdn = "sn=" + snVal;
+        ctx.addToEnvironment("java.naming.ldap.deleteRDN", "false");
+        ctx.rename(oldRdn, newRdn);
+
+        // Check, whether old Entry does not exists
+        try {
+            ctx.lookup(oldRdn);
+            fail("Entry must not exist");
+        } catch (NameNotFoundException ignored) {
+            // expected behaviour
+        }
+
+        // Check, whether new Entry exists
+        DirContext tori = (DirContext) ctx.lookup(newRdn);
+        assertNotNull(tori);
+
+        // Check values of cn and sn
+        // especially the number of cn and sn occurences
+        Attribute cn = tori.getAttributes("").get("cn");
+        assertTrue(cn.contains(cnVal));
+        assertEquals("Number of cn occurences", 1, cn.size());
+        Attribute sn = tori.getAttributes("").get("sn");
+        assertTrue(sn.contains(snVal));
+        assertEquals("Number of sn occurences", 1, sn.size());
+        
         // Remove entry (use new rdn)
         ctx.unbind(newRdn);
     }



Mime
View raw message