directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r307437 - in /directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives: LdapDNTest.java LdapRDNTest.java LdapStringTest.java LdapUrlTest.java
Date Sun, 09 Oct 2005 13:57:55 GMT
Author: elecharny
Date: Sun Oct  9 06:57:46 2005
New Revision: 307437

URL: http://svn.apache.org/viewcvs?rev=307437&view=rev
Log:
* Creation of new tests class for LdapRDN and LdapString
* Moved tests for LdapDN and LdapURL

Added:
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapDNTest.java
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapStringTest.java
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java   (contents, props changed)
      - copied, changed from r292344, directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java

Added: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapDNTest.java?rev=307437&view=auto
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapDNTest.java (added)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapDNTest.java Sun Oct  9 06:57:46 2005
@@ -0,0 +1,1029 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1new.ldap.codec.primitives;
+
+import java.util.Enumeration;
+
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1new.ldap.codec.primitives.LdapDN;
+
+/**
+ * Test the class LdapDN
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapDNTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    // CONSTRUCTOR functions --------------------------------------------------
+    
+    /**
+     * Test a null DN
+     */
+    public void testLdapDNNull() throws DecoderException
+    {
+        Assert.assertEquals( "", new LdapDN().getName() );
+    }
+
+    /**
+     * test an empty DN
+     */
+    public void testLdapDNEmpty() throws InvalidNameException
+    {
+        Assert.assertEquals( "", new LdapDN( "" ).getName() );
+    }
+
+    /**
+     * test a simple DN : a = b
+     */
+    public void testLdapDNSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        Assert.assertEquals( "a=b", dn.getName() );
+    }
+
+    /**
+     * test a composite DN : a = b, d = e
+     */
+    public void testLdapDNComposite() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b, c = d" );
+        Assert.assertEquals( "a=b,c=d", dn.getName() );
+    }
+
+    /**
+     * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a  =  b
+     */
+    public void testLdapDNCompositeWithSpace() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
+        Assert.assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.getName() );
+    }
+
+    /**
+     * 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
+    {
+        LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
+        Assert.assertEquals( "a=b,c=d,e=f", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with multiple NameComponents : a = b + c = d
+     */
+    public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b + c = d" );
+        Assert.assertEquals( "a=b+c=d", dn.getName() );
+    }
+
+    /**
+     * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h + i=j
+     */
+    public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
+        Assert.assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
+     */
+    public void testLdapDNOidUpper() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
+        Assert.assertEquals( "oid.12.34.56=azerty", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     */
+    public void testLdapDNOidLower() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
+        Assert.assertEquals( "oid.12.34.56=azerty", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with an oid attribut without oid prefix : 12.34.56 = azerty
+     */
+    public void testLdapDNOidWithoutPrefix() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "12.34.56 = azerty" );
+        Assert.assertEquals( "12.34.56=azerty", dn.getName() );
+    }
+
+    /**
+     * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 = azerty; 7.8 = test
+     */
+    public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
+        Assert.assertEquals( "12.34.56=azerty,7.8=test", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\A0\00"
+     */
+    public void testLdapDNPairCharAttributeValue() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00" );
+        Assert.assertEquals( "a=\\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\A0\\00", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with hexString attribute value : a = #0010A0AAFF
+     */
+    public void testLdapDNHexStringAttributeValue() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
+        Assert.assertEquals( "a=#0010A0AAFF", dn.getName() );
+    }
+
+    /**
+     * test a simple DN with quoted attribute value : a = "quoted \"value"
+     */
+    public void testLdapDNQuotedAttributeValue() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = quoted \\\"value" );
+        Assert.assertEquals( "a=quoted \\\"value", dn.getName() );
+    }
+
+    // REMOVE operation -------------------------------------------------------
+    
+    /**
+     * test a remove from position 0
+     */
+    public void testLdapDNRemove0() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
+        Assert.assertEquals( "e=f", dn.remove( 0 ).toString() );
+        Assert.assertEquals( "a=b,c=d", dn.getName() );
+    }
+
+    /**
+     * test a remove from position 1
+     */
+    public void testLdapDNRemove1() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
+        Assert.assertEquals( "c=d", dn.remove( 1 ).toString() );
+        Assert.assertEquals( "a=b,e=f", dn.getName() );
+    }
+    
+    /**
+     * test a remove from position 2
+     */
+    public void testLdapDNRemove2() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
+        Assert.assertEquals( "a=b", dn.remove( 2 ).toString() );
+        Assert.assertEquals( "c=d,e=f", dn.getName() );
+    }
+
+    /**
+     * test a remove from position 1 whith semi colon
+     */
+    public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
+        Assert.assertEquals( "c=d", dn.remove( 1 ).toString() );
+        Assert.assertEquals( "a=b,e=f", dn.getName() );
+    }
+
+    /**
+     * test a remove out of bound
+     */
+    public void testLdapDNRemoveOutOfBound() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
+        
+        try
+        {
+            dn.remove( 4 );
+            // We whould never reach this point
+            Assert.fail();
+        }
+        catch ( ArrayIndexOutOfBoundsException aoobe )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+    
+    // SIZE operations
+    /**
+     * test a 0 size 
+     */
+    public void testLdapDNSize0() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        Assert.assertEquals( 0, dn.size() );
+    }
+
+    /**
+     * test a 1 size 
+     */
+    public void testLdapDNSize1() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b" );
+        Assert.assertEquals( 1, dn.size() );
+    }
+
+    /**
+     * test a 3 size 
+     */
+    public void testLdapDNSize3() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    /**
+     * test a 3 size with NameComponents
+     */
+    public void testLdapDNSize3NC() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    /**
+     * test size after operations
+     */
+    public void testLdapResizing() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        Assert.assertEquals( 0, dn.size() );
+        
+        dn.add( "e = f" );
+        Assert.assertEquals( 1, dn.size() );
+        
+        dn.add( "c = d" );
+        Assert.assertEquals( 2, dn.size() );
+
+        dn.remove( 0 );
+        Assert.assertEquals( 1, dn.size() );
+        
+        dn.remove( 0 );
+        Assert.assertEquals( 0, dn.size() );
+    }
+    
+    // ADD Operations
+    /**
+     * test Add on a new LdapDN
+     */
+    public void testLdapEmptyAdd() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        
+        dn.add( "e = f" );
+        Assert.assertEquals( "e=f" , dn.getName() );
+        Assert.assertEquals( 1, dn.size() );
+    }
+    
+    /**
+     * test Add to an existing LdapDN
+     */
+    public void testLdapDNAdd() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d");
+        
+        dn.add( "e = f" );
+        Assert.assertEquals( "e=f,a=b,c=d" , dn.getName() );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    /**
+     * test Add a composite RDN to an existing LdapDN
+     */
+    public void testLdapDNAddComposite() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d");
+        
+        dn.add( "e = f + g = h" );
+        
+        // Warning ! The order of AVAs has changed during the parsing
+        // This has no impact on the correctness of the DN, but the
+        // String used to do the comparizon should be inverted.
+        Assert.assertEquals( "g=h+e=f,a=b,c=d" , dn.getName() );
+        Assert.assertEquals( 3, dn.size() );
+    }
+    
+    /**
+     * test Add at the end of an existing LdapDN
+     */
+    public void testLdapDNAddEnd() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d");
+        
+        dn.add( dn.size(), "e = f" );
+        Assert.assertEquals( "e=f,a=b,c=d" , dn.getName() );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    /**
+     * test Add at the start of an existing LdapDN
+     */
+    public void testLdapDNAddStart() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d");
+        
+        dn.add( 0, "e = f" );
+        Assert.assertEquals( "a=b,c=d,e=f" , dn.getName() );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    /**
+     * test Add at the middle of an existing LdapDN
+     */
+    public void testLdapDNAddMiddle() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d");
+        
+        dn.add( 1, "e = f" );
+        Assert.assertEquals( "a=b,e=f,c=d" , dn.getName() );
+        Assert.assertEquals( 3, dn.size() );
+    }
+
+    // ADD ALL Operations
+    /**
+     * Test AddAll 
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAddAll() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        LdapDN dn2 = new LdapDN( "c = d" );
+        dn.addAll( dn2 );
+        Assert.assertEquals( "c=d,a=b", dn.getName() );
+    }
+    
+    /**
+     * Test AddAll with an empty added name
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        LdapDN dn2 = new LdapDN();
+        dn.addAll( dn2 );
+        Assert.assertEquals( "a=b", dn.getName() );
+    }
+
+    /**
+     * Test AddAll to an empty name
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAddAllNameEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        LdapDN dn2 = new LdapDN( "a = b" );
+        dn.addAll( dn2 );
+        Assert.assertEquals( "a=b", dn.getName() );
+    }
+    
+    /**
+     * Test AddAll at position 0
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAt0AddAll() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        LdapDN dn2 = new LdapDN( "c = d" );
+        dn.addAll( 0, dn2 );
+        Assert.assertEquals( "a=b,c=d", dn.getName() );
+    }
+    
+    /**
+     * Test AddAll at position 1
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAt1AddAll() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        LdapDN dn2 = new LdapDN( "c = d" );
+        dn.addAll( 1, dn2 );
+        Assert.assertEquals( "c=d,a=b", dn.getName() );
+    }
+    
+    /**
+     * Test AddAll at the middle
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b, c = d" );
+        LdapDN dn2 = new LdapDN( "e = f" );
+        dn.addAll( 1, dn2 );
+        Assert.assertEquals( "a=b,e=f,c=d", dn.getName() );
+    }
+    
+    /**
+     * Test AddAll with an empty added name at position 0
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        LdapDN dn2 = new LdapDN();
+        dn.addAll( 0, dn2 );
+        Assert.assertEquals( "a=b", dn.getName() );
+    }
+
+    /**
+     * Test AddAll to an empty name at position 0
+     * @throws InvalidNameException
+     */
+    public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        LdapDN dn2 = new LdapDN( "a = b" );
+        dn.addAll( 0, dn2 );
+        Assert.assertEquals( "a=b", dn.getName() );
+    }
+    
+    // GET PREFIX actions
+    /**
+     * Get the prefix at pos 0 
+     */
+    public void testLdapDNGetPrefixPos0() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getPrefix( 0 ));
+         Assert.assertEquals( "", newDn.getName() );
+    }
+
+    /**
+     * Get the prefix at pos 1 
+     */
+    public void testLdapDNGetPrefixPos1() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getPrefix( 1 ));
+        Assert.assertEquals( "e=f", newDn.getName() );
+    }
+    
+    /**
+     * Get the prefix at pos 2 
+     */
+    public void testLdapDNGetPrefixPos2() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getPrefix( 2 ));
+        Assert.assertEquals( "c=d,e=f", newDn.getName() );
+    }
+    
+    /**
+     * Get the prefix at pos 3 
+     */
+    public void testLdapDNGetPrefixPos3() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getPrefix( 3 ));
+        Assert.assertEquals( "a=b,c=d,e=f", newDn.getName() );
+    }
+
+    /**
+     * Get the prefix out of bound 
+     */
+    public void testLdapDNGetPrefixPos4() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        
+        try
+        {
+            dn.getPrefix( 4 );
+            // We should not reach this point.
+            Assert.fail();
+        }
+        catch ( ArrayIndexOutOfBoundsException aoobe )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+
+    /**
+     * Get the prefix of an empty LdapName
+     */
+    public void testLdapDNGetPrefixEmptyDN() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        LdapDN newDn = ((LdapDN)dn.getPrefix( 0 ));
+        Assert.assertEquals( "", newDn.getName() );
+    }
+    
+    // GET SUFFIX operations 
+    /**
+     * Get the suffix at pos 0 
+     */
+    public void testLdapDNGetSuffixPos0() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getSuffix( 0 ));
+         Assert.assertEquals( "a=b,c=d,e=f", newDn.getName() );
+    }
+
+    /**
+     * Get the suffix at pos 1 
+     */
+    public void testLdapDNGetSuffixPos1() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getSuffix( 1 ));
+        Assert.assertEquals( "a=b,c=d", newDn.getName() );
+    }
+    
+    /**
+     * Get the suffix at pos 2 
+     */
+    public void testLdapDNGetSuffixPos2() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getSuffix( 2 ));
+        Assert.assertEquals( "a=b", newDn.getName() );
+    }
+    
+    /**
+     * Get the suffix at pos 3 
+     */
+    public void testLdapDNGetSuffixPos3() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        LdapDN newDn = ((LdapDN)dn.getSuffix( 3 ));
+        Assert.assertEquals( "", newDn.getName() );
+    }
+
+    /**
+     * Get the suffix out of bound 
+     */
+    public void testLdapDNGetSuffixPos4() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        
+        try
+        {
+            dn.getSuffix( 4 );
+            // We should not reach this point.
+            Assert.fail();
+        }
+        catch ( ArrayIndexOutOfBoundsException aoobe )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+
+    /**
+     * Get the suffix of an empty LdapName
+     */
+    public void testLdapDNGetSuffixEmptyDN() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        LdapDN newDn = ((LdapDN)dn.getSuffix( 0 ));
+        Assert.assertEquals( "", newDn.getName() );
+    }
+    
+    // IS EMPTY operations
+    /**
+     * Test that a LdapDN is empty
+     */
+    public void testLdapDNIsEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        Assert.assertEquals( true, dn.isEmpty() );
+    }
+    
+    /**
+     * Test that a LdapDN is empty
+     */
+    public void testLdapDNNotEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b" );
+        Assert.assertEquals( false, dn.isEmpty() );
+    }
+
+    /**
+     * Test that a LdapDN is empty
+     */
+    public void testLdapDNRemoveIsEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d" );
+        dn.remove(0);
+        dn.remove(0);
+        
+        Assert.assertEquals( true, dn.isEmpty() );
+    }
+    
+    // STARTS WITH operations
+    /**
+     * Test a startsWith a null LdapDN
+     */
+    public void testLdapDNStartsWithNull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.startsWith( null ) );
+    }
+    
+    /**
+     * Test a startsWith an empty LdapDN
+     */
+    public void testLdapDNStartsWithEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.startsWith( new LdapDN() ) );
+    }
+    
+    /**
+     * Test a startsWith an simple LdapDN
+     */
+    public void testLdapDNStartsWithSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
+    }
+    
+    /**
+     * Test a startsWith a complex LdapDN
+     */
+    public void testLdapDNStartsWithComplex() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
+    }
+
+    /**
+     * Test a startsWith a complex LdapDN
+     */
+    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" ) ) );
+    }
+
+    /**
+     * Test a startsWith a full LdapDN
+     */
+    public void testLdapDNStartsWithFull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
+    }
+    
+    /**
+     * Test a startsWith which returns false
+     */
+    public void testLdapDNStartsWithWrong() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
+    }
+    
+    // ENDS WITH operations
+    /**
+     * Test a endsWith a null LdapDN
+     */
+    public void testLdapDNEndsWithNull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.endsWith( null ) );
+    }
+    
+    /**
+     * Test a endsWith an empty LdapDN
+     */
+    public void testLdapDNEndsWithEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.endsWith( new LdapDN() ) );
+    }
+    
+    /**
+     * Test a endsWith an simple LdapDN
+     */
+    public void testLdapDNEndsWithSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
+    }
+    
+    /**
+     * Test a endsWith a complex LdapDN
+     */
+    public void testLdapDNEndsWithComplex() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
+    }
+
+    /**
+     * Test a endsWith a complex LdapDN
+     */
+    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" ) ) );
+    }
+
+    /**
+     * Test a endsWith a full LdapDN
+     */
+    public void testLdapDNEndsWithFull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
+    }
+    
+    /**
+     * Test a endsWith which returns false
+     */
+    public void testLdapDNEndsWithWrong() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
+        Assert.assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
+    }
+    
+    // GET ALL operations
+    /**
+     * test a getAll operation on a null DN
+     */
+    public void testLdapDNGetAllNull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        Enumeration nc = dn.getAll();
+        
+        Assert.assertEquals( false, nc.hasMoreElements() );
+    }
+
+    /**
+     * test a getAll operation on an empty DN
+     */
+    public void testLdapDNGetAllEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN("");
+        Enumeration nc = dn.getAll();
+        
+        Assert.assertEquals( false, nc.hasMoreElements() );
+    }
+    
+    /**
+     * test a getAll operation on a simple DN
+     */
+    public void testLdapDNGetAllSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN("a=b");
+        Enumeration nc = dn.getAll();
+        
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "a=b", nc.nextElement() );
+        Assert.assertEquals( false, nc.hasMoreElements() );
+    }
+    
+    /**
+     * test a getAll operation on a complex DN
+     */
+    public void testLdapDNGetAllComplex() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
+        Enumeration nc = dn.getAll();
+        
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "c=d", nc.nextElement() );
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "a=b", nc.nextElement() );
+        Assert.assertEquals( true, nc.hasMoreElements() );
+        Assert.assertEquals( "e=f+g=h", nc.nextElement() );
+        Assert.assertEquals( false, nc.hasMoreElements() );
+    }
+    
+    // CLONE Operation
+    /**
+     * test a clone operation on a empty DN
+     */
+    public void testLdapDNCloneEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        LdapDN clone = (LdapDN)dn.clone();
+        
+        Assert.assertEquals( "", clone.getName() );
+    }
+    
+    /**
+     * test a clone operation on a simple DN
+     */
+    public void testLdapDNCloneSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a=b" );
+        LdapDN clone = (LdapDN)dn.clone();
+        
+        Assert.assertEquals( "a=b", clone.getName() );
+        dn.remove( 0 );
+        Assert.assertEquals( "a=b", clone.getName() );
+    }
+    
+    /**
+     * test a clone operation on a complex DN
+     */
+    public void testLdapDNCloneComplex() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
+        LdapDN clone = (LdapDN)dn.clone();
+        
+        Assert.assertEquals( "e=f+g=h,a=b,c=d", clone.getName() );
+        dn.remove( 2 );
+        Assert.assertEquals( "e=f+g=h,a=b,c=d", clone.getName() );
+    }
+    
+    // GET operations
+    /**
+     * test a get in a null DN
+     */
+    public void testLdapDNGetNull() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN();
+        Assert.assertEquals( "", dn.get( 0 ) );
+    }
+
+    /**
+     * test a get in an empty DN
+     */
+    public void testLdapDNGetEmpty() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "" );
+        Assert.assertEquals( "", dn.get( 0 ) );
+    }
+    
+    /**
+     * test a get in a simple DN
+     */
+    public void testLdapDNGetSimple() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b" );
+        Assert.assertEquals( "a=b", dn.get( 0 ) );
+    }
+    
+    /**
+     * test a get in a complex DN
+     */
+    public void testLdapDNGetComplex() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
+        Assert.assertEquals( "g=h", dn.get( 0 ) );
+        Assert.assertEquals( "e=f", dn.get( 1 ) );
+        Assert.assertEquals( "a=b+c=d", dn.get( 2 ) );
+    }
+    
+    /**
+     * test a get out of bound
+     */
+    public void testLdapDNGetOutOfBound() throws InvalidNameException
+    {
+        LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
+        
+        try
+        {
+            dn.get( 4 );
+            Assert.fail();
+        }
+        catch ( ArrayIndexOutOfBoundsException aioob )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+    
+    /**
+     * Tests the examples from the JNDI tutorials to make sure LdapName behaves
+     * appropriately.  The example can be found online 
+     * <a href="">here</a>.
+     * 
+     * @throws Exception if anything goes wrong
+     */
+    public void testJNDITutorialExample()
+        throws Exception
+    {
+        // Parse the name
+        Name name = new LdapDN( "cn=John,ou=People,ou=Marketing" );
+        
+        // Remove the second component from the head: ou=People
+        String out = name.remove( 1 ).toString() ;
+        
+        // System.out.println( l_out ) ;
+        assertEquals( "ou=People", out ) ;
+
+        // Add to the head (first): cn=John,ou=Marketing,ou=East
+        out = name.add( 0, "ou=East" ).toString() ;
+        
+        assertEquals( "cn=John,ou=Marketing,ou=East", out ) ;
+        
+        // Add to the tail (last): cn=HomeDir,cn=John,ou=Marketing,ou=East
+        out = name.add( "cn=HomeDir" ).toString() ;
+        
+        assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", out ) ;
+    }
+    
+    public void testAttributeEqualsIsCaseInSensitive() throws Exception
+    {
+        Name name1 = new LdapDN( "cn=HomeDir" );
+        Name name2 = new LdapDN( "CN=HomeDir" );
+
+        assertTrue( name1.equals( name2 ) );
+    }
+
+
+    public void testAttributeTypeEqualsIsCaseInsensitive() throws Exception
+    {
+        Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
+        Name name2 = new LdapDN( "cn=HomeDir+CN=WorkDir" );
+
+        assertTrue( name1.equals( name2 ) );
+    }
+
+
+    public void testNameEqualsIsInsensitiveToAttributesOrder() throws Exception
+    {
+
+        Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
+        Name name2 = new LdapDN( "cn=WorkDir+cn=HomeDir" );
+
+        assertTrue( name1.equals( name2 ) );
+    }
+
+
+    public void testAttributeComparisonIsCaseInSensitive() throws Exception
+    {
+        Name name1 = new LdapDN( "cn=HomeDir" );
+        Name name2 = new LdapDN( "CN=HomeDir" );
+
+        assertEquals( 0, name1.compareTo( name2 ) );
+    }
+
+
+    public void testAttributeTypeComparisonIsCaseInsensitive() throws Exception
+    {
+        Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
+        Name name2 = new LdapDN( "cn=HomeDir+CN=WorkDir" );
+
+        assertEquals( 0, name1.compareTo( name2 ) );
+    }
+
+
+    public void testNameComparisonIsInsensitiveToAttributesOrder() throws Exception
+    {
+
+        Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
+        Name name2 = new LdapDN( "cn=WorkDir+cn=HomeDir" );
+
+        assertEquals( 0, name1.compareTo( name2 ) );
+    }
+    
+    public void testNameComparisonIsInsensitiveToAttributesOrderFailure() throws Exception
+    {
+
+        Name name1 = new LdapDN( "cn=HomeDir+cn=Workdir" );
+        Name name2 = new LdapDN( "cn=Work+cn=HomeDir" );
+
+        assertEquals( -1, name1.compareTo( name2 ) );
+    }
+    
+    /**
+     * Test the encoding of a LdanDN
+     *
+     */
+    public void testNameToBytes() throws Exception
+    {
+        LdapDN dn = new LdapDN( "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" ) );
+    }
+}

Added: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java?rev=307437&view=auto
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java (added)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapRDNTest.java Sun Oct  9 06:57:46 2005
@@ -0,0 +1,336 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1new.ldap.codec.primitives;
+
+import javax.naming.InvalidNameException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1new.ldap.codec.primitives.LdapRDN;
+
+/**
+ * Test the class LdapRDN
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapRDNTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    /**
+     * Test a null RDN
+     */
+    public void testLdapRDNNull() throws InvalidNameException
+    {
+        Assert.assertEquals( "", new LdapRDN().toString() );
+    }
+
+    /**
+     * test an empty RDN
+     */
+    public void testLdapRDNEmpty() throws InvalidNameException
+    {
+        Assert.assertEquals( "", new LdapRDN( "" ).toString() );
+    }
+
+    /**
+     * test a simple RDN : a = b
+     */
+    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() );
+    }
+
+    /**
+     * test a simple RDN with differents separators : a = b + c = d
+     */
+    public void testLdapRDNSimpleMultivaluedAttribute() throws InvalidNameException
+    {
+        String result = new LdapRDN( "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 testLdapRDNCompositeMultivaluedAttribute() throws InvalidNameException
+    {
+        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 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() );
+    }
+
+    /**
+     * test a simple RDN with hexString attribute value : a = #0010A0AAFF
+     */
+    public void testLdapRDNHexStringAttributeValue() throws InvalidNameException
+    {
+        Assert.assertEquals( "a=#0010A0AAFF",
+                new LdapRDN( "a = #0010A0AAFF" ).toString() );
+    }
+
+    /**
+     * test a simple RDN with quoted attribute value : a = "quoted \"value"
+     */
+    public void testLdapRDNQuotedAttributeValue() throws InvalidNameException
+    {
+        Assert.assertEquals( "a=quoted \\\"value",
+                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.removeAttributeTypeAndValue( "a" );
+        
+        RDNParser.parse( "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.addAttributeTypeAndValue( "aa", "bb" );
+        
+        LdapRDN rdnClone = (LdapRDN)rdn.clone();
+        
+        rdn.removeAttributeTypeAndValue( "aa" );
+        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 clone method for a RDN.
+     */
+    public void testRDNRemoveNameComponent() throws InvalidNameException
+    {
+        LdapRDN rdn = new LdapRDN( " a = b + c = d + a = f + g = h " );
+        rdn.removeAttributeTypeAndValue( "a" );
+        Assert.assertEquals( "c=d+g=h", rdn.toString() );
+    }
+
+    /**
+     * Test the compareTo method for a RDN.
+     */
+    public void testRDNCompareToNull() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b + c = d + a = f + g = h " );
+        LdapRDN rdn2 = null;
+        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * 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 ) );
+    }
+
+    /**
+     * Compares a single NC to a composite NC.
+     */
+    public void testRDNCompareToNC2NCS() throws InvalidNameException
+    {
+        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 ) );
+    }
+
+    /**
+     * Compares a composite NCS to a composite NCS in the same order.
+     */
+    public void testRDNCompareToNCS2NCSOrdered() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b + c = d + a = f + g = h " );
+        LdapRDN rdn2 = new LdapRDN( " a = b + c = d + a = f + g = h " );
+
+        Assert.assertEquals( LdapRDN.EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * Compares a composite NCS to a composite NCS in a different order.
+     */
+    public void testRDNCompareToNCS2NCSUnordered() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b + a = f + g = h + c = d " );
+        LdapRDN rdn2 = new LdapRDN( " a = b + c = d + a = f + g = h " );
+
+        Assert.assertEquals( LdapRDN.EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * Compares a composite NCS to a different composite NCS.
+     */
+    public void testRDNCompareToNCS2NCSNotEquals() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = f + g = h + c = d " );
+        LdapRDN rdn2 = new LdapRDN( " c = d + a = h + g = h " );
+
+        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * Compares a simple NC to a simple NC.
+     */
+    public void testRDNCompareToNC2NC() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b " );
+        LdapRDN rdn2 = new LdapRDN( " a = b " );
+
+        Assert.assertEquals( LdapRDN.EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * Compares a simple NC to a simple NC in UperCase.
+     */
+    public void testRDNCompareToNC2NCUperCase() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b " );
+        LdapRDN rdn2 = new LdapRDN( " A = B " );
+
+        Assert.assertEquals( LdapRDN.EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+
+    /**
+     * Compares a simple NC to a different simple NC.
+     */
+    public void testRDNCompareToNC2NCNotEquals() throws InvalidNameException
+    {
+        LdapRDN rdn1 = new LdapRDN( " a = b " );
+        LdapRDN rdn2 = new LdapRDN( " A = d " );
+
+        Assert.assertEquals( LdapRDN.NOT_EQUALS, rdn1.compareTo( rdn2 ) );
+    }
+}
+

Added: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapStringTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapStringTest.java?rev=307437&view=auto
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapStringTest.java (added)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapStringTest.java Sun Oct  9 06:57:46 2005
@@ -0,0 +1,104 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1new.ldap.codec.primitives;
+
+import java.io.UnsupportedEncodingException;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the class LdapString
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapStringTest extends TestCase
+{
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Setup the test
+     */
+    protected void setUp()
+    {
+    }
+
+    // CONSTRUCTOR functions --------------------------------------------------
+    
+    /**
+     * Test a null LdapString
+     */
+    public void testLdapStringNull() throws LdapStringEncodingException
+    {
+        LdapString ls = new LdapString();
+        
+        Assert.assertEquals( "", ls.getString() );
+    }
+    
+    /**
+     * Test an empty LdapString
+     */
+    public void testLdapStringEmpty() throws LdapStringEncodingException, UnsupportedEncodingException
+    {
+        LdapString ls = new LdapString( "".getBytes( "UTF-8" ) );
+        
+        Assert.assertEquals( "", ls.getString() );
+    }
+    
+    /**
+     * Test an ASCII LdapString
+     */
+    public void testLdapStringASCII() throws LdapStringEncodingException, UnsupportedEncodingException
+    {
+        LdapString ls = new LdapString( "azerty".getBytes( "UTF-8" ) );
+        
+        Assert.assertEquals( "azerty", ls.getString() );
+    }
+    
+    /**
+     * Test a european LdapString
+     */
+    public void testLdapStringEuropean() throws LdapStringEncodingException, UnsupportedEncodingException
+    {
+        LdapString ls = new LdapString( "J\u00e9r\u00f4me".getBytes( "UTF-8" ) );
+        
+        Assert.assertEquals( "Jérôme", ls.getString() );
+        Assert.assertEquals( 8, ls.getNbBytes() );
+        Assert.assertEquals( "Jérôme" , new String( ls.getBytes(), "UTF-8" ) );
+    }
+
+    /**
+     * Test the bytes LdapString constructor
+     */
+    public void testLdapStringBytes() throws LdapStringEncodingException, UnsupportedEncodingException
+    {
+        LdapString ls = new LdapString( new byte[]{'J', (byte)0xc3, (byte)0xa9, 'r', (byte)0xc3, (byte)0xb4, 'm', 'e'} );
+        
+        Assert.assertEquals( "Jérôme", ls.getString() );
+        Assert.assertEquals( 8, ls.getNbBytes() );
+        Assert.assertEquals( "Jérôme" , new String( ls.getBytes(), "UTF-8" ) );
+    }
+
+    /**
+     * Test a wrong LdapString
+     */
+    public void testWrongLdapStringBytes() throws LdapStringEncodingException, UnsupportedEncodingException
+    {
+        LdapString ls = new LdapString( new byte[]{'J', (byte)0xe3, (byte)0xc9, 'r', (byte)0xc3, (byte)0xb4, 'm', 'e'} );
+        Assert.assertEquals( "J\ufffd\ufffdrôme" ,ls.getString() );
+    }
+}

Copied: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java (from r292344, directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java)
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java?p2=directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java&p1=directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java&r1=292344&r2=307437&rev=307437&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/utils/LdapUrlTest.java (original)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java Sun Oct  9 06:57:46 2005
@@ -14,7 +14,7 @@
  *   limitations under the License.
  *
  */
-package org.apache.asn1new.ldap.codec.utils;
+package org.apache.asn1new.ldap.codec.primitives;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -41,7 +41,7 @@
     /**
      * Test a null LdapURL
      */
-    public void testLdapUrlNull() throws DecoderException
+    public void testLdapUrlNull() throws LdapURLEncodingException
     {
         Assert.assertEquals( "ldap:///", new LdapURL().toString() );
     }
@@ -49,37 +49,37 @@
     /**
      * test an empty LdapURL
      */
-    public void testLdapDNEmpty() throws DecoderException
+    public void testLdapDNEmpty() throws LdapURLEncodingException
     {
-        Assert.assertEquals( "ldap:///", new LdapURL( "".getBytes() ).toString() );
+        Assert.assertEquals( "ldap:///", new LdapURL( "" ).toString() );
     }
 
     /**
      * test a simple LdapURL
      */
-    public void testLdapDNSimple() throws DecoderException
+    public void testLdapDNSimple() throws LdapURLEncodingException
     {
-        Assert.assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/".getBytes() ).toString() );
+        Assert.assertEquals( "ldap://directory.apache.org:80/", new LdapURL( "ldap://directory.apache.org:80/" ).toString() );
     }
 
     /**
      * test a LdapURL host 1
      */
-    public void testLdapDNWithMinus() throws DecoderException
+    public void testLdapDNWithMinus() throws LdapURLEncodingException
     {
-        Assert.assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/".getBytes() ).toString() );
+        Assert.assertEquals( "ldap://d-a.org:80/", new LdapURL( "ldap://d-a.org:80/" ).toString() );
     }
 
     /**
      * test a LdapURL with a bad port
      */
-    public void testLdapDNBadPort() throws DecoderException
+    public void testLdapDNBadPort() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:/".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -91,13 +91,13 @@
     /**
      * test a LdapURL with a bad port 2
      */
-    public void testLdapDNBadPort2() throws DecoderException
+    public void testLdapDNBadPort2() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:-1/".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:-1/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -109,13 +109,13 @@
     /**
      * test a LdapURL with a bad port 3
      */
-    public void testLdapDNBadPort3() throws DecoderException
+    public void testLdapDNBadPort3() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:abc/".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:abc/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -127,13 +127,13 @@
     /**
      * test a LdapURL with a bad port 4
      */
-    public void testLdapDNBadPort4() throws DecoderException
+    public void testLdapDNBadPort4() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:65536/".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:65536/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -145,21 +145,21 @@
     /**
      * test a LdapURL with no host 
      */
-    public void testLdapDNBadHost1() throws DecoderException
+    public void testLdapDNBadHost1() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap:///", new LdapURL( "ldap:///".getBytes() ).toString() );
+        Assert.assertEquals("ldap:///", new LdapURL( "ldap:///" ).toString() );
     }
 
     /**
      * test a LdapURL with a bad host 2
      */
-    public void testLdapDNBadHost2() throws DecoderException
+    public void testLdapDNBadHost2() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://./".getBytes() );
+            new LdapURL( "ldap://./" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -171,13 +171,13 @@
     /**
      * test a LdapURL with a bad host 3
      */
-    public void testLdapDNBadHost3() throws DecoderException
+    public void testLdapDNBadHost3() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://a..b/".getBytes() );
+            new LdapURL( "ldap://a..b/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -189,13 +189,13 @@
     /**
      * test a LdapURL with a bad host 4
      */
-    public void testLdapDNBadHost4() throws DecoderException
+    public void testLdapDNBadHost4() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://-/".getBytes() );
+            new LdapURL( "ldap://-/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -207,13 +207,13 @@
     /**
      * test a LdapURL with a bad host 5
      */
-    public void testLdapDNBadHost5() throws DecoderException
+    public void testLdapDNBadHost5() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://a.b.c-/".getBytes() );
+            new LdapURL( "ldap://a.b.c-/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -225,13 +225,13 @@
     /**
      * test a LdapURL with a bad host 6
      */
-    public void testLdapDNBadHost6() throws DecoderException
+    public void testLdapDNBadHost6() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://a.b.-c/".getBytes() );
+            new LdapURL( "ldap://a.b.-c/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -243,13 +243,13 @@
     /**
      * test a LdapURL with a bad host 7
      */
-    public void testLdapDNBadHost7() throws DecoderException
+    public void testLdapDNBadHost7() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://a.-.c/".getBytes() );
+            new LdapURL( "ldap://a.-.c/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -261,29 +261,29 @@
     /**
      * test a LdapURL IP host
      */
-    public void testLdapDNIPHost() throws DecoderException
+    public void testLdapDNIPHost() throws LdapURLEncodingException
     {
-        Assert.assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/".getBytes() ).toString() );
+        Assert.assertEquals( "ldap://1.2.3.4/", new LdapURL( "ldap://1.2.3.4/" ).toString() );
     }
 
     /**
      * test a LdapURL IP host and port
      */
-    public void testLdapDNIPHostPort() throws DecoderException
+    public void testLdapDNIPHostPort() throws LdapURLEncodingException
     {
-        Assert.assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/".getBytes() ).toString() );
+        Assert.assertEquals( "ldap://1.2.3.4:80/", new LdapURL( "ldap://1.2.3.4:80/" ).toString() );
     }
 
     /**
      * test a LdapURL with a bad IP host 1
      */
-    public void testLdapDNBadHostIP1() throws DecoderException
+    public void testLdapDNBadHostIP1() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://1.1.1/".getBytes() );
+            new LdapURL( "ldap://1.1.1/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -295,13 +295,13 @@
     /**
      * test a LdapURL with a bad IP host 2
      */
-    public void testLdapDNBadHostIP2() throws DecoderException
+    public void testLdapDNBadHostIP2() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://1.1.1./".getBytes() );
+            new LdapURL( "ldap://1.1.1./" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -313,13 +313,13 @@
     /**
      * test a LdapURL with a bad IP host 3
      */
-    public void testLdapDNBadHostIP3() throws DecoderException
+    public void testLdapDNBadHostIP3() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://1.1.1.100000/".getBytes() );
+            new LdapURL( "ldap://1.1.1.100000/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -331,13 +331,13 @@
     /**
      * test a LdapURL with a bad IP host 4
      */
-    public void testLdapDNBadHostIP4() throws DecoderException
+    public void testLdapDNBadHostIP4() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://1.1.1.1.1/".getBytes() );
+            new LdapURL( "ldap://1.1.1.1.1/" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -349,45 +349,48 @@
     /**
      * test a LdapURL with a valid host hich is not an IP
      */
-    public void testLdapDNNotAnIP() throws DecoderException
+    public void testLdapDNNotAnIP() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/".getBytes() ).toString() );
+        Assert.assertEquals("ldap://1.1.1.100000.a/", new LdapURL( "ldap://1.1.1.100000.a/" ).toString() );
     }
 
     /**
      * test a LdapURL with valid simpleDN
      */
-    public void testLdapDNSimpleDN() throws DecoderException
+    public void testLdapDNSimpleDN() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org/", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org/".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org/", 
+                new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org/" ).toString() );
     }
 
     /**
      * test a LdapURL with valid simpleDN 2
      */
-    public void testLdapDNSimpleDN2() throws DecoderException
+    public void testLdapDNSimpleDN2() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example", new LdapURL( "ldap://directory.apache.org:389/dc=example".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example", 
+                new LdapURL( "ldap://directory.apache.org:389/dc=example" ).toString() );
     }
 
     /**
      * test a LdapURL with a valid encoded DN
      */
-    public void testLdapDNSimpleDNEncoded() throws DecoderException
+    public void testLdapDNSimpleDNEncoded() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example%202,dc=org", new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc=org".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example%202,dc=org", 
+                new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc=org" ).toString() );
     }
     
     /**
      * test a LdapURL with an invalid DN
      */
-    public void testLdapDNInvalidDN() throws DecoderException
+    public void testLdapDNInvalidDN() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc : org".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc : org" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -397,13 +400,13 @@
     /**
      * test a LdapURL with an invalid DN 2
      */
-    public void testLdapDNInvalidDN2() throws DecoderException
+    public void testLdapDNInvalidDN2() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc = org,".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:389/dc=example%202,dc = org," );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -413,37 +416,40 @@
     /**
      * test a LdapURL with valid unique attributes
      */
-    public void testLdapDNUniqueAttribute() throws DecoderException
+    public void testLdapDNUniqueAttribute() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou",
+                new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou" ).toString() );
     }
 
     /**
      * test a LdapURL with valid attributes
      */
-    public void testLdapDNAttributes() throws DecoderException
+    public void testLdapDNAttributes() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc", 
+                new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,objectclass,dc" ).toString() );
     }
 
     /**
      * test a LdapURL with valid duplicated attributes
      */
-    public void testLdapDNDuplicatedAttributes() throws DecoderException
+    public void testLdapDNDuplicatedAttributes() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou".getBytes() ).toString() );
+        Assert.assertEquals("ldap://directory.apache.org:389/dc=example,dc=org?ou,dc", 
+                new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou,dc,ou" ).toString() );
     }
 
     /**
      * test a LdapURL with invalid attributes
      */
-    public void testLdapInvalideAttributes() throws DecoderException
+    public void testLdapInvalideAttributes() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou=,dc".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:389/dc=example,dc=org?ou=,dc" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -452,13 +458,13 @@
     /**
      * test a LdapURL with attributes but no DN
      */
-    public void testLdapNoDNAttributes() throws DecoderException
+    public void testLdapNoDNAttributes() throws LdapURLEncodingException
     {
         try 
         {
-            new LdapURL( "ldap://directory.apache.org:389/?ou,dc".getBytes() );
+            new LdapURL( "ldap://directory.apache.org:389/?ou,dc" );
         }
-        catch (DecoderException de)
+        catch (LdapURLEncodingException luee)
         {
             Assert.assertTrue(true);
             return;
@@ -468,73 +474,82 @@
     /**
      * test 1 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_1() throws DecoderException
+    public void testLdapRFC2255_1() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap:///o=University%20of%20Michigan,c=US", new LdapURL( "ldap:///o=University%20of%20Michigan,c=US".getBytes() ).toString() );
+        Assert.assertEquals("ldap:///o=University%20of%20Michigan,c=US", 
+                new LdapURL( "ldap:///o=University%20of%20Michigan,c=US" ).toString() );
     }
     
     /**
      * test 2 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_2() throws DecoderException
+    public void testLdapRFC2255_2() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US".getBytes() ).toString() );
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US", 
+                new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US" ).toString() );
     }
 
     /**
      * test 3 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_3() throws DecoderException
+    public void testLdapRFC2255_3() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress".getBytes() ).toString() );
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress", 
+                new LdapURL( "ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US?postalAddress" ).toString() );
     }
 
     /**
      * test 4 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_4() throws DecoderException
+    public void testLdapRFC2255_4() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", new LdapURL( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)".getBytes() ).toString() );
+        Assert.assertEquals("ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)", 
+                new LdapURL( "ldap://host.com:6666/o=University%20of%20Michigan,c=US??sub?(cn=Babs%20Jensen)" ).toString() );
     }
 
     /**
      * test 5 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_5() throws DecoderException
+    public void testLdapRFC2255_5() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://ldap.itd.umich.edu/c=GB?objectClass?one", new LdapURL( "ldap://ldap.itd.umich.edu/c=GB?objectClass?one".getBytes() ).toString() );
+        Assert.assertEquals("ldap://ldap.itd.umich.edu/c=GB?objectClass?one", 
+                new LdapURL( "ldap://ldap.itd.umich.edu/c=GB?objectClass?one" ).toString() );
     }
 
     /**
      * test 6 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_6() throws DecoderException
+    public void testLdapRFC2255_6() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://ldap.question.com/o=Question%3f,c=US?mail", new LdapURL( "ldap://ldap.question.com/o=Question%3f,c=US?mail".getBytes() ).toString() );
+        Assert.assertEquals("ldap://ldap.question.com/o=Question%3f,c=US?mail", 
+                new LdapURL( "ldap://ldap.question.com/o=Question%3f,c=US?mail" ).toString() );
     }
 
     /**
      * test 7 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_7() throws DecoderException
+    public void testLdapRFC2255_7() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", new LdapURL( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)".getBytes() ).toString() );
+        Assert.assertEquals("ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)", 
+                new LdapURL( "ldap://ldap.netscape.com/o=Babsco,c=US???(int=%5c00%5c00%5c00%5c04)" ).toString() );
     }
 
     /**
      * test 8 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_8() throws DecoderException
+    public void testLdapRFC2255_8() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap:///??sub??bindname=cn=Manager%2co=Foo", new LdapURL( "ldap:///??sub??bindname=cn=Manager%2co=Foo".getBytes() ).toString() );
+        Assert.assertEquals("ldap:///??sub??bindname=cn=Manager%2co=Foo", 
+                new LdapURL( "ldap:///??sub??bindname=cn=Manager%2co=Foo" ).toString() );
     }
 
     /**
      * test 9 from RFC 2255 LdapURL 
      */
-    public void testLdapRFC2255_9() throws DecoderException
+    public void testLdapRFC2255_9() throws LdapURLEncodingException
     {
-        Assert.assertEquals("ldap:///??sub??!bindname=cn=Manager%2co=Foo", new LdapURL( "ldap:///??sub??!bindname=cn=Manager%2co=Foo".getBytes() ).toString() );
+        Assert.assertEquals("ldap:///??sub??!bindname=cn=Manager%2co=Foo", 
+                new LdapURL( "ldap:///??sub??!bindname=cn=Manager%2co=Foo" ).toString() );
     }
 }
 

Propchange: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/primitives/LdapUrlTest.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message