directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r291840 - /directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
Date Tue, 27 Sep 2005 07:02:03 GMT
Author: elecharny
Date: Tue Sep 27 00:01:59 2005
New Revision: 291840

URL: http://svn.apache.org/viewcvs?rev=291840&view=rev
Log:
Updated the content of this class, copying the content from the same class in utils package

Modified:
    directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java

Modified: directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java?rev=291840&r1=291839&r2=291840&view=diff
==============================================================================
--- directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
(original)
+++ directory/shared/ldap/branches/shared-ldap-NameComponent/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
Tue Sep 27 00:01:59 2005
@@ -23,6 +23,7 @@
 
 import org.apache.asn1.codec.DecoderException;
 import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+import org.apache.asn1new.ldap.codec.primitives.LdapRDN;
 
 /**
  * Test the class LdapRDN
@@ -43,65 +44,134 @@
     /**
      * Test a null RDN
      */
-    public void testLdapRDNNull()
+    public void testLdapRDNNull() throws InvalidNameException
     {
-        try
-        {
-            new LdapRDN( null, null );
-            // Should never go further.
-        }
-        catch ( InvalidNameException ine )
-        {
-            Assert.assertTrue( true );
-        }
+        Assert.assertEquals( null, new LdapRDN().toString() );
+    }
+
+    /**
+     * test an empty RDN
+     */
+    public void testLdapRDNEmpty() throws InvalidNameException
+    {
+        Assert.assertEquals( null, new LdapRDN( "" ).toString() );
     }
 
     /**
      * test a simple RDN : a = b
      */
-    public void testLdapRDNSimple()  throws InvalidNameException
+    public void testLdapRDNSimple() throws InvalidNameException
+    {
+        Assert.assertEquals( "a=b", new LdapRDN( "a = b" ).toString() );
+    }
+
+    /**
+     * test a composite RDN : a = b, d = e
+     */
+    public void testLdapRDNComposite() throws InvalidNameException
+    {
+        Assert.assertEquals( "a=b+c=d", new LdapRDN( "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 testLdapRDNCompositeWithSpace() throws InvalidNameException
     {
-        Assert.assertEquals( "a=b", new LdapRDN( "a ", " b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a=b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a=b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a =b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a= b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a=b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a =b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a= b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a=b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a = b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a =b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a= b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a = b" ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a =b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a= b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( "a = b " ).toString() );
+        Assert.assertEquals( "a=b", new LdapRDN( " a = b " ).toString() );
     }
 
     /**
-     * test a composite RDN : a = b + c = d
+     * test a simple RDN with differents separators : a = b + c = d
      */
-    public void testLdapRDNComposite()  throws InvalidNameException
+    public void testLdapRDNSimpleMultivaluedAttribute() throws InvalidNameException
     {
-        LdapRDN rdn = new LdapRDN();
-        rdn.addNameComponent( "a ", " b" );
-        rdn.addNameComponent( " c ", " d " );
-        Assert.assertEquals( "a=b+c=d", rdn.toString() );
+        String result = new LdapRDN( "a = b + c = d" ).toString(); 
+        Assert.assertEquals( "a=b+c=d", result );
     }
 
     /**
-     * test a composite RDN : A = b + c = d with uppercase
+     * test a composite RDN with differents separators : a=b+c=d, e=f + g=h + i=j
      */
-    public void testLdapRDNCompositeUpperCase() throws InvalidNameException
+    public void testLdapRDNCompositeMultivaluedAttribute() throws InvalidNameException
     {
-        LdapRDN rdn = new LdapRDN();
-        rdn.addNameComponent( "A ", " b" );
-        rdn.addNameComponent( " c ", " d " );
-        Assert.assertEquals( "a=b+c=d", rdn.toString() );
+        LdapRDN rdn = new LdapRDN( "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 DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\A0\00"
+     * test a simple RDN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+     */
+    public void testLdapRDNOidUpper() throws InvalidNameException
+    {
+        Assert.assertEquals( "oid.12.34.56=azerty",
+                new LdapRDN( "OID.12.34.56 =  azerty" ).toString() );
+    }
+
+    /**
+     * test a simple RDN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     */
+    public void testLdapRDNOidLower() throws InvalidNameException
+    {
+        Assert.assertEquals( "oid.12.34.56=azerty",
+                new LdapRDN( "oid.12.34.56 = azerty" ).toString() );
+    }
+
+    /**
+     * test a simple RDN with an oid attribut wiithout oid prefix : 12.34.56 = azerty
+     */
+    public void testLdapRDNOidWithoutPrefix() throws InvalidNameException
+    {
+        Assert.assertEquals( "12.34.56=azerty",
+                new LdapRDN( "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 testLdapRDNCompositeOidWithoutPrefix() throws InvalidNameException
+    {
+        String result = new LdapRDN( "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 = \,\=\+\<\>\#\;\\\"\A0\00"
      */
     public void testLdapRDNPairCharAttributeValue() throws InvalidNameException
     {
         Assert.assertEquals( "a=\\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00",
-                new LdapRDN( "a ", "   \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00   " ).toString()
);
+                new LdapRDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00" ).toString()
);
     }
 
     /**
      * test a simple RDN with hexString attribute value : a = #0010A0AAFF
      */
-    public void testLdapRDNHexStringAttributeValue()  throws InvalidNameException
+    public void testLdapRDNHexStringAttributeValue() throws InvalidNameException
     {
         Assert.assertEquals( "a=#0010A0AAFF",
-                new LdapRDN( "a", " #0010A0AAFF  " ).toString() );
+                new LdapRDN( "a = #0010A0AAFF" ).toString() );
     }
 
     /**
@@ -110,6 +180,42 @@
     public void testLdapRDNQuotedAttributeValue() throws InvalidNameException
     {
         Assert.assertEquals( "a=quoted \\\"value",
-                new LdapRDN( "a ", " quoted \\\"value  " ).toString() );
+                new LdapRDN( "a = quoted \\\"value" ).toString() );
+    }
+    
+    /**
+     * Test the clone method for a RDN.
+     */
+    public void testRDNCloningOneNameComponent()  throws InvalidNameException
+    {
+        LdapRDN rdn = new LdapRDN( "a", "b" );
+        
+        LdapRDN rdnClone = (LdapRDN)rdn.clone();
+        
+        rdn.removeNameComponent( "a" );
+        
+        LdapRDN.parseNameComponent( "c=d", rdn );
+        
+        Assert.assertEquals( "b" , rdnClone.getValue( "a" ) );
+    }
+
+    /**
+     * Test the clone method for a RDN.
+     */
+    public void testRDNCloningTwoNameComponent()  throws InvalidNameException
+    {
+        LdapRDN rdn = new LdapRDN( "a", "b" );
+        rdn.addNameComponent( "aa", "bb" );
+        
+        LdapRDN rdnClone = (LdapRDN)rdn.clone();
+        
+        rdn.removeNameComponent( "aa" );
+        rdn.clear();
+        LdapRDN.parseNameComponent( "c=d", rdn );
+        
+        Assert.assertEquals( "b" , rdnClone.getValue( "a" ) );
+        Assert.assertEquals( "bb" , rdnClone.getValue( "aa" ) );
+        Assert.assertEquals( null , rdnClone.getValue( "c" ) );
     }
 }
+



Mime
View raw message