directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r617816 [2/2] - in /directory: apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/jndi/ apacheds/branches/bigbang/core/src/main/java/org/apache/directory/server/core/operational/ shared/branches/bigbang/ldap/src/m...
Date Sat, 02 Feb 2008 15:43:13 GMT
Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java?rev=617816&r1=617815&r2=617816&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/name/RdnTest.java
Sat Feb  2 07:43:12 2008
@@ -32,13 +32,16 @@
 import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
 
-import junit.framework.Assert;
-import junit.framework.TestCase;
-
 import org.apache.directory.shared.ldap.name.Rdn;
 import org.apache.directory.shared.ldap.name.RdnParser;
 import org.apache.directory.shared.ldap.util.StringTools;
+
 import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 
 /**
@@ -46,482 +49,528 @@
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class RdnTest extends TestCase
+public class RdnTest
 {
-   // ~ Methods
-   // ------------------------------------------------------------------------------------
-   /**
-    * Test a null RDN
-    */
-   public void testRdnNull()
-   {
-       Assert.assertEquals( "", new Rdn().toString() );
-   }
-
-
-   /**
-    * test an empty RDN
-    */
-   public void testRdnEmpty() throws InvalidNameException
-   {
-       Assert.assertEquals( "", new Rdn( "" ).toString() );
-   }
-
-
-   /**
-    * test a simple RDN : a = b
-    */
-   public void testRdnSimple() throws InvalidNameException
-   {
-       Assert.assertEquals( "a=b", new Rdn( "a = b" ).toString() );
-   }
-
-
-   /**
-    * test a composite RDN : a = b, d = e
-    */
-   public void testRdnComposite() throws InvalidNameException
-   {
-       Assert.assertEquals( "a=b+c=d", new Rdn( "a = b + c = d" ).toString() );
-   }
-
-
-   /**
-    * test a composite RDN with or without spaces: a=b, a =b, a= b, a = b, a =
-    * b
-    */
-   public void testRdnCompositeWithSpace() throws InvalidNameException
-   {
-       Assert.assertEquals( "a=b", new Rdn( "a=b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a=b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a =b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a= b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a=b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a =b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a= b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a=b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a = b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a =b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a= b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a = b" ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a =b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a= b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( "a = b " ).toString() );
-       Assert.assertEquals( "a=b", new Rdn( " a = b " ).toString() );
-   }
-
-
-   /**
-    * test a simple RDN with differents separators : a = b + c = d
-    */
-   public void testRdnSimpleMultivaluedAttribute() throws InvalidNameException
-   {
-       String result = new Rdn( "a = b + c = d" ).toString();
-       Assert.assertEquals( "a=b+c=d", result );
-   }
-
-
-   /**
-    * test a composite RDN with differents separators : a=b+c=d, e=f + g=h +
-    * i=j
-    */
-   public void testRdnCompositeMultivaluedAttribute() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( "a =b+c=d + e=f + g  =h + i =j " );
-
-       // NameComponent are not ordered
-       Assert.assertEquals( "b", rdn.getValue( "a" ) );
-       Assert.assertEquals( "d", rdn.getValue( "c" ) );
-       Assert.assertEquals( "f", rdn.getValue( "  E  " ) );
-       Assert.assertEquals( "h", rdn.getValue( "g" ) );
-       Assert.assertEquals( "j", rdn.getValue( "i" ) );
-   }
-
-
-   /**
-    * test a simple RDN with an oid prefix (uppercase) : OID.12.34.56 = azerty
-    */
-   public void testRdnOidUpper() throws InvalidNameException
-   {
-       Assert.assertEquals( "oid.12.34.56=azerty", new Rdn( "OID.12.34.56 =  azerty" ).toString()
);
-   }
-
-
-   /**
-    * test a simple RDN with an oid prefix (lowercase) : oid.12.34.56 = azerty
-    */
-   public void testRdnOidLower() throws InvalidNameException
-   {
-       Assert.assertEquals( "oid.12.34.56=azerty", new Rdn( "oid.12.34.56 = azerty" ).toString()
);
-   }
-
-
-   /**
-    * test a simple RDN with an oid attribut wiithout oid prefix : 12.34.56 =
-    * azerty
-    */
-   public void testRdnOidWithoutPrefix() throws InvalidNameException
-   {
-       Assert.assertEquals( "12.34.56=azerty", new Rdn( "12.34.56 = azerty" ).toString()
);
-   }
-
-
-   /**
-    * test a composite RDN with an oid attribut wiithout oid prefix : 12.34.56 =
-    * azerty; 7.8 = test
-    */
-   public void testRdnCompositeOidWithoutPrefix() throws InvalidNameException
-   {
-       String result = new Rdn( "12.34.56 = azerty + 7.8 = test" ).toString();
-       Assert.assertEquals( "12.34.56=azerty+7.8=test", result );
-   }
-
-
-   /**
-    * test a simple RDN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C3\A9"
-    */
-   public void testRdnPairCharAttributeValue() throws InvalidNameException
-   {
-       String rdn = StringTools.utf8ToString( new byte[]{'a', '=', '\\', ',', '=', '\\',
'+', '\\', '<', 
-           '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\', 'C', '3', '\\', 'A',
'9' });
-       Assert.assertEquals( rdn, new Rdn(
-           "a = \\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9" ).toString() );
-   }
-
-
-   /**
-    * test a simple RDN with hexString attribute value : a = #0010A0AAFF
-    */
-   public void testRdnHexStringAttributeValue() throws InvalidNameException
-   {
-       Assert.assertEquals( "a=#0010A0AAFF", new Rdn( "a = #0010A0AAFF" ).toString() );
-   }
-
-
-   /**
-    * test a simple RDN with quoted attribute value : a = "quoted \"value"
-    */
-   public void testRdnQuotedAttributeValue() throws InvalidNameException
-   {
-       Assert.assertEquals( "a=quoted \\\"value", new Rdn( "a = quoted \\\"value" ).toString()
);
-   }
-
-
-   /**
-    * Test the clone method for a RDN.
-    */
-   public void testRDNCloningOneNameComponent() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( "a", "a", "b", "b" );
-
-       Rdn rdnClone = ( Rdn ) rdn.clone();
-
-       RdnParser.parse( "c=d", rdn );
-
-       Assert.assertEquals( "b", rdnClone.getValue( "a" ) );
-   }
-
-
-   /**
-    * Test the clone method for a RDN.
-    */
-   public void testRDNCloningTwoNameComponent() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( "a = b + aa = bb" );
-
-       Rdn rdnClone = ( Rdn ) rdn.clone();
-
-       rdn.clear();
-       RdnParser.parse( "c=d", rdn );
-
-       Assert.assertEquals( "b", rdnClone.getValue( "a" ) );
-       Assert.assertEquals( "bb", rdnClone.getValue( "aa" ) );
-       Assert.assertEquals( "", rdnClone.getValue( "c" ) );
-   }
-
-
-   /**
-    * Test the compareTo method for a RDN.
-    */
-   public void testRDNCompareToNull() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
-       Rdn rdn2 = null;
-       Assert.assertEquals( 1, rdn1.compareTo( rdn2 ) );
-   }
-
-
-   /**
-    * Compares a composite NC to a single NC.
-    */
-   public void testRDNCompareToNCS2NC() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
-       Rdn rdn2 = new Rdn( " a = b " );
-       Assert.assertTrue( rdn1.compareTo( rdn2 ) > 0 );
-   }
-
-
-   /**
-    * Compares a single NC to a composite NC.
-    */
-   public void testRDNCompareToNC2NCS() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-       Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
-
-       Assert.assertTrue( rdn1.compareTo( rdn2 ) < 0 );
-   }
-
-
-   /**
-    * Compares a composite NCS to a composite NCS in the same order.
-    */
-   public void testRDNCompareToNCS2NCSOrdered() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
-       Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
-
-       Assert.assertEquals( 0, rdn1.compareTo( rdn2 ) );
-   }
-
-
-   /**
-    * Compares a composite NCS to a composite NCS in a different order.
-    */
-   public void testRDNCompareToNCS2NCSUnordered() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b + a = f + g = h + c = d " );
-       Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
-
-       Assert.assertEquals( 0, rdn1.compareTo( rdn2 ) );
-   }
-
-
-   /**
-    * Compares a composite NCS to a different composite NCS.
-    */
-   public void testRDNCompareToNCS2NCSNotEquals() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = f + g = h + c = d " );
-       Rdn rdn2 = new Rdn( " c = d + a = h + g = h " );
-
-       Assert.assertEquals( -1, rdn1.compareTo( rdn2 ) );
-   }
-
-
-   /**
-    * Compares with a null RDN.
-    */
-   public void testRDNCompareToNullRdn() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-
-       Assert.assertEquals( 1, rdn1.compareTo( null ) );
-   }
-
-   /**
-    * Compares with a bad object
-    */
-   public void testRDNCompareToBadObject() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-
-       Assert.assertEquals( Rdn.UNDEFINED, rdn1.compareTo( "test" ) );
-   }
-
-   /**
-    * Compares a simple NC to a simple NC.
-    */
-   public void testRDNCompareToNC2NC() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-       Rdn rdn2 = new Rdn( " a = b " );
-
-       Assert.assertEquals( 0, rdn1.compareTo( rdn2 ) );
-   }
-
-
-   /**
-    * Compares a simple NC to a simple NC in UperCase.
-    */
-   public void testRDNCompareToNC2NCUperCase() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-       Rdn rdn2 = new Rdn( " A = b " );
-
-       Assert.assertEquals( 0, rdn1.compareTo( rdn2 ) );
-       Assert.assertEquals( true, rdn1.equals( rdn2 ) );
-   }
-
-
-   /**
-    * Compares a simple NC to a different simple NC.
-    */
-   public void testRDNCompareToNC2NCNotEquals() throws InvalidNameException
-   {
-       Rdn rdn1 = new Rdn( " a = b " );
-       Rdn rdn2 = new Rdn( " A = d " );
-
-       Assert.assertTrue( rdn1.compareTo( rdn2 ) < 0 );
-   }
-
-
-   public void testToAttributes() throws InvalidNameException, NamingException
-   {
-       Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
-
-       Attributes attributes = rdn.toAttributes();
-
-       Assert.assertNotNull( attributes.get( "a" ) );
-       Assert.assertNotNull( attributes.get( "g" ) );
-       Assert.assertNotNull( attributes.get( "c" ) );
-
-       Attribute attribute = attributes.get( "a" );
-
-       Assert.assertNotNull( attribute.get( 0 ) );
-       Assert.assertEquals( "b", attribute.get( 0 ) );
-
-       Assert.assertNotNull( attribute.get( 1 ) );
-       Assert.assertEquals( "f", attribute.get( 1 ) );
-
-       attribute = attributes.get( "g" );
-       Assert.assertNotNull( attribute.get( 0 ) );
-       Assert.assertEquals( "h", attribute.get( 0 ) );
-
-       attribute = attributes.get( "c" );
-       Assert.assertNotNull( attribute.get( 0 ) );
-       Assert.assertEquals( "d", attribute.get( 0 ) );
-   }
-
-
-   public void testGetValue() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
-
-       Assert.assertEquals( "b", rdn.getValue() );
-   }
-
-
-   public void testGetType() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
-
-       Assert.assertEquals( "a", rdn.getNormType() );
-   }
-
-
-   public void testGetSize() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
-
-       Assert.assertEquals( 4, rdn.size() );
-   }
-
-
-   public void testGetSize0()
-   {
-       Rdn rdn = new Rdn();
-
-       Assert.assertEquals( 0, rdn.size() );
-   }
-
-
-   public void testEquals() throws InvalidNameException
-   {
-       Rdn rdn = new Rdn( "a=b + c=d + a=f" );
-
-       Assert.assertFalse( rdn.equals( null ) );
-       Assert.assertFalse( rdn.equals( "test" ) );
-       Assert.assertFalse( rdn.equals( new Rdn( "a=c + c=d + a=f" ) ) );
-       Assert.assertFalse( rdn.equals( new Rdn( "a=b" ) ) );
-       Assert.assertTrue( rdn.equals( new Rdn( "a=b + c=d + a=f" ) ) );
-       Assert.assertTrue( rdn.equals( new Rdn( "a=b + C=d + A=f" ) ) );
-       Assert.assertTrue( rdn.equals( new Rdn( "c=d + a=f + a=b" ) ) );
-   }
-
-
-   public void testUnescapeValueHexa()
-   {
-       byte[] res = ( byte[] ) Rdn.unescapeValue( "#fF" );
-
-       Assert.assertEquals( "0xFF ", StringTools.dumpBytes( res ) );
-
-       res = ( byte[] ) Rdn.unescapeValue( "#0123456789aBCDEF" );
-       Assert.assertEquals( "0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF ", StringTools.dumpBytes(
res ) );
-   }
-
-
-   public void testUnescapeValueHexaWrong()
-   {
-       try
-       {
-           Rdn.unescapeValue( "#fF1" );
-           Assert.fail(); // Should not happen
-       }
-       catch ( IllegalArgumentException iae )
-       {
-           Assert.assertTrue( true );
-       }
-   }
-
-
-   public void testUnescapeValueString()
-   {
-       String res = ( String ) Rdn.unescapeValue( "azerty" );
-
-       Assert.assertEquals( "azerty", res );
-   }
-
-
-   public void testUnescapeValueStringSpecial()
-   {
-       String res = ( String ) Rdn.unescapeValue( "\\\\\\#\\,\\+\\;\\<\\>\\=\\\"\\
" );
-
-       Assert.assertEquals( "\\#,+;<>=\" ", res );
-   }
-
-
-   public void testEscapeValueString()
-   {
-       String res = Rdn.escapeValue( StringTools.getBytesUtf8( "azerty" ) );
-
-       Assert.assertEquals( "azerty", res );
-   }
-
-
-   public void testEscapeValueStringSpecial()
-   {
-       String res = Rdn.escapeValue( StringTools.getBytesUtf8( "\\#,+;<>=\" " ) );
-
-       Assert.assertEquals( "\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
-   }
-
-
-   public void testEscapeValueNumeric()
-   {
-       String res = Rdn.escapeValue( new byte[]
-           { '-', 0x00, '-', 0x1F, '-', 0x7F, '-' } );
-
-       Assert.assertEquals( "-\\00-\\1F-\\7F-", res );
-   }
-
-
-   public void testEscapeValueMix()
-   {
-       String res = Rdn.escapeValue( new byte[]
-           { '\\', 0x00, '-', '+', '#', 0x7F, '-' } );
+    // ~ Methods
+    // ------------------------------------------------------------------------------------
+    /**
+     * Test a null RDN
+     */
+    @Test
+    public void testRdnNull()
+    {
+        assertEquals( "", new Rdn().toString() );
+    }
+
+
+    /**
+     * test an empty RDN
+     */
+    @Test
+    public void testRdnEmpty() throws InvalidNameException
+    {
+        assertEquals( "", new Rdn( "" ).toString() );
+    }
+
+
+    /**
+     * test a simple RDN : a = b
+     */
+    @Test
+    public void testRdnSimple() throws InvalidNameException
+    {
+        assertEquals( "a=b", new Rdn( "a = b" ).toString() );
+    }
+
+
+    /**
+     * test a composite RDN : a = b, d = e
+     */
+    @Test
+    public void testRdnComposite() throws InvalidNameException
+    {
+        assertEquals( "a=b+c=d", new Rdn( "a = b + c = d" ).toString() );
+    }
+
+
+    /**
+     * test a composite RDN with or without spaces: a=b, a =b, a= b, a = b, a =
+     * b
+     */
+    @Test
+    public void testRdnCompositeWithSpace() throws InvalidNameException
+    {
+        assertEquals( "a=b", new Rdn( "a=b" ).toString() );
+        assertEquals( "a=b", new Rdn( " a=b" ).toString() );
+        assertEquals( "a=b", new Rdn( "a =b" ).toString() );
+        assertEquals( "a=b", new Rdn( "a= b" ).toString() );
+        assertEquals( "a=b", new Rdn( "a=b " ).toString() );
+        assertEquals( "a=b", new Rdn( " a =b" ).toString() );
+        assertEquals( "a=b", new Rdn( " a= b" ).toString() );
+        assertEquals( "a=b", new Rdn( " a=b " ).toString() );
+        assertEquals( "a=b", new Rdn( "a = b" ).toString() );
+        assertEquals( "a=b", new Rdn( "a =b " ).toString() );
+        assertEquals( "a=b", new Rdn( "a= b " ).toString() );
+        assertEquals( "a=b", new Rdn( " a = b" ).toString() );
+        assertEquals( "a=b", new Rdn( " a =b " ).toString() );
+        assertEquals( "a=b", new Rdn( " a= b " ).toString() );
+        assertEquals( "a=b", new Rdn( "a = b " ).toString() );
+        assertEquals( "a=b", new Rdn( " a = b " ).toString() );
+    }
+
+
+    /**
+     * test a simple RDN with differents separators : a = b + c = d
+     */
+    @Test
+    public void testRdnSimpleMultivaluedAttribute() throws InvalidNameException
+    {
+        String result = new Rdn( "a = b + c = d" ).toString();
+        assertEquals( "a=b+c=d", result );
+    }
+
+
+    /**
+     * test a composite RDN with differents separators : a=b+c=d, e=f + g=h +
+     * i=j
+     */
+    @Test
+    public void testRdnCompositeMultivaluedAttribute() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "a =b+c=d + e=f + g  =h + i =j " );
+
+        // NameComponent are not ordered
+        assertEquals( "b", rdn.getValue( "a" ) );
+        assertEquals( "d", rdn.getValue( "c" ) );
+        assertEquals( "f", rdn.getValue( "  E  " ) );
+        assertEquals( "h", rdn.getValue( "g" ) );
+        assertEquals( "j", rdn.getValue( "i" ) );
+    }
+
+
+    /**
+     * test a simple RDN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+     */
+    @Test
+    public void testRdnOidUpper() throws InvalidNameException
+    {
+        assertEquals( "oid.12.34.56=azerty", new Rdn( "OID.12.34.56 =  azerty" ).toString()
);
+    }
+
+
+    /**
+     * test a simple RDN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     */
+    @Test
+    public void testRdnOidLower() throws InvalidNameException
+    {
+        assertEquals( "oid.12.34.56=azerty", new Rdn( "oid.12.34.56 = azerty" ).toString()
);
+    }
+
+
+    /**
+     * test a simple RDN with an oid attribut wiithout oid prefix : 12.34.56 =
+     * azerty
+     */
+    @Test
+    public void testRdnOidWithoutPrefix() throws InvalidNameException
+    {
+        assertEquals( "12.34.56=azerty", new Rdn( "12.34.56 = azerty" ).toString() );
+    }
+
+
+    /**
+     * test a composite RDN with an oid attribut wiithout oid prefix : 12.34.56 =
+     * azerty; 7.8 = test
+     */
+    @Test
+    public void testRdnCompositeOidWithoutPrefix() throws InvalidNameException
+    {
+        String result = new Rdn( "12.34.56 = azerty + 7.8 = test" ).toString();
+        assertEquals( "12.34.56=azerty+7.8=test", result );
+    }
+
+
+    /**
+     * test a simple RDN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C3\A9"
+     */
+    @Test
+    public void testRdnPairCharAttributeValue() throws InvalidNameException
+    {
+        String rdn = StringTools.utf8ToString( new byte[]
+            { 'a', '=', '\\', ',', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\',
';', '\\', '\\', '\\', '"', '\\',
+                'C', '3', '\\', 'A', '9' } );
+        assertEquals( rdn, new Rdn( "a = \\,=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9" ).toString()
);
+    }
+
+
+    /**
+     * test a simple RDN with hexString attribute value : a = #0010A0AAFF
+     */
+    @Test
+    public void testRdnHexStringAttributeValue() throws InvalidNameException
+    {
+        assertEquals( "a=#0010A0AAFF", new Rdn( "a = #0010A0AAFF" ).toString() );
+    }
+
+
+    /**
+     * test a simple RDN with quoted attribute value : a = "quoted \"value"
+     */
+    @Test
+    public void testRdnQuotedAttributeValue() throws InvalidNameException
+    {
+        assertEquals( "a=quoted \\\"value", new Rdn( "a = quoted \\\"value" ).toString()
);
+    }
+
+
+    /**
+     * Test the clone method for a RDN.
+     */
+    @Test
+    public void testRDNCloningOneNameComponent() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "a", "a", "b", "b" );
+
+        Rdn rdnClone = ( Rdn ) rdn.clone();
+
+        RdnParser.parse( "c=d", rdn );
+
+        assertEquals( "b", rdnClone.getValue( "a" ) );
+    }
+
+
+    /**
+     * Test the clone method for a RDN.
+     */
+    @Test
+    public void testRDNCloningTwoNameComponent() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "a = b + aa = bb" );
+
+        Rdn rdnClone = ( Rdn ) rdn.clone();
+
+        rdn.clear();
+        RdnParser.parse( "c=d", rdn );
+
+        assertEquals( "b", rdnClone.getValue( "a" ) );
+        assertEquals( "bb", rdnClone.getValue( "aa" ) );
+        assertEquals( "", rdnClone.getValue( "c" ) );
+    }
+
+
+    /**
+     * Test the compareTo method for a RDN.
+     */
+    @Test
+    public void testRDNCompareToNull() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
+        Rdn rdn2 = null;
+        assertEquals( 1, rdn1.compareTo( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NC to a single NC.
+     */
+    @Test
+    public void testRDNCompareToNCS2NC() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
+        Rdn rdn2 = new Rdn( " a = b " );
+        assertTrue( rdn1.compareTo( rdn2 ) > 0 );
+    }
+
+
+    /**
+     * Compares a single NC to a composite NC.
+     */
+    @Test
+    public void testRDNCompareToNC2NCS() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+        Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
+
+        assertTrue( rdn1.compareTo( rdn2 ) < 0 );
+    }
+
+
+    /**
+     * Compares a composite NCS to a composite NCS in the same order.
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSOrdered() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b + c = d + a = f + g = h " );
+        Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
+
+        assertEquals( 0, rdn1.compareTo( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NCS to a composite NCS in a different order.
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSUnordered() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b + a = f + g = h + c = d " );
+        Rdn rdn2 = new Rdn( " a = b + c = d + a = f + g = h " );
+
+        assertEquals( 0, rdn1.compareTo( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NCS to a different composite NCS.
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSNotEquals() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = f + g = h + c = d " );
+        Rdn rdn2 = new Rdn( " c = d + a = h + g = h " );
+
+        assertEquals( -1, rdn1.compareTo( rdn2 ) );
+    }
+
+
+    /**
+     * Compares with a null RDN.
+     */
+    @Test
+    public void testRDNCompareToNullRdn() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+
+        assertEquals( 1, rdn1.compareTo( null ) );
+    }
+
+
+    /**
+     * Compares with a bad object
+     */
+    @Test
+    public void testRDNCompareToBadObject() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+
+        assertEquals( Rdn.UNDEFINED, rdn1.compareTo( "test" ) );
+    }
+
+
+    /**
+     * Compares a simple NC to a simple NC.
+     */
+    @Test
+    public void testRDNCompareToNC2NC() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+        Rdn rdn2 = new Rdn( " a = b " );
+
+        assertEquals( 0, rdn1.compareTo( rdn2 ) );
+    }
 
-       Assert.assertEquals( "\\\\\\00-\\+#\\7F-", res );
-   }
 
-    public void testDIRSERVER_703() throws InvalidNameException 
+    /**
+     * Compares a simple NC to a simple NC in UperCase.
+     */
+    @Test
+    public void testRDNCompareToNC2NCUperCase() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+        Rdn rdn2 = new Rdn( " A = b " );
+
+        assertEquals( 0, rdn1.compareTo( rdn2 ) );
+        assertEquals( true, rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a simple NC to a different simple NC.
+     */
+    @Test
+    public void testRDNCompareToNC2NCNotEquals() throws InvalidNameException
+    {
+        Rdn rdn1 = new Rdn( " a = b " );
+        Rdn rdn2 = new Rdn( " A = d " );
+
+        assertTrue( rdn1.compareTo( rdn2 ) < 0 );
+    }
+
+
+    @Test
+    public void testToAttributes() throws InvalidNameException, NamingException
+    {
+        Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
+
+        Attributes attributes = rdn.toAttributes();
+
+        assertNotNull( attributes.get( "a" ) );
+        assertNotNull( attributes.get( "g" ) );
+        assertNotNull( attributes.get( "c" ) );
+
+        Attribute attribute = attributes.get( "a" );
+
+        assertNotNull( attribute.get( 0 ) );
+        assertEquals( "b", attribute.get( 0 ) );
+
+        assertNotNull( attribute.get( 1 ) );
+        assertEquals( "f", attribute.get( 1 ) );
+
+        attribute = attributes.get( "g" );
+        assertNotNull( attribute.get( 0 ) );
+        assertEquals( "h", attribute.get( 0 ) );
+
+        attribute = attributes.get( "c" );
+        assertNotNull( attribute.get( 0 ) );
+        assertEquals( "d", attribute.get( 0 ) );
+    }
+
+
+    @Test
+    public void testGetValue() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
+
+        assertEquals( "b", rdn.getValue() );
+    }
+
+
+    @Test
+    public void testGetType() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
+
+        assertEquals( "a", rdn.getNormType() );
+    }
+
+
+    @Test
+    public void testGetSize() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( " a = b + a = f + g = h + c = d " );
+
+        assertEquals( 4, rdn.size() );
+    }
+
+
+    @Test
+    public void testGetSize0()
+    {
+        Rdn rdn = new Rdn();
+
+        assertEquals( 0, rdn.size() );
+    }
+
+
+    @Test
+    public void testEquals() throws InvalidNameException
+    {
+        Rdn rdn = new Rdn( "a=b + c=d + a=f" );
+
+        assertFalse( rdn.equals( null ) );
+        assertFalse( rdn.equals( "test" ) );
+        assertFalse( rdn.equals( new Rdn( "a=c + c=d + a=f" ) ) );
+        assertFalse( rdn.equals( new Rdn( "a=b" ) ) );
+        assertTrue( rdn.equals( new Rdn( "a=b + c=d + a=f" ) ) );
+        assertTrue( rdn.equals( new Rdn( "a=b + C=d + A=f" ) ) );
+        assertTrue( rdn.equals( new Rdn( "c=d + a=f + a=b" ) ) );
+    }
+
+
+    @Test
+    public void testUnescapeValueHexa()
+    {
+        byte[] res = ( byte[] ) Rdn.unescapeValue( "#fF" );
+
+        assertEquals( "0xFF ", StringTools.dumpBytes( res ) );
+
+        res = ( byte[] ) Rdn.unescapeValue( "#0123456789aBCDEF" );
+        assertEquals( "0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF ", StringTools.dumpBytes(
res ) );
+    }
+
+
+    @Test
+    public void testUnescapeValueHexaWrong()
+    {
+        try
+        {
+            Rdn.unescapeValue( "#fF1" );
+            fail(); // Should not happen
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test
+    public void testUnescapeValueString()
+    {
+        String res = ( String ) Rdn.unescapeValue( "azerty" );
+
+        assertEquals( "azerty", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringSpecial()
+    {
+        String res = ( String ) Rdn.unescapeValue( "\\\\\\#\\,\\+\\;\\<\\>\\=\\\"\\
" );
+
+        assertEquals( "\\#,+;<>=\" ", res );
+    }
+
+
+    @Test
+    public void testEscapeValueString()
+    {
+        String res = Rdn.escapeValue( StringTools.getBytesUtf8( "azerty" ) );
+
+        assertEquals( "azerty", res );
+    }
+
+
+    @Test
+    public void testEscapeValueStringSpecial()
+    {
+        String res = Rdn.escapeValue( StringTools.getBytesUtf8( "\\#,+;<>=\" " ) );
+
+        assertEquals( "\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
+    }
+
+
+    @Test
+    public void testEscapeValueNumeric()
+    {
+        String res = Rdn.escapeValue( new byte[]
+            { '-', 0x00, '-', 0x1F, '-', 0x7F, '-' } );
+
+        assertEquals( "-\\00-\\1F-\\7F-", res );
+    }
+
+
+    @Test
+    public void testEscapeValueMix()
+    {
+        String res = Rdn.escapeValue( new byte[]
+            { '\\', 0x00, '-', '+', '#', 0x7F, '-' } );
+
+        assertEquals( "\\\\\\00-\\+#\\7F-", res );
+    }
+
+
+    @Test
+    public void testDIRSERVER_703() throws InvalidNameException
     {
         Rdn rdn = new Rdn( "cn=Kate Bush+sn=Bush" );
         assertEquals( "cn=Kate Bush+sn=Bush", rdn.getUpName() );
     }
 
 
+    @Test
     public void testMultiValuedIterator() throws InvalidNameException
     {
         Rdn rdn = new Rdn( "cn=Kate Bush+sn=Bush" );
@@ -535,6 +584,7 @@
     }
 
 
+    @Test
     public void testSingleValuedIterator() throws InvalidNameException
     {
         Rdn rdn = new Rdn( "cn=Kate Bush" );
@@ -546,6 +596,7 @@
     }
 
 
+    @Test
     public void testEmptyIterator() throws InvalidNameException
     {
         Rdn rdn = new Rdn();
@@ -555,12 +606,15 @@
     }
 
 
+    @Test
     public void testRdnWithSpaces() throws InvalidNameException
     {
         Rdn rdn = new Rdn( "cn=a\\ b\\ c" );
         assertEquals( "cn=a b c", rdn.toString() );
     }
 
+
+    @Test
     public void testEscapedSpaceInValue() throws InvalidNameException
     {
         Rdn rdn1 = new Rdn( "cn=a b c" );
@@ -577,6 +631,7 @@
     }
 
 
+    @Test
     public void testEscapedHashInValue() throws InvalidNameException
     {
         Rdn rdn1 = new Rdn( "cn=a#b#c" );
@@ -593,6 +648,7 @@
     }
 
 
+    @Test
     public void testEscapedAttributeValue() throws InvalidNameException
     {
         // space doesn't need to be escaped in the middle of a string
@@ -605,7 +661,7 @@
         assertEquals( "a b\\ ", Rdn.escapeValue( "a b " ) );
         assertEquals( "\\ a b\\ ", Rdn.escapeValue( " a b " ) );
         assertEquals( "\\  a  b \\ ", Rdn.escapeValue( "  a  b  " ) );
-        
+
         // hash doesn't need to be escaped in the middle and the end of a string
         assertEquals( "a#b", Rdn.escapeValue( "a#b" ) );
         assertEquals( "a#b#", Rdn.escapeValue( "a#b#" ) );
@@ -613,7 +669,7 @@
         assertEquals( "a#b#c#", Rdn.escapeValue( "a#b#c#" ) );
         assertEquals( "a#b#c#d", Rdn.escapeValue( "a#b#c#d" ) );
         assertEquals( "a#b#c#d#", Rdn.escapeValue( "a#b#c#d#" ) );
-        
+
         // hash must be escaped at the beginning of a string
         assertEquals( "\\#a#b", Rdn.escapeValue( "#a#b" ) );
         assertEquals( "\\##a#b", Rdn.escapeValue( "##a#b" ) );
@@ -724,7 +780,7 @@
         assertEquals( rdn, rdn2 );
     }
 
-    
+
     /**
      * Test serialization of a simple Rdn with no value
      */
@@ -750,7 +806,7 @@
         assertEquals( rdn, rdn2 );
     }
 
-    
+
     /**
      * Test serialization of a simple Rdn with one value
      */
@@ -776,7 +832,7 @@
         assertEquals( rdn, rdn2 );
     }
 
-    
+
     /**
      * Test serialization of a simple Rdn with three values
      */
@@ -802,12 +858,13 @@
         assertEquals( rdn, rdn2 );
     }
 
-    
+
     /**
      * Test serialization of a simple Rdn with three unordered values
      */
     @Test
-    public void testSimpleRdnThreeValuesUnorderedSerialization() throws NamingException,
IOException, ClassNotFoundException
+    public void testSimpleRdnThreeValuesUnorderedSerialization() throws NamingException,
IOException,
+        ClassNotFoundException
     {
         Rdn rdn = new Rdn( " B = b + A = a + C = c " );
         rdn.normalize();
@@ -824,6 +881,209 @@
 
         Rdn rdn2 = new Rdn();
         rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /** Static Serialization tests ------------------------------------------------- */
+
+    /**
+     * Test serialization of an empty RDN
+     */
+    @Test
+    public void testEmptyRDNStaticSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( "" );
+
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    @Test
+    public void testNullRdnStaticSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn();
+
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn
+     */
+    @Test
+    public void testSimpleRdnStaticSerialization() throws NamingException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( "a=b" );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn
+     */
+    @Test
+    public void testSimpleRdn2StaticSerialization() throws NamingException, IOException,
ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( " ABC  = DEF " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with no value
+     */
+    @Test
+    public void testSimpleRdnNoValueStaticSerialization() throws NamingException, IOException,
ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( " ABC  =" );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with one value
+     */
+    @Test
+    public void testSimpleRdnOneValueStaticSerialization() throws NamingException, IOException,
ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( " ABC  = def " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with three values
+     */
+    @Test
+    public void testSimpleRdnThreeValuesStaticSerialization() throws NamingException, IOException,
+        ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( " A = a + B = b + C = c " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with three unordered values
+     */
+    @Test
+    public void testSimpleRdnThreeValuesUnorderedStaticSerialization() throws NamingException,
IOException,
+        ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( " B = b + A = a + C = c " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        RdnSerializer.serialize( rdn, out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = RdnSerializer.deserialize( in );
 
         assertEquals( rdn, rdn2 );
     }



Mime
View raw message