directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r675528 - /directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
Date Thu, 10 Jul 2008 11:33:26 GMT
Author: elecharny
Date: Thu Jul 10 04:33:25 2008
New Revision: 675528

URL: http://svn.apache.org/viewvc?rev=675528&view=rev
Log:
Added a test for DIRSERVER-1196
Minor refactoring

Modified:
    directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java

Modified: directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java?rev=675528&r1=675527&r2=675528&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
(original)
+++ directory/apacheds/branches/bigbang/server-unit/src/test/java/org/apache/directory/server/ModifyRdnTest.java
Thu Jul 10 04:33:25 2008
@@ -52,14 +52,13 @@
  */
 public class ModifyRdnTest extends AbstractServerTest
 {
-
     private LdapContext ctx = null;
 
 
     /**
      * Create attributes for a person entry.
      */
-    protected Attributes getPersonAttributes( String sn, String cn )
+    private Attributes getPersonAttributes( String sn, String cn )
     {
         Attributes attributes = new AttributesImpl();
         Attribute attribute = new AttributeImpl( "objectClass" );
@@ -77,7 +76,7 @@
     /**
      * Create attributes for a organizational unit entry.
      */
-    protected Attributes getOrganizationalUnitAttributes( String ou )
+    private Attributes getOrganizationalUnitAttributes( String ou )
     {
         Attributes attributes = new AttributesImpl();
         Attribute attribute = new AttributeImpl( "objectClass" );
@@ -538,6 +537,56 @@
 
 
     /**
+     * Test for DIRSERVER-1096.
+     * Modify the RDN of an entry with an escaped new RDN. 
+     * Ensure that the attribute itself contains the unescaped value.
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testModifyRdnWithEscapedPoundNewRdn() throws Exception
+    {
+        // Create a person "cn=Tori Amos", 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=Tori Amos to cn=\#test\+
+        ctx.addToEnvironment( "java.naming.ldap.deleteRDN", "true" );
+        String newRdn = "cn=\\23test";
+        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 newCtx = ( DirContext ) ctx.lookup( newRdn );
+        assertNotNull( newCtx );
+
+        // Check that the DN contains the escaped value
+        assertEquals( "cn=\\23test," + ctx.getNameInNamespace(), newCtx.getNameInNamespace()
);
+
+        // Check that cn contains the unescaped value
+        Attribute cn = newCtx.getAttributes( "" ).get( "cn" );
+        assertEquals( "Number of cn occurences", 1, cn.size() );
+        assertTrue( cn.contains( "\\#test" ) );
+
+        // Remove entry (use new rdn)
+        ctx.unbind( newRdn );
+    }
+
+
+    /**
      * Test for DIRSERVER-1162 and DIRSERVER-1085.
      * 
      * Modify single valued RDN to a multi valued RDN.
@@ -981,10 +1030,12 @@
     private String getRdn( Attributes attributes, String... rdnTypes ) throws NamingException
     {
         String rdn = "";
+        
         for ( String type : rdnTypes )
         {
             rdn += type + "=" + attributes.get( type ).get() + "+";
         }
+
         rdn = rdn.substring( 0, rdn.length() - 1 );
         return rdn;
     }
@@ -1007,5 +1058,4 @@
 
         return attributes;
     }
-
 }



Mime
View raw message