directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r357849 - in /directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name: DNParserTest.java LdapDNTest.java LdapRDNTest.java
Date Tue, 20 Dec 2005 00:05:12 GMT
Author: elecharny
Date: Mon Dec 19 16:05:06 2005
New Revision: 357849

URL: http://svn.apache.org/viewcvs?rev=357849&view=rev
Log:
- Fixed the tests that didn't worked
- Merged LdapName and LdapDN tests
- Merged DnParser and DNParser tests

All 190 are ok.

Modified:
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/DNParserTest.java
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java
    directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapRDNTest.java

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/DNParserTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/DNParserTest.java?rev=357849&r1=357848&r2=357849&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/DNParserTest.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/DNParserTest.java Mon Dec 19 16:05:06 2005
@@ -16,11 +16,14 @@
  */
 package org.apache.ldap.common.name;
 
-import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameParser;
+import javax.naming.NamingException;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
 
+import org.apache.asn1.codec.util.StringUtils;
 import org.apache.ldap.common.name.DNParser;
 import org.apache.ldap.common.name.LdapDN;
 
@@ -45,9 +48,9 @@
     /**
      * test an empty DN
      */
-    public void testLdapDNEmpty() throws InvalidNameException
+    public void testLdapDNEmpty() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
     	
         Assert.assertEquals( "", (( LdapDN )dnParser.parse( "" )).getName() );
     }
@@ -55,9 +58,9 @@
     /**
      * test a simple DN : a = b
      */
-    public void testLdapDNSimple() throws InvalidNameException
+    public void testLdapDNSimple() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
 
     	Assert.assertEquals( "a = b", (( LdapDN )dnParser.parse( "a = b" )).getName() );
         Assert.assertEquals( "a=b", (( LdapDN )dnParser.parse( "a = b" )).getString() );
@@ -66,9 +69,9 @@
     /**
      * test a composite DN : a = b, d = e
      */
-    public void testLdapDNComposite() throws InvalidNameException
+    public void testLdapDNComposite() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a = b, c = d" );
         Assert.assertEquals( "a=b,c=d", dn.toString() );
         Assert.assertEquals( "a = b, c = d", dn.getName() );
@@ -77,9 +80,9 @@
     /**
      * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a  =  b
      */
-    public void testLdapDNCompositeWithSpace() throws InvalidNameException
+    public void testLdapDNCompositeWithSpace() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a=b, a =b, a= b, a = b, a  =  b" );
         Assert.assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
         Assert.assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getName() );
@@ -89,9 +92,9 @@
      * test a composite DN with differents separators : a=b;c=d,e=f
      * It should return a=b,c=d,e=f (the ';' is replaced by a ',')
      */
-    public void testLdapDNCompositeSepators() throws InvalidNameException
+    public void testLdapDNCompositeSepators() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
     	LdapDN dn = ( LdapDN )dnParser.parse( "a=b;c=d,e=f" );
         Assert.assertEquals( "a=b,c=d,e=f", dn.toString() );
         Assert.assertEquals( "a=b;c=d,e=f", dn.getName() );
@@ -100,9 +103,9 @@
     /**
      * test a simple DN with multiple NameComponents : a = b + c = d
      */
-    public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
+    public void testLdapDNSimpleMultivaluedAttribute() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a = b + c = d" );
         Assert.assertEquals( "a=b+c=d", dn.toString() );
         Assert.assertEquals( "a = b + c = d", dn.getName() );
@@ -111,9 +114,9 @@
     /**
      * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h + i=j
      */
-    public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
+    public void testLdapDNCompositeMultivaluedAttribute() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a=b+c=d, e=f + g=h + i=j" );
         Assert.assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
         Assert.assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getName() );
@@ -122,9 +125,9 @@
     /**
      * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
      */
-    public void testLdapDNOidUpper() throws InvalidNameException
+    public void testLdapDNOidUpper() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "OID.12.34.56 = azerty" );
         Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
         Assert.assertEquals( "OID.12.34.56 = azerty", dn.getName() );
@@ -133,9 +136,9 @@
     /**
      * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
      */
-    public void testLdapDNOidLower() throws InvalidNameException
+    public void testLdapDNOidLower() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "oid.12.34.56 = azerty" );
         Assert.assertEquals( "oid.12.34.56=azerty", dn.toString() );
         Assert.assertEquals( "oid.12.34.56 = azerty", dn.getName() );
@@ -144,9 +147,9 @@
     /**
      * test a simple DN with an oid attribut without oid prefix : 12.34.56 = azerty
      */
-    public void testLdapDNOidWithoutPrefix() throws InvalidNameException
+    public void testLdapDNOidWithoutPrefix() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "12.34.56 = azerty" );
         Assert.assertEquals( "12.34.56=azerty", dn.toString() );
         Assert.assertEquals( "12.34.56 = azerty", dn.getName() );
@@ -155,9 +158,9 @@
     /**
      * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 = azerty; 7.8 = test
      */
-    public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
+    public void testLdapDNCompositeOidWithoutPrefix() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "12.34.56 = azerty; 7.8 = test" );
         Assert.assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
         Assert.assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getName() );
@@ -166,9 +169,9 @@
     /**
      * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\A0\00"
      */
-    public void testLdapDNPairCharAttributeValue() throws InvalidNameException
+    public void testLdapDNPairCharAttributeValue() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00" );
         Assert.assertEquals( "a=\\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00", dn.toString() );
         Assert.assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00", dn.getName() );
@@ -177,9 +180,9 @@
     /**
      * test a simple DN with hexString attribute value : a = #0010A0AAFF
      */
-    public void testLdapDNHexStringAttributeValue() throws InvalidNameException
+    public void testLdapDNHexStringAttributeValue() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a = #0010A0AAFF" );
         Assert.assertEquals( "a=#0010A0AAFF", dn.toString() );
         Assert.assertEquals( "a = #0010A0AAFF", dn.getName() );
@@ -188,9 +191,9 @@
     /**
      * test a simple DN with quoted attribute value : a = "quoted \"value"
      */
-    public void testLdapDNQuotedAttributeValue() throws InvalidNameException
+    public void testLdapDNQuotedAttributeValue() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "a = quoted \\\"value" );
         Assert.assertEquals( "a=quoted \\\"value", dn.toString() );
         Assert.assertEquals( "a = quoted \\\"value", dn.getName() );
@@ -200,32 +203,279 @@
      * Test the encoding of a LdanDN
      *
      */
-    public void testNameToBytes() throws Exception
+    public void testNameToBytes() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN dn = ( LdapDN )dnParser.parse( "cn = John, ou = People, OU = Marketing" );
         
         byte[] bytes = dn.getBytes();
         
         Assert.assertEquals( 30, dn.getNbBytes() );
-        Assert.assertEquals("cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
+        Assert.assertEquals("cn=John,ou=People,ou=Marketing", StringUtils.utf8ToString( bytes ) );
     }
     
-    public void testStringParser() throws Exception
+    public void testStringParser() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN name = ( LdapDN )dnParser.parse( "CN = Emmanuel  Lécharny" );
         
         Assert.assertEquals( "CN = Emmanuel  Lécharny", name.getName() );
         Assert.assertEquals( "cn=Emmanuel  Lécharny", name.toString() );
     }
 
-    public void testVsldapExtras() throws Exception
+    public void testVsldapExtras() throws NamingException
     {
-    	DNParser dnParser = new DNParser();
+    	NameParser dnParser = DNParser.getNameParser();
         LdapDN name = ( LdapDN )dnParser.parse( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas, ou=Search, o=IMC, c=US" );
         
         Assert.assertEquals( "cn=Billy Bakers, OID.2.5.4.11=Corporate Tax, ou=Fin-Accounting, ou=Americas, ou=Search, o=IMC, c=US", name.getName() );
         Assert.assertEquals( "cn=Billy Bakers,oid.2.5.4.11=Corporate Tax,ou=Fin-Accounting,ou=Americas,ou=Search,o=IMC,c=US", name.toString() );
+    }
+    
+    //~ Methods ----------------------------------------------------------------
+
+    /**
+     * Class under test for void DnParser()
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testDnParser() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        assertNotNull( parser );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringEmpty() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameEmpty = parser.parse( "" );
+
+        assertNotNull( nameEmpty );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringNull() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameNull = parser.parse( null );
+
+        assertEquals( "Null DN are legal : ", "", nameNull.toString() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC1779_1() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC1779_1 = parser.parse( "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California, C=US" );
+
+        assertEquals( "RFC1779_1 : ", "CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, ST=California, C=US", ((LdapDN)nameRFC1779_1).toUpName() );
+        assertEquals( "RFC1779_1 : ", "cn=Marshall T. Rose,o=Dover Beach Consulting,l=Santa Clara,st=California,c=US", nameRFC1779_1.toString() );
+    }
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_1() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_1 = parser.parse( "CN=Steve Kille,O=Isode limited,C=GB" );
+
+        assertEquals( "RFC2253_1 : ",
+                "CN=Steve Kille,O=Isode limited,C=GB",
+                ((LdapDN)nameRFC2253_1).toUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_2() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_2 = parser.parse( "CN = Sales + CN =   J. Smith , O = Widget Inc. , C = US" );
+
+        assertEquals( "RFC2253_2 : ",
+                "CN = Sales + CN =   J. Smith , O = Widget Inc. , C = US",
+                ((LdapDN)nameRFC2253_2).toUpName() );
+        assertEquals( "RFC2253_2 : ",
+                "cn=Sales+cn=J. Smith,o=Widget Inc.,c=US",
+                nameRFC2253_2.toString() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_3() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_3 = parser.parse( "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB" );
+
+        assertEquals( "RFC2253_3 : ", "CN=L. Eagle,   O=Sue\\, Grabbit and Runn, C=GB", ((LdapDN)nameRFC2253_3).toUpName() );
+        assertEquals( "RFC2253_3 : ", "cn=L. Eagle,o=Sue\\, Grabbit and Runn,c=GB", nameRFC2253_3.toString() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_4() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_4 = parser.parse( "CN=Before\\0DAfter,O=Test,C=GB" );
+        assertEquals( "RFC2253_4 : ", "CN=Before\\0DAfter,O=Test,C=GB", ((LdapDN)nameRFC2253_4).toUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_5() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_5 = parser.parse( "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB" );
+
+        assertEquals( "RFC2253_5 : ",
+                "1.3.6.1.4.1.1466.0=#04024869,O=Test,C=GB",
+                ((LdapDN)nameRFC2253_5).toUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseStringRFC2253_6() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        Name nameRFC2253_6 = parser.parse( "SN=Lu\\C4\\8Di\\C4\\87" );
+
+        assertEquals( "RFC2253_6 : ",
+                "SN=Lu\\C4\\8Di\\C4\\87",
+                ((LdapDN)nameRFC2253_6).toUpName() );
+    }
+
+
+    /**
+     * Class under test for Name parse(String)
+     *
+     * @throws NamingException if anything goes wrong
+     */
+    public final void testParseInvalidString() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+
+        try
+        {
+            parser.parse( "&#347;=&#347;rasulu,dc=example,dc=com" );
+            fail( "the invalid name should never succeed in a parse" );
+        }
+        catch ( Exception e )
+        {
+            assertNotNull(e);
+        }
+    }
+
+
+    /**
+     * Tests to see if inner whitespace is preserved after an escaped ',' in
+     * a value of a name component.  This test was added to try to reproduce
+     * the bug encountered in DIREVE-179 <a href="http://issues.apache.org/jira/browse/DIREVE-179">
+     * here</a>. 
+     *
+     * @throws NamingException if anything goes wrong on parse()
+     */
+    public final void testPreserveSpaceAfterEscape() throws NamingException
+    {
+    	NameParser parser = DNParser.getNameParser();
+        String input = "ou=some test\\,  something else";
+        String result = parser.parse( input ).toString();
+        assertEquals( input, result );
+    }
+    
+    public void testWindowsFilePath() throws Exception
+    {
+        // '\' should be escaped as stated in RFC 2253
+        String path = "windowsFilePath=C:\\\\cygwin";
+        NameParser parser = DNParser.getNameParser();
+        Name result = parser.parse( path );
+        assertEquals( path, ((LdapDN)result).toUpName() );
+        assertEquals( "windowsfilepath=C:\\\\cygwin", result.toString() );
+    }    
+    
+    public void testNameFrenchChars() throws Exception
+    {
+        String cn = new String(
+                new byte[] { 'c', 'n', '=', 0x4A, (byte) 0xC3, (byte) 0xA9, 0x72, (byte) 0xC3, (byte) 0xB4, 0x6D, 0x65 });
+
+        NameParser parser = DNParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+        
+        assertEquals( cn, result.toString() );
+
+    }
+
+    public void testNameGermanChars() throws Exception
+    {
+        String cn = new String(new byte[]{'c', 'n', '=', (byte)0xC3, (byte)0x84, (byte)0xC3, (byte)0x96, (byte)0xC3, 
+                    (byte)0x9C, (byte)0xC3, (byte)0x9F, (byte)0xC3, (byte)0xA4, (byte)0xC3, (byte)0xB6, (byte)0xC3, (byte)0xBC}, "UTF-8");
+        
+
+        NameParser parser = DNParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+        
+        assertEquals( cn, result.toString() );
+    }
+
+    public void testNameTurkishChars() throws Exception
+    {
+        String cn = new String(new byte[]{'c', 'n', '=', (byte)0xC4, (byte)0xB0, (byte)0xC4, (byte)0xB1, 
+                (byte)0xC5, (byte)0x9E, (byte)0xC5, (byte)0x9F, 
+                (byte)0xC3, (byte)0x96, (byte)0xC3, (byte)0xB6, 
+                (byte)0xC3, (byte)0x9C, (byte)0xC3, (byte)0xBC, 
+                (byte)0xC4, (byte)0x9E, (byte)0xC4, (byte)0x9F }, "UTF-8");
+
+        NameParser parser = DNParser.getNameParser();
+        String result = parser.parse( cn ).toString();
+        
+        assertEquals( cn, result.toString() );
+
     }
 }

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java?rev=357849&r1=357848&r2=357849&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapDNTest.java Mon Dec 19 16:05:06 2005
@@ -16,7 +16,13 @@
  */
 package org.apache.ldap.common.name;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 import javax.naming.InvalidNameException;
 import javax.naming.Name;
@@ -705,7 +711,7 @@
     public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
     {
         LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
-        Assert.assertEquals( true, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
+        Assert.assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
     }
 
     /**
@@ -769,7 +775,7 @@
     public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
     {
         LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
-        Assert.assertEquals( true, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
+        Assert.assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
     }
 
     /**
@@ -822,7 +828,7 @@
         Enumeration nc = dn.getAll();
         
         Assert.assertEquals( true, nc.hasMoreElements() );
-        Assert.assertEquals( "a=b", nc.nextElement() );
+        Assert.assertEquals( "a=b", nc.nextElement().toString() );
         Assert.assertEquals( false, nc.hasMoreElements() );
     }
     
@@ -835,11 +841,30 @@
         Enumeration nc = dn.getAll();
         
         Assert.assertEquals( true, nc.hasMoreElements() );
-        Assert.assertEquals( "c=d", nc.nextElement() );
+        Assert.assertEquals( "c=d", nc.nextElement().toString() );
         Assert.assertEquals( true, nc.hasMoreElements() );
-        Assert.assertEquals( "a=b", nc.nextElement() );
+        Assert.assertEquals( "a=b", nc.nextElement().toString() );
         Assert.assertEquals( true, nc.hasMoreElements() );
-        Assert.assertEquals( "e=f+g=h", nc.nextElement() );
+        Assert.assertEquals( "e=f+g=h", nc.nextElement().toString() );
+        Assert.assertEquals( false, nc.hasMoreElements() );
+    }
+    
+    /**
+     * test a getAll operation on a complex DN
+     */
+    public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
+        Enumeration nc = dn.getAll();
+        
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "c=d", nc.nextElement().toString() );
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "a=b", nc.nextElement().toString() );
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        
+        // The lowest atav should be the first one
+        Assert.assertEquals( "e=f+g=h", nc.nextElement().toString() );
         Assert.assertEquals( false, nc.hasMoreElements() );
     }
     
@@ -1048,9 +1073,932 @@
     
     public void testStringParser() throws Exception
     {
-        Name name = new DNParser().parse( "CN = Emmanuel  Lécharny" );
+        Name name = DNParser.getNameParser().parse( "CN = Emmanuel  Lécharny" );
         
         Assert.assertEquals( "CN = Emmanuel  Lécharny", ((LdapDN)name).getName() );
         Assert.assertEquals( "cn=Emmanuel  Lécharny", name.toString() );
+    }
+    
+    /**
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testHashCode() 
+        throws Exception
+    {
+        String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East" ;
+        Name name = new LdapDN( strName ) ;
+        assertEquals( name.hashCode(), strName.hashCode() ) ;
+    }
+
+
+    /**
+     * Class to test for void LdapName(String)
+     * @throws Exception if anything goes wrong.
+     */
+    public void testLdapNameString() 
+        throws Exception
+    {
+        Name name = new LdapDN( "" ) ;
+        Name name50 = new LdapDN() ; 
+        assertEquals( name50, name ) ;
+        
+        Name name0 = new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name copy =  new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+        Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" ) ;
+        Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" ) ;
+            
+        assertTrue( name0.compareTo( copy ) == 0 ) ;
+        assertTrue( name0.compareTo( name1 ) < 0 ) ;
+        assertTrue( name0.compareTo( name2 ) < 0 ) ;
+        assertTrue( name1.compareTo( name2 ) < 0 ) ;
+        assertTrue( name2.compareTo( name1 ) > 0 ) ;
+        assertTrue( name2.compareTo( name0 ) > 0 ) ;
+        assertTrue( name2.compareTo( name3 ) < 0 ) ;
+        assertTrue( name2.compareTo( name4 ) < 0 ) ;
+        assertTrue( name3.compareTo( name4 ) < 0 ) ;
+        assertTrue( name3.compareTo( name5 ) > 0 ) ;
+        assertTrue( name4.compareTo( name5 ) > 0 ) ;
+        assertTrue( name2.compareTo( name5 ) < 0 ) ;
+    }
+
+
+    /**
+     * Class to test for void LdapName()
+     */
+    public void testLdapName() 
+    {
+        Name name = new LdapDN() ;
+        assertTrue( name.toString().equals( "" ) ) ;
+    }
+
+
+    /**
+     * Class to test for void LdapName(List)
+     */
+    public void testLdapNameList() throws InvalidNameException
+    {
+        ArrayList list = new ArrayList() ;
+        list.add( "ou=People" ) ;
+        list.add( "dc=example" ) ;
+        list.add( "dc=com" ) ;
+        Name name = new LdapDN( list ) ;
+        assertTrue( name.toString().equals( 
+            "ou=People,dc=example,dc=com" ) ) ;
+    }
+
+
+    /**
+     * Class to test for void LdapName(Iterator)
+     */
+    public void testLdapNameIterator() throws InvalidNameException
+    {
+        ArrayList list = new ArrayList() ;
+        list.add( "ou=People" ) ;
+        list.add( "dc=example" ) ;
+        list.add( "dc=com" ) ;
+        Name name = new LdapDN( list.iterator() ) ;
+        assertTrue( name.toString().equals( 
+            "ou=People,dc=example,dc=com" ) ) ;
+    }
+
+
+    /**
+     * Class to test for Object clone()
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testClone()
+        throws Exception 
+    {
+        String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East" ;
+        Name name = new LdapDN( strName ) ;
+        assertEquals( name, name.clone() ) ;
+    }
+
+
+    /**
+     * Class to test for compareTo 
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testCompareTo()
+        throws Exception 
+    {
+        Name name0 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name copy = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name2 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name3 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+        Name name4 = 
+            new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" ) ;
+        Name name5 = 
+            new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" ) ;
+            
+        assertTrue( name0.compareTo( copy ) == 0 ) ;
+        assertTrue( name0.compareTo( name1 ) < 0 ) ;
+        assertTrue( name0.compareTo( name2 ) < 0 ) ;
+        assertTrue( name1.compareTo( name2 ) < 0 ) ;
+        assertTrue( name2.compareTo( name1 ) > 0 ) ;
+        assertTrue( name2.compareTo( name0 ) > 0 ) ;
+        assertTrue( name2.compareTo( name3 ) < 0 ) ;
+        assertTrue( name2.compareTo( name4 ) < 0 ) ;
+        assertTrue( name3.compareTo( name4 ) < 0 ) ;
+        assertTrue( name3.compareTo( name5 ) > 0 ) ;
+        assertTrue( name4.compareTo( name5 ) > 0 ) ;
+        assertTrue( name2.compareTo( name5 ) < 0 ) ;
+        
+        List list = new ArrayList() ;
+        
+        Comparator comparator = new Comparator()
+        {
+            public int compare( Object obj1, Object obj2 ) 
+            {
+                Name name1 = ( LdapDN ) obj1 ;
+                Name name2 = ( LdapDN ) obj2 ;
+                return name1.compareTo( name2 ) ;
+            }
+            
+            public boolean equals( Object obj ) 
+            {
+                return super.equals( obj ) ;
+            }
+            
+            
+            public int hashCode()
+            {
+                return super.hashCode() ;
+            }
+        } ;
+        
+        list.add( name0 ) ;
+        list.add( name1 ) ;
+        list.add( name2 ) ;
+        list.add( name3 ) ;
+        list.add( name4 ) ;
+        list.add( name5 ) ;
+        Collections.sort( list, comparator ) ;
+        
+        assertEquals( name0, list.get( 0 ) ) ;
+        assertEquals( name1, list.get( 1 ) ) ;
+        assertEquals( name2, list.get( 2 ) ) ;
+        assertEquals( name5, list.get( 3 ) ) ;
+        assertEquals( name3, list.get( 4 ) ) ;
+        assertEquals( name4, list.get( 5 ) ) ;
+    }
+
+
+    /**
+     * Class to test for size 
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testSize() 
+        throws Exception
+    {
+        Name name0 =
+            new LdapDN( "" ) ;
+        Name name1 =
+            new LdapDN( "ou=East" ) ;
+        Name name2 =
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name3 =
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name4 =
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name5 =
+            new LdapDN( 
+                "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+        Name name6 =
+            new LdapDN( 
+                "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West"
+                ) ;
+                
+        assertEquals( 0, name0.size() ) ;
+        assertEquals( 1, name1.size() ) ;
+        assertEquals( 2, name2.size() ) ;
+        assertEquals( 3, name3.size() ) ;
+        assertEquals( 4, name4.size() ) ;
+        assertEquals( 5, name5.size() ) ;
+        assertEquals( 6, name6.size() ) ;
+    }
+
+
+    /**
+     * Class to test for isEmpty 
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testIsEmpty() 
+        throws Exception
+    {
+        Name name0 =
+            new LdapDN( "" ) ;
+        Name name1 =
+            new LdapDN( "ou=East" ) ;
+        Name name2 =
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name3 =
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name4 =
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name5 =
+            new LdapDN( 
+                "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+        Name name6 =
+            new LdapDN( 
+                "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West"
+                ) ;
+                
+        assertEquals( true, name0.isEmpty() ) ;
+        assertEquals( false, name1.isEmpty() ) ;
+        assertEquals( false, name2.isEmpty() ) ;
+        assertEquals( false, name3.isEmpty() ) ;
+        assertEquals( false, name4.isEmpty() ) ;
+        assertEquals( false, name5.isEmpty() ) ;
+        assertEquals( false, name6.isEmpty() ) ;
+    }
+
+
+    /**
+     * Class to test for getSuffix
+     * @throws Exception if anything goes wrong. 
+     */
+    public void testGetAll() 
+        throws Exception
+    {
+        Name name0 = new LdapDN( "" ) ;
+        Name name1 = new LdapDN( "ou=East" ) ;
+        Name name2 = new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+        Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" ) ;
+                
+        Enumeration enum0 = name0.getAll() ;
+        assertEquals( false, enum0.hasMoreElements() ) ; 
+        
+        Enumeration enum1 = name1.getAll() ;
+        assertEquals( true, enum1.hasMoreElements() ) ;
+        
+        for ( int i = 0 ; enum1.hasMoreElements(); i++ ) 
+        {
+            LdapRDN element = ( LdapRDN ) enum1.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=East", element.toString() ) ;
+            }
+        }
+        
+        Enumeration enum2 = name2.getAll() ;
+        assertEquals( true, enum2.hasMoreElements() ) ; 
+        
+        for ( int i = 0 ; enum2.hasMoreElements(); i++ ) 
+        {
+        	LdapRDN element = ( LdapRDN ) enum2.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=East", element.toString() ) ;
+            }
+            
+            if ( i == 1 ) 
+            {
+                assertEquals( "ou=Marketing", element.toString() ) ;
+            }
+        }
+                
+        Enumeration enum3 = name3.getAll() ;
+        assertEquals( true, enum3.hasMoreElements() ) ; 
+        
+        for ( int i = 0 ; enum3.hasMoreElements(); i++ ) 
+        {
+        	LdapRDN element = ( LdapRDN ) enum3.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=East", element.toString() ) ;
+            }
+            
+            if ( i == 1 ) 
+            {
+                assertEquals( "ou=Marketing", element.toString() ) ;
+            }
+            
+            if ( i == 2 ) 
+            {
+                assertEquals( "cn=John", element.toString() ) ;
+            }
+        }
+        
+        Enumeration enum4 = name4.getAll() ;
+        assertEquals( true, enum4.hasMoreElements() ) ; 
+        
+        for ( int i = 0 ; enum4.hasMoreElements(); i++ ) 
+        {
+        	LdapRDN element = ( LdapRDN ) enum4.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=East", element.toString() ) ;
+            }
+            
+            if ( i == 1 ) 
+            {
+                assertEquals( "ou=Marketing", element.toString() ) ;
+            }
+            
+            if ( i == 2 ) 
+            {
+                assertEquals( "cn=John", element.toString() ) ;
+            }
+            
+            if ( i == 3 ) 
+            {
+                assertEquals( "cn=HomeDir", element.toString() ) ;
+            }
+        }
+        
+        Enumeration enum5 = name5.getAll() ;
+        assertEquals( true, enum5.hasMoreElements() ) ; 
+        
+        for ( int i = 0 ; enum5.hasMoreElements(); i++ ) 
+        {
+        	LdapRDN element = ( LdapRDN ) enum5.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=West", element.toString() ) ;
+            }
+            
+            if ( i == 1 ) 
+            {
+                assertEquals( "ou=Marketing", element.toString() ) ;
+            }
+            
+            if ( i == 2 ) 
+            {
+                assertEquals( "cn=John", element.toString() ) ;
+            }
+            
+            if ( i == 3 ) 
+            {
+                assertEquals( "cn=HomeDir", element.toString() ) ;
+            }
+            
+            if ( i == 4 ) 
+            {
+                assertEquals( "cn=Website", element.toString() ) ;
+            }
+        }
+                
+        Enumeration enum6 = name6.getAll() ;
+        assertEquals( true, enum6.hasMoreElements() ) ; 
+        
+        for ( int i = 0 ; enum6.hasMoreElements(); i++ ) 
+        {
+        	LdapRDN element = ( LdapRDN ) enum6.nextElement() ;
+            
+            if ( i == 0 ) 
+            {
+                assertEquals( "ou=West", element.toString() ) ;
+            }
+            
+            if ( i == 1 ) 
+            {
+                assertEquals( "ou=Marketing", element.toString() ) ;
+            }
+            
+            if ( i == 2 ) 
+            {
+                assertEquals( "cn=John", element.toString() ) ;
+            }
+            
+            if ( i == 3 ) 
+            {
+                assertEquals( "cn=HomeDir", element.toString() ) ;
+            }
+            
+            if ( i == 4 ) 
+            {
+                assertEquals( "cn=Website", element.toString() ) ;
+            }
+            
+            if ( i == 5 ) 
+            {
+                assertEquals( "cn=Airline", element.toString() ) ;
+            }
+        }
+    }
+
+
+    /**
+     * Class to test for get
+     * @throws Exception anything goes wrong
+     */
+    public void testGet() 
+        throws Exception
+    {
+        Name name = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        assertEquals( "cn=HomeDir", name.get( 3 ) ) ;
+        assertEquals( "cn=John", name.get( 2 ) ) ;
+        assertEquals( "ou=Marketing", name.get( 1 ) ) ;
+        assertEquals( "ou=East", name.get( 0 ) ) ;
+    }
+
+
+    /**
+     * Class to test for getSuffix
+     * @throws Exception anything goes wrong
+     */
+    public void testGetXSuffix()
+        throws Exception
+    {
+        Name name = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        assertEquals( "", name.getSuffix( 4 ).toString() ) ;
+        assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() ) ;
+        assertEquals( "cn=HomeDir,cn=John", 
+            name.getSuffix( 2 ).toString() ) ;
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing", 
+            name.getSuffix( 1 ).toString() ) ;
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", 
+            name.getSuffix( 0 ).toString() ) ;
+    }
+
+
+    /**
+     * Class to test for getPrefix
+     * @throws Exception anything goes wrong
+     */
+    public void testGetPrefix()
+        throws Exception
+    {
+        Name name = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", 
+            name.getPrefix( 4 ).toString() ) ;
+        assertEquals( "cn=John,ou=Marketing,ou=East", 
+            name.getPrefix( 3 ).toString() ) ;
+        assertEquals( "ou=Marketing,ou=East", 
+            name.getPrefix( 2 ).toString() ) ;
+        assertEquals( "ou=East", 
+            name.getPrefix( 1 ).toString() ) ;
+        assertEquals( "", 
+            name.getPrefix( 0 ).toString() ) ;
+    }
+
+    /**
+     * Class to test for startsWith
+     * @throws Exception anything goes wrong
+     */
+    public void testStartsWith()
+        throws Exception 
+    {
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name2 = 
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name3 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name4 = 
+            new LdapDN( "ou=East" ) ;
+        Name name5 = 
+            new LdapDN( "" ) ;
+
+        Name name6 = 
+            new LdapDN( "cn=HomeDir" ) ;
+        Name name7 = 
+            new LdapDN( "cn=HomeDir,cn=John" ) ;
+        Name name8 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" ) ;
+                        
+        assertTrue( name0.startsWith( name1 ) ) ;
+        assertTrue( name0.startsWith( name2 ) ) ;
+        assertTrue( name0.startsWith( name3 ) ) ;
+        assertTrue( name0.startsWith( name4 ) ) ;
+        assertTrue( name0.startsWith( name5 ) ) ;
+        
+        assertTrue( ! name0.startsWith( name6 ) ) ;
+        assertTrue( ! name0.startsWith( name7 ) ) ;
+        assertTrue( ! name0.startsWith( name8 ) ) ;
+    }
+
+
+    /**
+     * Class to test for endsWith
+     * @throws Exception anything goes wrong
+     */
+    public void testEndsWith() 
+        throws Exception 
+    {
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        Name name2 = 
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        Name name3 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name4 = 
+            new LdapDN( "ou=East" ) ;
+        Name name5 = 
+            new LdapDN( "" ) ;
+
+        Name name6 = 
+            new LdapDN( "cn=HomeDir" ) ;
+        Name name7 = 
+            new LdapDN( "cn=HomeDir,cn=John" ) ;
+        Name name8 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" ) ;
+                        
+        assertTrue( name0.endsWith( name1 ) ) ;
+        assertTrue( ! name0.endsWith( name2 ) ) ;
+        assertTrue( ! name0.endsWith( name3 ) ) ;
+        assertTrue( ! name0.endsWith( name4 ) ) ;
+        assertTrue( name0.endsWith( name5 ) ) ;
+        
+        assertTrue( name0.endsWith( name6 ) ) ;
+        assertTrue( name0.endsWith( name7 ) ) ;
+        assertTrue( name0.endsWith( name8 ) ) ;
+
+        /*
+        Hashtable env = new Hashtable() ;
+        env.put( Context.SECURITY_AUTHENTICATION, "simple" ) ;
+        env.put( Context.SECURITY_PRINCIPAL, "cn=admin,dc=example,dc=com" ) ;
+        env.put( Context.SECURITY_CREDENTIALS, "jPasswordField1" ) ;
+        env.put( Context.INITIAL_CONTEXT_FACTORY, 
+            "com.sun.jndi.ldap.LdapCtxFactory" ) ;
+        env.put( Context.PROVIDER_URL, 
+            "ldap://localhost:1396/dc=example,dc=com" ) ;
+        DirContext ctx = new InitialDirContext( env ) ;
+        NamingEnumeration enum = ctx.listBindings( "" ) ;
+        Name name0 = 
+            new LdapDN( "ou=Special Users,dc=example,dc=com" ) ;
+        Name name1 = 
+            new LdapDN( "dc=example,dc=com" ) ;
+        Name name2 = 
+            new LdapDN( "dc=com" ) ;
+        Name name3 = 
+            new LdapDN( "ou=Special Users" ) ;
+        Name name4 = 
+            new LdapDN( "ou=Special Users,dc=example" ) ;
+        Name name5 = 
+            new LdapDN( "" ) ;
+        while ( enum.hasMore() )
+        {
+            Binding binding = ( Binding ) enum.next() ;
+            DirContext dirCtx = ( DirContext ) binding.getObject() ;
+            NameParser parser = dirCtx.getNameParser( "" ) ;
+            Name namex = parser.parse( dirCtx.getNameInNamespace() ) ;
+            // DirContext dirCtx = ( DirContext ) enum.next() ;
+        }
+        */
+    }
+
+
+    /**
+     * Class to test for Name addAll(Name)
+     * @throws Exception when anything goes wrong
+     */
+    public void testAddAllName0()
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        assertTrue( name0.equals( name.addAll( name0 ) ) ) ;
+    }
+
+    /**
+     * Class to test for Name addAll(Name)
+     * @throws Exception when anything goes wrong
+     */
+    public void testAddAllNameExisting0()
+        throws Exception 
+    {
+        Name name1 = new LdapDN( "ou=Marketing,ou=East" );
+        Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
+        Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
+        assertTrue( nameAdded.equals( name1.addAll( name2 ) ) ) ;
+    }
+
+
+    /**
+     * Class to test for Name addAll(Name)
+     * @throws Exception when anything goes wrong
+     */
+    public void testAddAllName1()
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        Name name0 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=HomeDir,cn=John" ) ;
+        Name name2 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+            
+        assertTrue( name0.equals( name.addAll( name0 ) ) ) ;
+        assertTrue( name2.equals( name.addAll( name1 ) ) ) ;
+    }
+    
+    
+    /**
+     * Class to test for Name addAll(int, Name)
+     * @throws Exception when something goes wrong
+     */
+    public void testAddAllintName0()
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        Name name0 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=HomeDir,cn=John" ) ;
+        Name name2 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+            
+        assertTrue( name0.equals( name.addAll( name0 ) ) ) ;
+        assertTrue( name2.equals( name.addAll( 2, name1 ) ) ) ;
+    }
+
+
+    /**
+     * Class to test for Name addAll(int, Name)
+     * @throws Exception when something goes wrong
+     */
+    public void testAddAllintName1()
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" ) ;
+        Name name1 = 
+            new LdapDN( "cn=John" ) ;
+        Name name2 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+            
+        assertTrue( name0.equals( name.addAll( name0 ) ) ) ;
+        assertTrue( name2.equals( name.addAll( 2, name1 ) ) ) ;
+
+        Name name3 = 
+            new LdapDN( "cn=Airport" ) ;
+        Name name4 = 
+            new LdapDN( 
+            "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+            
+        assertTrue( name4.equals( name.addAll( 4, name3 ) ) ) ;
+
+        Name name5 = 
+            new LdapDN( "cn=ABC123" ) ;
+        Name name6 = 
+            new LdapDN( 
+            "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" ) ;
+        
+        assertTrue( name6.equals( name.addAll( 3, name5 ) ) ) ;
+    }
+
+
+    /**
+     * Class to test for Name add(String)
+     * @throws Exception when something goes wrong
+     */
+    public void testAddString()
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        assertEquals( name, new LdapDN( "" ) ) ;
+        
+        Name name4 = 
+            new LdapDN( "ou=East" ) ;
+        name.add( "ou=East" ) ;
+        assertEquals( name4, name ) ;
+
+        Name name3 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        name.add( "ou=Marketing" ) ;
+        assertEquals( name3, name ) ;
+         
+        Name name2 = 
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        name.add( "cn=John" ) ;
+        assertEquals( name2, name ) ;
+
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        name.add( "cn=HomeDir" ) ;
+        assertEquals( name0, name ) ;
+    }
+
+
+    /**
+     * Class to test for Name add(int, String)
+     * @throws Exception if anything goes wrong
+     */
+    public void testAddintString() 
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        assertEquals( name, new LdapDN( "" ) ) ;
+        
+        Name name4 = 
+            new LdapDN( "ou=East" ) ;
+        name.add( "ou=East" ) ;
+        assertEquals( name4, name ) ;
+
+        Name name3 = 
+            new LdapDN( "ou=Marketing,ou=East" ) ;
+        name.add( 1, "ou=Marketing" ) ;
+        assertEquals( name3, name ) ;
+         
+        Name name2 = 
+            new LdapDN( "cn=John,ou=Marketing,ou=East" ) ;
+        name.add( 2, "cn=John" ) ;
+        assertEquals( name2, name ) ;
+
+        Name name0 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" ) ;
+        name.add( 3, "cn=HomeDir" ) ;
+        assertEquals( name0, name ) ;
+        
+        Name name5 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL "
+                + "Bean Inc." ) ;
+        name.add( 0, "o=LL Bean Inc." ) ;
+        assertEquals( name5, name ) ;
+        
+        Name name6 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL "
+                + "Bean Inc." ) ;
+        name.add( 1, "c=US" ) ;
+        assertEquals( name6, name ) ;
+        
+        Name name7 = 
+            new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing,"
+                + "ou=East,c=US,o=LL "
+                + "Bean Inc." ) ;
+        name.add( 4, "ou=Advertising" ) ;
+        assertEquals( name7, name ) ;
+    }
+
+
+    /**
+     * Class to test for remove
+     * @throws Exception if anything goes wrong
+     */
+    public void testRemove() 
+        throws Exception 
+    {
+        Name name = new LdapDN() ;
+        assertEquals( new LdapDN( "" ), name ) ;
+            
+        Name name3 =
+            new LdapDN( "ou=Marketing" ) ;
+        name.add( "ou=East" ) ;
+        name.add( 1, "ou=Marketing" ) ;
+        name.remove( 0 ) ;
+        assertEquals( name3, name ) ;
+             
+        Name name2 = 
+            new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" ) ;
+        name.add( 0, "ou=East" ) ;
+        name.add( 2, "cn=John" ) ;
+        name.add( "cn=HomeDir" ) ;
+        name.remove( 2 ) ;
+        assertEquals( name2, name ) ;
+
+        name.remove( 1 ) ;
+        Name name1 = 
+            new LdapDN( "cn=HomeDir,ou=East" ) ;
+        assertEquals( name1, name ) ;
+            
+        name.remove( 1 ) ;
+        Name name0 = 
+            new LdapDN( "ou=East" ) ;
+        assertEquals( name0, name ) ;
+        
+        name.remove( 0 ) ;
+        assertEquals( new LdapDN( "" ), name ) ;
+    }
+
+
+    /**
+     * Class to test for String toString()
+     * @throws Exception if anything goes wrong
+     */
+    public void testToString()
+        throws Exception  
+    {
+        Name name = new LdapDN() ;
+        assertEquals( "", name.toString() ) ;
+        
+        name.add( "ou=East" ) ;
+        assertEquals( "ou=East", name.toString() ) ;
+        
+        name.add( 1, "ou=Marketing" ) ;
+        assertEquals( "ou=Marketing,ou=East", name.toString() ) ;
+
+        name.add( "cn=John" ) ;
+        assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() ) ;
+
+        name.add( "cn=HomeDir" ) ;
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", 
+            name.toString() ) ;
+    }
+
+
+    /**
+     * Class to test for boolean equals(Object)
+     * @throws Exception if anything goes wrong
+     */
+    public void testEqualsObject()
+        throws Exception 
+    {
+        assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) ) ;
+        
+        assertTrue( ! new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) ) ; 
+        assertTrue( ! new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) ) ; 
+        assertTrue( ! new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) ) ; 
+    }
+
+
+    public void testNameFrenchChars() throws Exception
+    {
+        String cn = new String(
+                new byte[] { 'c', 'n', '=', 0x4A, (byte) 0xC3, (byte) 0xA9, 0x72, (byte) 0xC3, (byte) 0xB4, 0x6D, 0x65 });
+
+        Name name = new LdapDN( cn);
+        
+        assertEquals( cn, name.toString() );
+    }
+
+    public void testNameGermanChars() throws Exception
+    {
+        String cn = new String(new byte[]{'c', 'n', '=', (byte)0xC3, (byte)0x84, (byte)0xC3, (byte)0x96, (byte)0xC3, 
+                    (byte)0x9C, (byte)0xC3, (byte)0x9F, (byte)0xC3, (byte)0xA4, (byte)0xC3, (byte)0xB6, (byte)0xC3, (byte)0xBC}, "UTF-8");
+
+        Name name = new LdapDN( cn );
+        
+        assertEquals( cn, name.toString() );
+    }
+
+    public void testNameTurkishChars() throws Exception
+    {
+        String cn = new String(new byte[]{'c', 'n', '=', (byte)0xC4, (byte)0xB0, (byte)0xC4, (byte)0xB1, 
+                (byte)0xC5, (byte)0x9E, (byte)0xC5, (byte)0x9F, 
+                (byte)0xC3, (byte)0x96, (byte)0xC3, (byte)0xB6, 
+                (byte)0xC3, (byte)0x9C, (byte)0xC3, (byte)0xBC, 
+                (byte)0xC4, (byte)0x9E, (byte)0xC4, (byte)0x9F }, "UTF-8");
+
+        Name name = new LdapDN( cn);
+        
+        assertEquals( cn, name.toString() );
+    }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOid() throws Exception
+    {
+        ArrayList list = new ArrayList() ;
+        list.add( "ou=People" ) ;
+        list.add( "dc=example" ) ;
+        list.add( "dc=com" ) ;
+        Name name = new LdapDN( list.iterator() ) ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        Name result = LdapDN.toOidName( name, oids );
+        
+        assertTrue( result.toString().equals( 
+            "2.5.4.11=People,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) ) ;
+    }
+
+    /**
+     * Class to test for toOid( Name, Map)
+     */
+    public void testLdapNameToOidEmpty() throws Exception
+    {
+        Name name = new LdapDN() ;
+        
+        Map oids = new HashMap();
+        
+        oids.put( "dc", "0.9.2342.19200300.100.1.25" );
+        oids.put( "ou", "2.5.4.11" );
+        
+        Name result = LdapDN.toOidName( name, oids );
+        assertTrue( result.toString().equals( "" ) ) ;
     }
 }

Modified: directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapRDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapRDNTest.java?rev=357849&r1=357848&r2=357849&view=diff
==============================================================================
--- directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapRDNTest.java (original)
+++ directory/shared/ldap/branches/DN-refactoring/common/src/test/org/apache/ldap/common/name/LdapRDNTest.java Mon Dec 19 16:05:06 2005
@@ -238,23 +238,13 @@
     }
 
     /**
-     * Test the compareTo method for a RDN.
-     */
-    public void testRDNCompareToNC2Null() throws InvalidNameException
-    {
-        LdapRDN rdn1 = new LdapRDN( " a = b + c = d + a = f + g = h " );
-        LdapRDN rdn2 = new LdapRDN( " a = b " );
-        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
-    }
-    
-    /**
      * Compares a composite NC to a single NC.
      */
     public void testRDNCompareToNCS2NC() throws InvalidNameException
     {
         LdapRDN rdn1 = new LdapRDN( " a = b + c = d + a = f + g = h " );
         LdapRDN rdn2 = new LdapRDN( " a = b " );
-        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+        Assert.assertTrue( rdn1.compareTo( rdn2 ) > 0);
     }
 
     /**
@@ -265,7 +255,7 @@
         LdapRDN rdn1 = new LdapRDN( " a = b " );
         LdapRDN rdn2 = new LdapRDN( " a = b + c = d + a = f + g = h " );
 
-        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+        Assert.assertTrue( rdn1.compareTo( rdn2 ) < 0 );
     }
 
     /**
@@ -318,7 +308,7 @@
     public void testRDNCompareToNC2NCUperCase() throws InvalidNameException
     {
         LdapRDN rdn1 = new LdapRDN( " a = b " );
-        LdapRDN rdn2 = new LdapRDN( " A = B " );
+        LdapRDN rdn2 = new LdapRDN( " A = b " );
 
         Assert.assertEquals( LdapRDN.EQUALS, rdn1.compareTo( rdn2 ) );
     }
@@ -331,7 +321,7 @@
         LdapRDN rdn1 = new LdapRDN( " a = b " );
         LdapRDN rdn2 = new LdapRDN( " A = d " );
 
-        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+        Assert.assertTrue( rdn1.compareTo( rdn2 ) < 0 );
     }
 }
 



Mime
View raw message