Projects >> directory-shared >>41237579d1f8285ee8ed27cc241eb1126cc344b4

Chunk
Conflicting content
import junit.framework.Assert;
import junit.framework.TestCase;

<<<<<<< HEAD
import junit.framework.Assert;
import junit.framework.TestCase;

=======
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.asn1.primitives.BitString;
import org.apache.directory.shared.asn1.util.Asn1StringUtils;
Solution content
import junit.framework.Assert;
import junit.framework.TestCase;

import org.apache.directory.shared.asn1.codec.EncoderException;
import org.apache.directory.shared.asn1.primitives.BitString;
import org.apache.directory.shared.asn1.util.Asn1StringUtils;
File
ValueTest.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
    {
        byte[] encoded = null;
        int[] testedInt = new int[]
<<<<<<< HEAD
            { Integer.MIN_VALUE, -2147483647, -16777216, -16777215, -8388608, -8388607, -65536, -65535, -32768, -32767,
                -256, -255, -128, -127, -1, 0, 1, 127, 128, 255, 256, 32767, 32768, 65535, 65536, 8388607, 8388608,
                16777215, 16777216, Integer.MAX_VALUE };
=======
            { 
                Integer.MIN_VALUE, 
                -2147483647, 
                -16777216, 
                -16777215, 
                -8388608, 
                -8388607, 
                -65536, 
                -65535, 
                -32768, 
                -32767,
                -256, 
                -255, 
                -128, 
                -127, 
                -1, 
                0, 
                1, 
                127, 
                128, 
                255, 
                256, 
                32767, 
                32768, 
                65535, 
                65536, 
                8388607, 
                8388608,
                16777215, 
                16777216, 
                Integer.MAX_VALUE };
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903

        for ( int i:testedInt )
        {
Solution content
    {
        byte[] encoded = null;
        int[] testedInt = new int[]
            { 
                Integer.MIN_VALUE, 
                -2147483647, 
                -16777216, 
                -16777215, 
                -8388608, 
                -8388607, 
                -65536, 
                -65535, 
                -32768, 
                -32767,
                -256, 
                -255, 
                -128, 
                -127, 
                -1, 
                0, 
                1, 
                127, 
                128, 
                255, 
                256, 
                32767, 
                32768, 
                65535, 
                65536, 
                8388607, 
                8388608,
                16777215, 
                16777216, 
                Integer.MAX_VALUE };

        for ( int i:testedInt )
        {
File
ValueTest.java
Developer's decision
Version 1
Kind of conflict
Array initializer
Chunk
Conflicting content
    {
        byte[] encoded = null;
        int[] testedInt = new int[]
<<<<<<< HEAD
            { Integer.MIN_VALUE, -2147483647, -16777216, -16777215, -8388608, -8388607, -65536, -65535, -32768, -32767,
                -256, -255, -128, -127, -1, 0, 1, 127, 128, 255, 256, 32767, 32768, 65535, 65536, 8388607, 8388608,
                16777215, 16777216, Integer.MAX_VALUE };
=======
            { 
                Integer.MIN_VALUE, 
                -2147483647, 
                -16777216, 
                -16777215, 
                -8388608, 
                -8388607, 
                -65536, 
                -65535, 
                -32768, 
                -32767,
                -256, 
                -255, 
                -128, 
                -127, 
                -1, 0, 
                1, 
                127, 
                128, 
                255, 
                256, 
                32767, 
                32768, 
                65535, 
                65536, 
                8388607, 
                8388608,
                16777215, 
                16777216, 
                Integer.MAX_VALUE };
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903

        for ( int i:testedInt )
        {
Solution content
    {
        byte[] encoded = null;
        int[] testedInt = new int[]
            { 
                Integer.MIN_VALUE, 
                -2147483647, 
                -16777216, 
                -16777215, 
                -8388608, 
                -8388607, 
                -65536, 
                -65535, 
                -32768, 
                -32767,
                -256, 
                -255, 
                -128, 
                -127, 
                -1, 0, 
                1, 
                127, 
                128, 
                255, 
                256, 
                32767, 
                32768, 
                65535, 
                65536, 
                8388607, 
                8388608,
                16777215, 
                16777216, 
                Integer.MAX_VALUE };

        for ( int i:testedInt )
        {
File
ValueTest.java
Developer's decision
Version 1
Kind of conflict
Array initializer
Chunk
Conflicting content
        {
            sb.append( '/' ).append( urlEncode( dn.toString(), false ) );

<<<<<<< HEAD
            if ( ( attributes.size() != 0 )
=======
            if ( attributes.size() != 0 || forceScopeRendering
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                || ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || 
                    ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 ) ) )
            {
Solution content
        {
            sb.append( '/' ).append( urlEncode( dn.toString(), false ) );

            if ( attributes.size() != 0 || forceScopeRendering
                || ( ( scope != SearchControls.OBJECT_SCOPE ) || ( filter != null ) || 
                    ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 ) ) )
            {
File
LdapURL.java
Developer's decision
Version 2
Kind of conflict
If statement
Chunk
Conflicting content
    
                        if ( filter != null )
                        {
<<<<<<< HEAD
                            for ( String key:extensions.keySet() )
                            {

                                if ( !isFirst )
                                {
                                    sb.append( ',' );
                                }
                                else
                                {
                                    isFirst = false;
                                }

                                sb.append( urlEncode( key, false ) ).append( '=' ).append(
                                    urlEncode( extensions.get( key ), true ) );
                            }
=======
                            sb.append( urlEncode( filter, false ) );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                        }
    
                        if ( ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 ) )
Solution content
    
                        if ( filter != null )
                        {
                            sb.append( urlEncode( filter, false ) );
                        }
    
                        if ( ( extensions.size() != 0 ) || ( criticalExtensions.size() != 0 ) )
File
LdapURL.java
Developer's decision
Version 2
Kind of conflict
For statement
Method invocation
Chunk
Conflicting content
    
                            if ( extensions.size() != 0 )
                            {
<<<<<<< HEAD

                                if ( !isFirst )
=======
                                for ( String key:extensions.keySet() )
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                                {
    
                                    if ( !isFirst )
Solution content
    
                            if ( extensions.size() != 0 )
                            {
                                for ( String key:extensions.keySet() )
                                {
    
                                    if ( !isFirst )
File
LdapURL.java
Developer's decision
Version 2
Kind of conflict
For statement
If statement
Chunk
Conflicting content
        }
    }

<<<<<<< HEAD
=======
    
    /**
     * If set to true forces the toString method to render the scope 
     * regardless of optional nature.  Use this when you want explicit
     * search URL scope rendering.
     * 
     * @param forceScopeRendering the forceScopeRendering to set
     */
    public void setForceScopeRendering( boolean forceScopeRendering )
    {
        this.forceScopeRendering = forceScopeRendering;
    }

    
    /**
     * If set to true forces the toString method to render the scope 
     * regardless of optional nature.  Use this when you want explicit
     * search URL scope rendering.
     * 
     * @return the forceScopeRendering
     */
    public boolean isForceScopeRendering()
    {
        return forceScopeRendering;
    }

>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
}
Solution content
     */
        }
    }

    
    /**
     * If set to true forces the toString method to render the scope 
     * regardless of optional nature.  Use this when you want explicit
     * search URL scope rendering.
     * 
     * @param forceScopeRendering the forceScopeRendering to set
    public void setForceScopeRendering( boolean forceScopeRendering )
    {
        this.forceScopeRendering = forceScopeRendering;
    }

    
    /**
     * If set to true forces the toString method to render the scope 
     * regardless of optional nature.  Use this when you want explicit
     * search URL scope rendering.
     * 
     * @return the forceScopeRendering
     */
    public boolean isForceScopeRendering()
    {
        return forceScopeRendering;
    }

}
File
LdapURL.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
package org.apache.directory.shared.ldap.entry;


<<<<<<< HEAD
=======
import java.io.Externalizable;
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
import java.util.Iterator;
import java.util.List;
Solution content
package org.apache.directory.shared.ldap.entry;


import java.io.Externalizable;
import java.util.Iterator;
import java.util.List;
File
Entry.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
package org.apache.directory.shared.ldap.entry.client;


<<<<<<< HEAD
=======
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
Solution content
package org.apache.directory.shared.ldap.entry.client;


import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
File
DefaultClientAttribute.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
     */
    public AndNode( List childList )
    {
<<<<<<< HEAD
        super( childList, AssertionType.AND );
=======
        super( AssertionType.AND, childList );
    }


    /**
     * Creates a AndNode using a logical operator and a list of children.
     * 
     * @param childList the child nodes under this branch node.
     */
    public AndNode( ExprNode... childList )
    {
        super( AssertionType.AND, childList );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    }

Solution content
     */
    public AndNode( List childList )
    {
        super( AssertionType.AND, childList );
    }


    /**
     * Creates a AndNode using a logical operator and a list of children.
     * 
     * @param childList the child nodes under this branch node.
     */
    public AndNode( ExprNode... childList )
    {
        super( AssertionType.AND, childList );
    }

File
AndNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Method invocation
Method signature
Chunk
Conflicting content

    /**
<<<<<<< HEAD
=======
     * @see ExprNode#printRefinementToBuffer(StringBuilder) 
     */
    public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException
    {
        throw new UnsupportedOperationException( "AssertionNode can't be part of a refinement" );
    }


    /**
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     * @see Object#hashCode()
     * @return the instance's hash code 
     */
Solution content

    /**
     * @see ExprNode#printRefinementToBuffer(StringBuilder) 
     */
    public StringBuilder printRefinementToBuffer( StringBuilder buf ) throws UnsupportedOperationException
    {
        throw new UnsupportedOperationException( "AssertionNode can't be part of a refinement" );
    }


    /**
     * @see Object#hashCode()
     * @return the instance's hash code 
     */
File
AssertionNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
     * @param childList the child nodes under this branch node.
     * @param assertionType the node's type
     */
<<<<<<< HEAD
    protected BranchNode( List childList, AssertionType assertionType )
=======
    protected BranchNode( AssertionType assertionType, List childList )
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    {
        super( assertionType );
Solution content
     * @param childList the child nodes under this branch node.
     */
    protected BranchNode( AssertionType assertionType, List childList )
    {
        super( assertionType );
File
BranchNode.java
Developer's decision
Version 2
Kind of conflict
Method signature
Chunk
Conflicting content
        else
        {
            this.children = childList;
<<<<<<< HEAD
=======
        }
    }


    /**
     * Creates a BranchNode using a logical operator and a list of children.
     * 
     * @param assertionType the node's type
     * @param childList the child nodes under this branch node.
     */
    protected BranchNode( AssertionType assertionType, ExprNode... childList )
    {
        super( assertionType );

        if ( null == children )
        {
            this.children = new ArrayList( childList.length );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
        
        CollectionUtils.addAll( children, childList );
Solution content
        else
        {
            this.children = childList;
        }
    }


    /**
     * Creates a BranchNode using a logical operator and a list of children.
     * 
     * @param assertionType the node's type
     * @param childList the child nodes under this branch node.
     */
    protected BranchNode( AssertionType assertionType, ExprNode... childList )
    {
        super( assertionType );

        if ( null == children )
        {
            this.children = new ArrayList( childList.length );
        }
        
        CollectionUtils.addAll( children, childList );
File
BranchNode.java
Developer's decision
Version 2
Kind of conflict
Attribute
Comment
If statement
Method invocation
Method signature
Chunk
Conflicting content
    /**
     * Creates a new emptyExtensibleNode object.
     * 
<<<<<<< HEAD
     * @param attribute The attribute's ID for this node
=======
     * @param attribute the attribute associated with this node
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     */
    public ExtensibleNode( String attribute )
    {
Solution content
    /**
     * Creates a new emptyExtensibleNode object.
     * 
     * @param attribute the attribute associated with this node
     */
    public ExtensibleNode( String attribute )
    {
File
ExtensibleNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content
        {
            return false;
        }
<<<<<<< HEAD
            
=======

>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        return attribute.equals( ( ( LeafNode ) other ).getAttribute() );
    }
}
Solution content
        {
            return false;
        }

        return attribute.equals( ( ( LeafNode ) other ).getAttribute() );
    }
}
File
LeafNode.java
Developer's decision
Version 1
Kind of conflict
Blank
Chunk
Conflicting content
     */
    public OrNode( List childList)
    {
<<<<<<< HEAD
        super( childList, AssertionType.OR );
=======
        super( AssertionType.OR, childList );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    }

Solution content
     */
    public OrNode( List childList)
    {
        super( AssertionType.OR, childList );
    }

File
OrNode.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Chunk
Conflicting content
 * @author Apache Directory Project
 * @version $Revision$
 */
<<<<<<< HEAD
public class SimpleNode extends LeafNode
=======
public abstract class SimpleNode extends LeafNode
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
{
    /** the value */
    protected Value value;
Solution content
 * @author Apache Directory Project
 * @version $Revision$
 */
public abstract class SimpleNode extends LeafNode
{
    /** the value */
    protected Value value;
File
SimpleNode.java
Developer's decision
Version 2
Kind of conflict
Class signature
Chunk
Conflicting content
    /** the value */
    protected Value value;

<<<<<<< HEAD
    /** Constants for comparisons : > */
    public static final boolean EVAL_GREATER = true;
    
=======
    /* TODO - why are these here if not used? */
    /** Constants for comparisons : > */
    public static final boolean EVAL_GREATER = true;
    
    /* TODO - why are these here if not used? */
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    /** Constants for comparisons : < */
    public static final boolean EVAL_LESSER = false;
Solution content
    /** the value */
    protected Value value;

    /* TODO - why are these here if not used? */
    /** Constants for comparisons : > */
    public static final boolean EVAL_GREATER = true;
    
    /* TODO - why are these here if not used? */
    /** Constants for comparisons : < */
    public static final boolean EVAL_LESSER = false;
File
SimpleNode.java
Developer's decision
Version 2
Kind of conflict
Attribute
Comment
Chunk
Conflicting content
     * 
     * @param attribute the attribute name
     * @param value the value to test for
<<<<<<< HEAD
     * @param assertionType the node's type
=======
     * @param assertionType the type of assertion represented by this ExprNode
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     */
    protected SimpleNode( String attribute, Value value, AssertionType assertionType )
    {
Solution content
     * 
     * @param attribute the attribute name
     * @param value the value to test for
     * @param assertionType the type of assertion represented by this ExprNode
     */
    protected SimpleNode( String attribute, Value value, AssertionType assertionType )
    {
File
SimpleNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content

    /**
<<<<<<< HEAD
=======
     * Pretty prints this expression node along with annotation information.
     *
     * TODO - perhaps this belong in some utility class?
     *
     * @param buf the buffer to print into
     * @return the same buf argument returned for call chaining
     */
    public StringBuilder printToBuffer( StringBuilder buf )
    {
        if ( ( null != getAnnotations() ) && getAnnotations().containsKey( "count" ) )
        {
            buf.append( ":[" );
            buf.append( getAnnotations().get( "count" ).toString() );
            buf.append( "] " );
        }

        buf.append( ')' );

        return buf;
    }


    /**
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     * @see ExprNode#printRefinementToBuffer(StringBuilder)
     * @return The buffer in which the refinement has been appended
     * @throws UnsupportedOperationException if this node isn't a part of a refinement.
Solution content

    /**
     * Pretty prints this expression node along with annotation information.
     *
     * TODO - perhaps this belong in some utility class?
     *
     * @param buf the buffer to print into
     * @return the same buf argument returned for call chaining
     */
    public StringBuilder printToBuffer( StringBuilder buf )
    {
        if ( ( null != getAnnotations() ) && getAnnotations().containsKey( "count" ) )
        {
            buf.append( ":[" );
            buf.append( getAnnotations().get( "count" ).toString() );
            buf.append( "] " );
        }

        buf.append( ')' );

        return buf;
    }


    /**
     * @see ExprNode#printRefinementToBuffer(StringBuilder)
     * @return The buffer in which the refinement has been appended
     * @throws UnsupportedOperationException if this node isn't a part of a refinement.
File
SimpleNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Method declaration
Chunk
Conflicting content
     * Creates a new SubstringNode object without any value
     * 
     * @param attribute the name of the attribute to substring assert
<<<<<<< HEAD
     * @param attribute The attribute's ID
=======
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     */
    public SubstringNode( String attribute )
    {
Solution content
     * Creates a new SubstringNode object without any value
     * 
     * @param attribute the name of the attribute to substring assert
     */
    public SubstringNode( String attribute )
    {
File
SubstringNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content
     * 
     * @param normalizer the normalizer to use for pattern component normalization
     * @return the equivalent compiled regular expression
<<<<<<< HEAD
     * @param normalizer The normalizer to use for the substring expressions
     * @exception NamingException If the substring can't be normalized
     * @exception PatternSyntaxException If the regexp is invalid
=======
     * @throws NamingException if there are problems while normalizing
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     */
    public final Pattern getRegex( Normalizer normalizer ) throws NamingException
    {
Solution content
     * 
     * @param normalizer the normalizer to use for pattern component normalization
     * @return the equivalent compiled regular expression
     * @throws NamingException if there are problems while normalizing
     */
    public final Pattern getRegex( Normalizer normalizer ) throws NamingException
    {
File
SubstringNode.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content
package org.apache.directory.shared.ldap.ldif;

<<<<<<< HEAD
import java.io.Serializable;
=======
import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Solution content
package org.apache.directory.shared.ldap.ldif;

import java.io.Externalizable;
import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
<<<<<<< HEAD

import javax.naming.InvalidNameException;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;
import javax.naming.ldap.Control;

import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.AttributesImpl;
import org.apache.directory.shared.ldap.message.ModificationItemImpl;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.StringTools;
=======
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903

import javax.naming.InvalidNameException;
import javax.naming.NamingException;
Solution content
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.naming.InvalidNameException;
import javax.naming.NamingException;
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
     * 
     * @param attr The attribute to be added
     */
<<<<<<< HEAD
    public void addModificationItem( int modOp, Attribute attr )
=======
    public void addModificationItem( int modOp, EntryAttribute attr )
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    {
        if ( changeType == ChangeType.Modify )
        {
Solution content
     * 
     * @param attr The attribute to be added
     */
    public void addModificationItem( int modOp, EntryAttribute attr )
    {
        if ( changeType == ChangeType.Modify )
        {
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
Method signature
Chunk
Conflicting content
        {
            for ( Modification modif:modificationList )
            {
<<<<<<< HEAD
                ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), 
                    (Attribute) modif.getAttribute().clone() );
=======
                Modification modifClone = new ClientModification( modif.getOperation(), 
                    (EntryAttribute) modif.getAttribute().clone() );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                clone.modificationList.add( modifClone );
            }
        }
Solution content
        {
            for ( Modification modif:modificationList )
            {
                Modification modifClone = new ClientModification( modif.getOperation(), 
                    (EntryAttribute) modif.getAttribute().clone() );
                clone.modificationList.add( modifClone );
            }
        }
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
<<<<<<< HEAD
        {
            for ( String key:modificationItems.keySet() )
            {
                ModificationItemImpl modif = modificationItems.get( key );
                ModificationItemImpl modifClone = new ModificationItemImpl( modif.getModificationOp(), 
                    (Attribute) modif.getAttribute().clone() );
=======
                Modification modif = modificationItems.get( key );
                Modification modifClone = new ClientModification( modif.getOperation(), 
                    (EntryAttribute) modif.getAttribute().clone() );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                clone.modificationItems.put( key, modifClone );
            }
Solution content
        {
            for ( String key:modificationItems.keySet() )
            {
                Modification modif = modificationItems.get( key );
                Modification modifClone = new ClientModification( modif.getOperation(), 
                    (EntryAttribute) modif.getAttribute().clone() );
                clone.modificationItems.put( key, modifClone );
            }
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
        
        for ( EntryAttribute attribute:entry )
        {
<<<<<<< HEAD
            for ( NamingEnumeration attrs = attributes.getAll(); 
                  attrs.hasMoreElements(); 
                  attribute = attrs.nextElement())
            {
                if ( attribute == null )
                {
                    sb.append( "        Null attribute\n" );
                    continue;
                }
                
                sb.append( "        ").append( attribute.getID() ).append( ":\n" );
                Object value = null;
                
                for ( NamingEnumeration values = attribute.getAll(); 
                      values.hasMoreElements(); 
                      value = values.nextElement())
                {
                    if ( value instanceof String )
                    {
                        sb.append(  "            " ).append( (String)value ).append('\n' );
                    }
                    else
                    {
                        sb.append(  "            " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
                    }
=======
            if ( attribute == null )
            {
                sb.append( "        Null attribute\n" );
                continue;
            }
            
            sb.append( "        ").append( attribute.getId() ).append( ":\n" );
            
            for ( Value value:attribute )
            {
                if ( value instanceof ClientStringValue )
                {
                    sb.append(  "            " ).append( value.get() ).append('\n' );
                }
                else
                {
                    sb.append(  "            " ).append( StringTools.dumpBytes( (byte[])value.get() ) ).append('\n' );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                }
            }
        }
Solution content
        
        for ( EntryAttribute attribute:entry )
        {
            if ( attribute == null )
            {
                sb.append( "        Null attribute\n" );
                continue;
            }
            
            sb.append( "        ").append( attribute.getId() ).append( ":\n" );
            
            for ( Value value:attribute )
            {
                if ( value instanceof ClientStringValue )
                {
                    sb.append(  "            " ).append( value.get() ).append('\n' );
                }
                else
                {
                    sb.append(  "            " ).append( StringTools.dumpBytes( (byte[])value.get() ) ).append('\n' );
                }
            }
        }
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
For statement
If statement
Method invocation
Variable
Chunk
Conflicting content
            {
                for ( Value value:attribute )
                {
<<<<<<< HEAD
                    Object value = null;
                    for ( NamingEnumeration values = attribute.getAll(); 
                          values.hasMoreElements(); 
                          value = values.nextElement() )
                    {
                        if ( value instanceof String )
                        {
                            sb.append(  "                " ).append( (String)value ).append('\n' );
                        }
                        else
                        {
                            sb.append(  "                " ).append( StringTools.dumpBytes( (byte[]) value ) ).append('\n' );
                        }
=======
                    if ( value instanceof ClientStringValue )
                    {
                        sb.append(  "                " ).append( (String)value.get() ).append('\n' );
                    }
                    else
                    {
                        sb.append(  "                " ).append( StringTools.dumpBytes( (byte[]) value.get() ) ).append('\n' );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                    }
                }
            }
Solution content
            {
                for ( Value value:attribute )
                {
                    if ( value instanceof ClientStringValue )
                    {
                        sb.append(  "                " ).append( (String)value.get() ).append('\n' );
                    }
                    else
                    {
                        sb.append(  "                " ).append( StringTools.dumpBytes( (byte[]) value.get() ) ).append('\n' );
                    }
                }
            }
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
For statement
If statement
Method invocation
Variable
Chunk
Conflicting content
    {
        int result = 37;

<<<<<<< HEAD
        if ( dn != null )
        {
            result = result*17 + dn.hashCode();
=======
        if ( entry.getDn() != null )
        {
            result = result*17 + entry.getDn().hashCode();
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
        
        if ( changeType != null )
Solution content
    {
        int result = 37;

        if ( entry.getDn() != null )
        {
            result = result*17 + entry.getDn().hashCode();
        }
        
        if ( changeType != null )
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Variable
Chunk
Conflicting content
            {
                case Add :
                    // Checks the attributes
<<<<<<< HEAD
                    if ( attributes != null )
                    {
                        result = result * 17 + attributes.hashCode();
=======
                    if ( entry != null )
                    {
                        result = result * 17 + entry.hashCode();
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                    }
                    
                    break;
Solution content
            {
                case Add :
                    // Checks the attributes
                    if ( entry != null )
                    {
                        result = result * 17 + entry.hashCode();
                    }
                    
                    break;
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
If statement
Method invocation
Variable
Chunk
Conflicting content
                    {
                        result = result * 17 + modificationList.hashCode();
                        
<<<<<<< HEAD
                        for ( ModificationItem modification:modificationList )
=======
                        for ( Modification modification:modificationList )
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                        {
                            result = result * 17 + modification.hashCode();
                        }
Solution content
                    {
                        result = result * 17 + modificationList.hashCode();
                        
                        for ( Modification modification:modificationList )
                        {
                            result = result * 17 + modification.hashCode();
                        }
File
LdifEntry.java
Developer's decision
Version 2
Kind of conflict
For statement
Chunk
Conflicting content
import java.util.ArrayList;
import java.util.List;

<<<<<<< HEAD
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.ModificationItem;

import org.apache.directory.shared.ldap.message.AttributeImpl;
import org.apache.directory.shared.ldap.message.ModificationItemImpl;
=======
import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;

import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientModification;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.AttributeUtils;
Solution content
import java.util.ArrayList;
import java.util.List;

import javax.naming.NamingException;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;

import org.apache.directory.shared.ldap.entry.Entry;
import org.apache.directory.shared.ldap.entry.EntryAttribute;
import org.apache.directory.shared.ldap.entry.Modification;
import org.apache.directory.shared.ldap.entry.ModificationOperation;
import org.apache.directory.shared.ldap.entry.Value;
import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
import org.apache.directory.shared.ldap.entry.client.ClientModification;
import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
import org.apache.directory.shared.ldap.name.LdapDN;
import org.apache.directory.shared.ldap.name.Rdn;
import org.apache.directory.shared.ldap.util.AttributeUtils;
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Import
Chunk
Conflicting content
     */
    public static boolean isLDIFSafe( String str )
    {
<<<<<<< HEAD
=======
        if ( str == null )
        {
            // A null string is LDIF safe
            return true;
        }
        
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        // Checking the first char
        char currentChar = str.charAt(0);
        
Solution content
        }
     */
    public static boolean isLDIFSafe( String str )
    {
        if ( str == null )
        {
            // A null string is LDIF safe
            return true;
        
        // Checking the first char
        char currentChar = str.charAt(0);
        
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
If statement
Chunk
Conflicting content
        {
            return false;
        }
<<<<<<< HEAD
        
        // Checking the other chars
        for (int i = 1; i < str.length(); i++)
        {
            currentChar = str.charAt(i);
            
            if ( ( currentChar > 127 ) || !LDIF_SAFE_OTHER_CHARS_ALPHABET[currentChar] )
            {
                return false;
            }
        }
        
=======
        
        // Checking the other chars
        for (int i = 1; i < str.length(); i++)
        {
            currentChar = str.charAt(i);
            
            if ( ( currentChar > 127 ) || !LDIF_SAFE_OTHER_CHARS_ALPHABET[currentChar] )
            {
                return false;
            }
        }
        
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        // The String cannot end with a space
        return ( currentChar != ' ' );
    }
Solution content
        {
            return false;
        }
        
        // Checking the other chars
        for (int i = 1; i < str.length(); i++)
        {
            currentChar = str.charAt(i);
            
            if ( ( currentChar > 127 ) || !LDIF_SAFE_OTHER_CHARS_ALPHABET[currentChar] )
            {
                return false;
            }
        }
        
        // The String cannot end with a space
        return ( currentChar != ' ' );
    }
File
LdifUtils.java
Developer's decision
Version 1
Kind of conflict
Comment
For statement
Chunk
Conflicting content
    {
        StringBuilder sb = new StringBuilder();
        
<<<<<<< HEAD
        NamingEnumeration ne = attrs.getAll();
        
        while ( ne.hasMore() )
        {
            Object attribute = ne.next();
            
            if ( attribute instanceof Attribute ) 
            {
                sb.append( convertToLdif( (Attribute) attribute, length ) );
            }            
=======
        for ( EntryAttribute attribute:entry )
        {
            sb.append( convertToLdif( attribute, length ) );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
        
        return sb.toString();
Solution content
    {
        StringBuilder sb = new StringBuilder();
        
        for ( EntryAttribute attribute:entry )
        {
            sb.append( convertToLdif( attribute, length ) );
        }
        
        return sb.toString();
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
For statement
If statement
Method invocation
Variable
While statement
Chunk
Conflicting content
        
        return sb.toString();
    }
<<<<<<< HEAD
=======
    
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
    /**
     * Convert an Entry to LDIF
Solution content
        
        return sb.toString();
    }
    
    
    /**
     * Convert an Entry to LDIF
File
LdifUtils.java
Developer's decision
Version 1
Kind of conflict
Blank
Chunk
Conflicting content
     * @return the corresponding LDIF code as a String
     * @throws NamingException If a naming exception is encountered.
     */
<<<<<<< HEAD
    public static String convertToLdif( Attribute attr, int length ) throws NamingException
    {
        StringBuilder sb = new StringBuilder();
        
        // iterating on the attribute's values
        for ( int i = 0; i < attr.size(); i++ )
        {
            StringBuilder lineBuffer = new StringBuilder();
            
            lineBuffer.append( attr.getID() );
            
            Object value = attr.get( i );
=======
    public static String convertToLdif( EntryAttribute attr, int length ) throws NamingException
    {
        StringBuilder sb = new StringBuilder();
        
        for ( Value value:attr )
        {
            StringBuilder lineBuffer = new StringBuilder();
            
            lineBuffer.append( attr.getId() );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            
            // First, deal with null value (which is valid)
            if ( value == null )
Solution content
     * @return the corresponding LDIF code as a String
     * @throws NamingException If a naming exception is encountered.
     */
    public static String convertToLdif( EntryAttribute attr, int length ) throws NamingException
    {
        StringBuilder sb = new StringBuilder();
        
        for ( Value value:attr )
        {
            StringBuilder lineBuffer = new StringBuilder();
            
            lineBuffer.append( attr.getId() );
            
            // First, deal with null value (which is valid)
            if ( value == null )
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Comment
For statement
Method invocation
Method signature
Variable
Chunk
Conflicting content
            {
                lineBuffer.append( ':' );
            }
<<<<<<< HEAD
            else if ( value instanceof byte[] )
            {
                // It is binary, so we have to encode it using Base64 before adding it
                char[] encoded = Base64.encode( ( byte[] ) value );
=======
            else if ( value instanceof ClientBinaryValue )
            {
                // It is binary, so we have to encode it using Base64 before adding it
                char[] encoded = Base64.encode( ( byte[] ) value.get() );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                
                lineBuffer.append( ":: " + new String( encoded ) );                            
            }
Solution content
            {
                lineBuffer.append( ':' );
            }
            else if ( value instanceof ClientBinaryValue )
            {
                // It is binary, so we have to encode it using Base64 before adding it
                char[] encoded = Base64.encode( ( byte[] ) value.get() );
                
                lineBuffer.append( ":: " + new String( encoded ) );                            
            }
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Comment
If statement
Method invocation
Variable
Chunk
Conflicting content
            else if ( value instanceof ClientStringValue )
            {
                // It's a String but, we have to check if encoding isn't required
<<<<<<< HEAD
                String str = (String) value;
                
                if ( !LdifUtils.isLDIFSafe( str ) )
                {
                    lineBuffer.append( ":: " + encodeBase64( (String)value ) );
                }
                else
                {
                    lineBuffer.append( ": " + value );
=======
                String str = (String) value.get();
                
                if ( !LdifUtils.isLDIFSafe( str ) )
                {
                    lineBuffer.append( ":: " + encodeBase64( str ) );
                }
                else
                {
                    lineBuffer.append( ":" );
                    
                    if ( str != null) 
                    {
                        lineBuffer.append( " " ).append( str );
                    }
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                }
            }
            
Solution content
            else if ( value instanceof ClientStringValue )
            {
                // It's a String but, we have to check if encoding isn't required
                String str = (String) value.get();
                
                if ( !LdifUtils.isLDIFSafe( str ) )
                {
                    lineBuffer.append( ":: " + encodeBase64( str ) );
                }
                else
                {
                    lineBuffer.append( ":" );
                    
                    if ( str != null) 
                    {
                        lineBuffer.append( " " ).append( str );
                    }
                }
            }
            
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Cast expression
If statement
Method invocation
Variable
Chunk
Conflicting content
     * @param deletedEntry The entry which has been deleted
     * @return A reverse LDIF
     */
<<<<<<< HEAD
    public static LdifEntry reverseDel( LdapDN dn, Attributes deletedEntry )
=======
    public static LdifEntry reverseDel( LdapDN dn, Entry deletedEntry ) throws NamingException
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    {
        LdifEntry entry = new LdifEntry();
        
Solution content
     * @param deletedEntry The entry which has been deleted
     * @return A reverse LDIF
     */
    public static LdifEntry reverseDel( LdapDN dn, Entry deletedEntry ) throws NamingException
    {
        LdifEntry entry = new LdifEntry();
        
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Method signature
Chunk
Conflicting content
     * @return A new LDIF entry with a reverted DN
     * @throws NamingException If the name reverting failed
     */
<<<<<<< HEAD
    public static LdifEntry reverseRename( Attributes t0, LdapDN t0_dn, Rdn t1_rdn ) throws NamingException
=======
    public static List reverseRename( Attributes t0, LdapDN t0_dn, Rdn t1_rdn ) throws NamingException
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    {
        LdifEntry entry = new LdifEntry();
        LdapDN parent = null;
Solution content
     * @return A new LDIF entry with a reverted DN
     * @throws NamingException If the name reverting failed
     */
    public static List reverseRename( Attributes t0, LdapDN t0_dn, Rdn t1_rdn ) throws NamingException
    {
        LdifEntry entry = new LdifEntry();
        LdapDN parent = null;
File
LdifUtils.java
Developer's decision
Version 2
Kind of conflict
Method signature
Chunk
Conflicting content
                    {
                        escaped = true;
                        break;
<<<<<<< HEAD
                    }
                }

                // Here, we have a char to escape. Start again the loop...
                if ( escaped )
                {
                    for ( int i = 0; i < valueLength; i++ )
                    {
                        char c = chars[i];
                        
                        if ( ( c < 0) || ( c > 128 ) )
                        {
                            // For chars which are not ASCII, use their hexa value prefixed by an '\'
                            byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
                            
                            for ( byte b:bb )
                            {
                                sb.append( '\\' ).
                                    append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
                                    append( StringTools.dumpHex( b ) );
                            }
                        }
                        else if ( DN_ESCAPED_CHARS[ c ] ) 
                        {
                            // Some chars need to be escaped even if they are US ASCII
                            // Just prefix them with a '\'
                            // Special cases are ' ' (space), '#') which need a special
                            // treatment.
                            if ( c == ' ' )
                            {
                                if ( ( i == 0 ) || ( i == valueLength - 1 ) )
                                {
                                    sb.append( '\\' ).append(  c  );
                                }
                                else
                                {
                                    sb.append( ' ' );
                                }
    
                                continue;
                            }
                            else if ( c == '#' )
                            {
                                if ( i == 0 )
                                {
                                    sb.append( "\\#" );
                                    continue;
                                }
                                else
                                {
                                    sb.append( '#' );
                                }
                                
                                continue;
                            }
    
                            sb.append( '\\' ).append( c );
                        }
                        else
                        {
                            // Standard ASCII chars are just appended
                            sb.append( c );
                        }
                    }
                }
=======
                    }
                }

                // Here, we have a char to escape. Start again the loop...
                if ( escaped )
                {
                    for ( int i = 0; i < valueLength; i++ )
                    {
                        char c = chars[i];
                        
                        if ( ( c < 0) || ( c > 128 ) )
                        {
                            // For chars which are not ASCII, use their hexa value prefixed by an '\'
                            byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
                            
                            for ( byte b:bb )
                            {
                                sb.append( '\\' ).
                                    append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
                                    append( StringTools.dumpHex( b ) );
                            }
                        }
                        else if ( DN_ESCAPED_CHARS[ c ] ) 
                        {
                            // Some chars need to be escaped even if they are US ASCII
                            // Just prefix them with a '\'
                            // Special cases are ' ' (space), '#') which need a special
                            // treatment.
                            if ( c == ' ' )
                            {
                                if ( ( i == 0 ) || ( i == valueLength - 1 ) )
                                {
                                    sb.append( '\\' ).append(  c  );
                                }
                                else
                                {
                                    sb.append( ' ' );
                                }
    
                                continue;
                            }
                            else if ( c == '#' )
                            {
                                if ( i == 0 )
                                {
                                    sb.append( "\\#" );
                                    continue;
                                }
                                else
                                {
                                    sb.append( '#' );
                                }
                                
                                continue;
                            }
    
                            sb.append( '\\' ).append( c );
                        }
                        else
                        {
                            // Standard ASCII chars are just appended
                            sb.append( c );
                        }
                    }
                }
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                else
                {
                    // The String does not contain any escaped char : 
Solution content
                    {
                        escaped = true;
                        break;
                    }
                }

                // Here, we have a char to escape. Start again the loop...
                if ( escaped )
                {
                    for ( int i = 0; i < valueLength; i++ )
                    {
                        char c = chars[i];
                        
                        if ( ( c < 0) || ( c > 128 ) )
                        {
                            // For chars which are not ASCII, use their hexa value prefixed by an '\'
                            byte[] bb = StringTools.getBytesUtf8( normalizedValue.substring( i, i + 1 ) );
                            
                            for ( byte b:bb )
                            {
                                sb.append( '\\' ).
                                    append( StringTools.dumpHex( (byte)(( b & 0x00F0 ) >> 4) ) ).
                                    append( StringTools.dumpHex( b ) );
                            }
                        }
                        else if ( DN_ESCAPED_CHARS[ c ] ) 
                        {
                            // Some chars need to be escaped even if they are US ASCII
                            // Just prefix them with a '\'
                            // Special cases are ' ' (space), '#') which need a special
                            // treatment.
                            if ( c == ' ' )
                            {
                                if ( ( i == 0 ) || ( i == valueLength - 1 ) )
                                {
                                    sb.append( '\\' ).append(  c  );
                                }
                                else
                                {
                                    sb.append( ' ' );
                                }
    
                                continue;
                            }
                            else if ( c == '#' )
                            {
                                if ( i == 0 )
                                {
                                    sb.append( "\\#" );
                                    continue;
                                }
                                else
                                {
                                    sb.append( '#' );
                                }
                                
                                continue;
                            }
    
                            sb.append( '\\' ).append( c );
                        }
                        else
                        {
                            // Standard ASCII chars are just appended
                            sb.append( c );
                        }
                    }
                }
                else
                {
                    // The String does not contain any escaped char : 
File
AttributeTypeAndValue.java
Developer's decision
Version 1
Kind of conflict
Comment
For statement
If statement
Chunk
Conflicting content
    /**
     * Create a DN when deserializing it.
<<<<<<< HEAD
=======
     * 
     * Note : this constructor is used only by the deserialization method.
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
     * @param upName The user provided name
     * @param normName the normalized name
     * @param bytes the name as a byte[]
Solution content
    /**
     * Create a DN when deserializing it.
     * 
     * Note : this constructor is used only by the deserialization method.
     * @param upName The user provided name
     * @param normName the normalized name
     * @param bytes the name as a byte[]
File
LdapDN.java
Developer's decision
Version 2
Kind of conflict
Comment
Chunk
Conflicting content
        Object upValue = rdn.getUpValue();
        String upType = rdn.getUpType();
        rdn.clear();
<<<<<<< HEAD
        Object normStringValue = DefaultStringNormalizer.normalizeString( (String)upValue );
=======
        Object normStringValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        Object normValue = oidNormalizer.getNormalizer().normalize( normStringValue );

        rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue, normValue );
Solution content
        Object upValue = rdn.getUpValue();
        String upType = rdn.getUpType();
        rdn.clear();
        Object normStringValue = DefaultStringNormalizer.normalizeString( ( String ) upValue );
        Object normValue = oidNormalizer.getNormalizer().normalize( normStringValue );

        rdn.addAttributeTypeAndValue( upType, oidNormalizer.getAttributeTypeOid(), upValue, normValue );
File
LdapDN.java
Developer's decision
Version 1
Kind of conflict
Method invocation
Variable
Chunk
Conflicting content
           default:
               return ((TreeSet)atavs).first().getNormType();
<<<<<<< HEAD
       }
   }

   
   /**
    * Return the normalized value, or the first one of we have more than one (the lowest)
    *
    * @return The first normalized value of this RDN
    */
   public String getNormValue()
   {
       switch ( nbAtavs )
       {
           case 0:
               return null;

           case 1:
               return (String)atav.getNormValue();

           default:
               return ((TreeSet)atavs).first().getNormalizedValue();
=======
>>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
       }
   }
Solution content
               break;

           default:
               return ((TreeSet)atavs).first().getNormType();
       }
   }

   /**
    * Return the value, or the first one of we have more than one (the lowest)
    *
    * @return The first value of this RDN
    */
   public Object getValue()
   {
       switch ( nbAtavs )
       {
           case 0:
               return null;

           case 1:
               return atav.getNormValue();

           default:
               return ((TreeSet)atavs).first().getNormValue();
       }
   }


   /**
    * Return the User Provided value
    * 
    * @return The first User provided value of this RDN
    */
   public Object getUpValue()
   {
       switch ( nbAtavs )
       {
           case 0:
               return null;

           case 1:
               return atav.getUpValue();

           default:
               return ((TreeSet)atavs).first().getUpValue();
       }
   }

      
    /**
     * Return the normalized value, or the first one of we have more than one (the lowest)
     *
     * @return The first normalized value of this RDN
     */
    public String getNormValue()
    {
        switch ( nbAtavs )
        {
            case 0:
                return null;
                
            case 1:
                return (String)atav.getNormValue();
                
            default:
                return ((TreeSet)atavs).first().getNormalizedValue();
        }
    }
   
   
   /**
    * Compares the specified Object with this Rdn for equality. Returns true if
    * the given object is also a Rdn and the two Rdns represent the same
    * attribute type and value mappings. The order of components in
    * multi-valued Rdns is not significant.
    *
    * @param rdn
    *            Rdn to be compared for equality with this Rdn
    * @return true if the specified object is equal to this Rdn
    */
   public boolean equals( Object rdn )
   {
       if ( this == rdn )
       {
           return true;
       }

       if ( !( rdn instanceof Rdn ) )
       {
           return false;
       }

       return compareTo( rdn ) == EQUAL;
   }


   /**
    * Get the number of Attribute type and value of this Rdn
    *
    * @return The number of ATAVs in this Rdn
    */
   public int size()
   {
       return nbAtavs;
   }


   /**
    * Transform the Rdn into an javax.naming.directory.Attributes
    *
    * @return An attributes structure containing all the ATAVs
    */
   public Attributes toAttributes()
   {
       Attributes attributes = new AttributesImpl( true );
       Attribute attribute = null;

       switch ( nbAtavs  )
       {
           case 0 :
               break;

           case 1 :
               attribute = new AttributeImpl( atavType, true );
               attribute.add( atav.getNormValue() );
               attributes.put( attribute );

           default :
               for ( String type:atavTypes.keySet() )
               {
                   List values = ( List ) atavTypes.get( type );

                   attribute = new AttributeImpl( type );

                   for ( AttributeTypeAndValue value:values )
                   {
                       attribute.add( value.getNormValue() );
                   }

                   attributes.put( attribute );
               }

               break;
       }

       return attributes;
   }


   /**
    * Unescape the given string according to RFC 2253 If in  form, a
    * LDAP string representation asserted value can be obtained by replacing
    * (left-to-right, non-recursively) each  appearing in the  as
    * follows: replace  with ; replace  with
    * ; replace  with the octet indicated by the
    *  If in  form, a BER representation can be obtained
    * from converting each  of the  to the octet indicated
    * by the 
    *
    * @param value
    *            The value to be unescaped
    * @return Returns a string value as a String, and a binary value as a byte
    *         array.
    * @throws IllegalArgumentException -
    *             When an Illegal value is provided.
    */
   public static Object unescapeValue( String value )
   {
       if ( StringTools.isEmpty( value ) )
       {
           return "";
       }

       char[] chars = value.toCharArray();

       if ( chars[0] == '#' )
       {
           if ( chars.length == 1 )
           {
               // The value is only containing a #
               return StringTools.EMPTY_BYTES;
           }

           if ( ( chars.length % 2 ) != 1 )
           {
               throw new IllegalArgumentException( "This value is not in hex form, we have an odd number of hex chars" );
           }

           // HexString form
           byte[] hexValue = new byte[( chars.length - 1 ) / 2];
           int pos = 0;

           for ( int i = 1; i < chars.length; i += 2 )
           {
               if ( StringTools.isHex( chars, i ) && StringTools.isHex( chars, i + 1 ) )
               {
                   hexValue[pos++] = StringTools.getHexValue( chars[i], chars[i + 1] );
               }
               else
               {
                   throw new IllegalArgumentException( "This value is not in hex form" );
               }
           }

           return hexValue;
       }
       else
       {
           boolean escaped = false;
           boolean isHex = false;
           byte pair = -1;
           int pos = 0;

           byte[] bytes = new byte[chars.length * 6];

           for ( int i = 0; i < chars.length; i++ )
           {
               if ( escaped )
               {
                   escaped = false;

                   switch ( chars[i] )
                   {
                       case '\\':
                       case '"':
                       case '+':
                       case ',':
                       case ';':
                       case '<':
                       case '>':
                       case '#':
                       case '=':
                       case ' ':
                           bytes[pos++] = ( byte ) chars[i];
                           break;

                       default:
                           if ( StringTools.isHex( chars, i ) )
                           {
                               isHex = true;
                               pair = ( (byte)( StringTools.getHexValue( chars[i] ) << 4 ) );
                           }
                       
                           break;
                   }
               }
               else
               {
                   if ( isHex )
                   {
                       if ( StringTools.isHex( chars, i ) )
                       {
                           pair += StringTools.getHexValue( chars[i] );
                           bytes[pos++] = pair;
                       }
                   }
                   else
                   {
                       switch ( chars[i] )
                       {
                           case '\\':
                               escaped = true;
                               break;

                           // We must not have a special char
                           // Specials are : '"', '+', ',', ';', '<', '>', ' ',
                           // '#' and '='
                           case '"':
                           case '+':
                           case ',':
                           case ';':
                           case '<':
                           case '>':
                           case '#':
                               if ( i != 0)
                               {
                                   // '#' are allowed if not in first position
                                   bytes[pos++] = '#';
                                   break;
                               }
                           case '=':
                               throw new IllegalArgumentException( "Unescaped special characters are not allowed" );

                           case ' ':
                               if ( ( i == 0 ) || ( i == chars.length - 1) )
                               {
                                   throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
                               }
                               else
                               {
                                   bytes[pos++] = ' ';
                                   break;
                               }

                           default:
                               if ( ( chars[i] >= 0 ) && ( chars[i] < 128 ) )
                               {
                                   bytes[pos++] = (byte)chars[i];
                               }
                               else
                               {
                                   byte[] result = StringTools.charToBytes( chars[i] );
                                   System.arraycopy( result, 0, bytes, pos, result.length );
                                   pos += result.length;
                               }
                               
                               break;
                       }
                   }
               }
           }

           return StringTools.utf8ToString( bytes, pos );
       }
   }


   /**
    * Transform a value in a String, accordingly to RFC 2253
    *
    * @param value The attribute value to be escaped
    * @return The escaped string value.
    */
           }
   public static String escapeValue( String value )
   {
       if ( StringTools.isEmpty( value ) )
       {
           return "";
       }
       
       char[] chars = value.toCharArray();
       char[] newChars = new char[chars.length * 3];
       int pos = 0;

       for ( int i = 0; i < chars.length; i++ )
       {
           switch ( chars[i] )
           {
               case ' ':
                   if ( ( i > 0 ) && ( i < chars.length - 1 ) )
                   {
                       newChars[pos++] = chars[i];
                   }
                   else
                   {
                       newChars[pos++] = '\\';
                       newChars[pos++] = chars[i];
                   }
                   
                   break;
                   
               case '#':
                   if ( i != 0 )
                   {
                       newChars[pos++] = chars[i];
                   }
                   else
                   {
                       newChars[pos++] = '\\';
                       newChars[pos++] = chars[i];
                   }
                   
                   break;
                   
               case '"':
               case '+':
               case ',':
               case ';':
               case '=':
               case '<':
               case '>':
               case '\\':
                   newChars[pos++] = '\\';
                   newChars[pos++] = chars[i];
                   break;

               case 0x7F:
                   newChars[pos++] = '\\';
                   newChars[pos++] = '7';
                   newChars[pos++] = 'F';
                   break;

               case 0x00:
               case 0x01:
               case 0x02:
               case 0x03:
               case 0x04:
               case 0x05:
               case 0x06:
               case 0x07:
               case 0x08:
               case 0x09:
               case 0x0A:
               case 0x0B:
               case 0x0C:
               case 0x0D:
               case 0x0E:
               case 0x0F:
                   newChars[pos++] = '\\';
                   newChars[pos++] = '0';
                   newChars[pos++] = StringTools.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
                   break;

               case 0x10:
               case 0x11:
               case 0x12:
               case 0x13:
               case 0x14:
               case 0x15:
               case 0x16:
               case 0x17:
               case 0x18:
               case 0x19:
               case 0x1A:
               case 0x1B:
               case 0x1C:
               case 0x1D:
               case 0x1E:
               case 0x1F:
                   newChars[pos++] = '\\';
                   newChars[pos++] = '1';
                   newChars[pos++] = StringTools.dumpHex( ( byte ) ( chars[i] & 0x0F ) );
                   break;

               default:
                   newChars[pos++] = chars[i];
                   break;

       }

       return new String( newChars, 0, pos );
   }
   
   /**
    * Transform a value in a String, accordingly to RFC 2253
    *
    * @param attrValue
    *            The attribute value to be escaped
    * @return The escaped string value.
    */
   public static String escapeValue( byte[] attrValue )
   {
       if ( StringTools.isEmpty( attrValue ) )
       {
           return "";
       }

       String value = StringTools.utf8ToString( attrValue );
       
       return escapeValue( value );
   }

   /**
     * Gets the hashcode of this rdn.
     *
     * @see java.lang.Object#hashCode()
     * @return the instance's hash code 
     */
   public int hashCode()
   {
       int result = 37;

       switch ( nbAtavs )
       {
           case 0:
               // An empty RDN
               break;

           case 1:
               // We have a single AttributeTypeAndValue
               result = result * 17 + atav.hashCode();
               break;

           default:
               // We have more than one AttributeTypeAndValue

               for ( AttributeTypeAndValue ata:atavs )
               {
                   result = result * 17 + ata.hashCode();
               }
           
               break;
       }

       return result;
   }


   /**
    * @see Externalizable#readExternal(ObjectInput)

* * A RDN is composed of on to many ATAVs (AttributeType And Value). * We should write all those ATAVs sequencially, following the * structure : * *

  • nbAtavs
  • The number of ATAVs to write. Can't be 0. *
  • upName
  • The User provided RDN *
  • normName
  • The normalized RDN. It can be empty if the normalized * name equals the upName. *
  • atavs
  • *

    * For each ATAV :

    *

  • start
  • The position of this ATAV in the upName string *
  • length
  • The ATAV user provided length *
  • Call the ATAV write method
  • The ATAV itself * * @param out The stream into which the serialized RDN will be put * @throws IOException If the stream can't be written */ public void writeExternal( ObjectOutput out ) throws IOException { out.writeInt( nbAtavs ); out.writeUTF( upName ); if ( upName.equals( normName ) ) { out.writeUTF( "" ); } else { out.writeUTF( normName ); } out.writeInt( start ); out.writeInt( length ); switch ( nbAtavs ) { case 0 : break; case 1 : out.writeObject( atav ); break; default : for ( AttributeTypeAndValue value:atavs ) { out.writeObject( value ); } break; } } /** * @see Externalizable#readExternal(ObjectInput) * * We read back the data to create a new RDB. The structure * read is exposed in the {@link Rdn#writeExternal(ObjectOutput)} * method

    * * @param in The input stream from which the RDN will be read * @throws IOException If we can't read from the input stream * @throws ClassNotFoundException If we can't create a new RDN */ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException { // Read the ATAV number nbAtavs = in.readInt(); // Read the UPName upName = in.readUTF(); // Read the normName normName = in.readUTF(); if ( StringTools.isEmpty( normName ) ) { normName = upName; } start = in.readInt(); length = in.readInt(); switch ( nbAtavs ) { case 0 : atav = null; break; case 1 : atav = (AttributeTypeAndValue)in.readObject(); atavType = atav.getNormType(); break; default : atavs = new TreeSet(); atavTypes = new MultiHashMap(); for ( int i = 0; i < nbAtavs; i++ ) { AttributeTypeAndValue value = (AttributeTypeAndValue)in.readObject(); atavs.add( value ); atavTypes.put( value.getNormType(), value ); } atav = null; atavType = null; break; } } }

    File
    Rdn.java
    Developer's decision
    Manual
    Kind of conflict
    Case statement
    Cast expression
    Comment
    Method invocation
    Method signature
    Return statement
    Switch statement
    Chunk
    Conflicting content
                               case '=':
                                   throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
    
    <<<<<<< HEAD
                               default:
                                   byte[] result = StringTools.charToBytes( chars[i] );
                                   System.arraycopy( result, 0, bytes, pos, result.length );
                                   pos += result.length;
    =======
                               case ' ':
                                   if ( ( i == 0 ) || ( i == chars.length - 1) )
                                   {
                                       throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
                                   }
                                   else
                                   {
                                       bytes[pos++] = ' ';
                                       break;
                                   }
    
                               default:
                                   if ( ( chars[i] >= 0 ) && ( chars[i] < 128 ) )
                                   {
                                       bytes[pos++] = (byte)chars[i];
                                   }
                                   else
                                   {
                                       byte[] result = StringTools.charToBytes( chars[i] );
                                       System.arraycopy( result, 0, bytes, pos, result.length );
                                       pos += result.length;
                                   }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                                   
                                   break;
                           }
    Solution content
                               case '=':
                                   throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
    
                               case ' ':
                                   if ( ( i == 0 ) || ( i == chars.length - 1) )
                                   {
                                       throw new IllegalArgumentException( "Unescaped special characters are not allowed" );
                                   }
                                   else
                                   {
                                       bytes[pos++] = ' ';
                                       break;
                                   }
    
                               default:
                                   if ( ( chars[i] >= 0 ) && ( chars[i] < 128 ) )
                                   {
                                       bytes[pos++] = (byte)chars[i];
                                   }
                                   else
                                   {
                                       byte[] result = StringTools.charToBytes( chars[i] );
                                       System.arraycopy( result, 0, bytes, pos, result.length );
                                       pos += result.length;
                                   }
                                   
                                   break;
                           }
    File
    Rdn.java
    Developer's decision
    Version 2
    Kind of conflict
    Attribute
    Case statement
    If statement
    Method invocation
    Variable
    Chunk
    Conflicting content
                    pos.end++;
                    pos.length = length + 2;
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                    return StringTools.utf8ToString( buffer, length );
    <<<<<<< HEAD
                    //return StringTools.utf8ToString( bytes, pos.start, pos.length );
    =======
                }
                else
                {
    Solution content
                    pos.end++;
                    pos.length = length + 2;
                    return StringTools.utf8ToString( buffer, length );
                }
                else
                {
    File
    RdnParser.java
    Developer's decision
    Version 2
    Kind of conflict
    Comment
    Chunk
    Conflicting content
            String upValue = StringTools.utf8ToString( dn, start2, pos.length );
            rdn.addAttributeTypeAndValue( type, type, upValue, value );
    <<<<<<< HEAD
    
    =======
            
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            rdn.normalize();
    
            pos.start = pos.end;
    Solution content
            String upValue = StringTools.utf8ToString( dn, start2, pos.length );
            rdn.addAttributeTypeAndValue( type, type, upValue, value );
            
            rdn.normalize();
    
            pos.start = pos.end;
    File
    RdnParser.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
    import javax.naming.directory.InvalidAttributeIdentifierException;
    import javax.naming.directory.ModificationItem;
    
    <<<<<<< HEAD
    import org.apache.directory.shared.ldap.message.AttributeImpl;
    import org.apache.directory.shared.ldap.message.AttributesImpl;
    import org.apache.directory.shared.ldap.message.ModificationItemImpl;
    =======
    import org.apache.directory.shared.ldap.entry.Entry;
    import org.apache.directory.shared.ldap.entry.EntryAttribute;
    import org.apache.directory.shared.ldap.entry.Modification;
    import org.apache.directory.shared.ldap.entry.Value;
    import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
    import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
    import org.apache.directory.shared.ldap.message.AttributeImpl;
    import org.apache.directory.shared.ldap.message.AttributesImpl;
    import org.apache.directory.shared.ldap.message.ModificationItemImpl;
    import org.apache.directory.shared.ldap.name.LdapDN;
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    import org.apache.directory.shared.ldap.schema.AttributeType;
    import org.apache.directory.shared.ldap.schema.MatchingRule;
    import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
    Solution content
    import javax.naming.directory.InvalidAttributeIdentifierException;
    import javax.naming.directory.ModificationItem;
    
    import org.apache.directory.shared.ldap.entry.Entry;
    import org.apache.directory.shared.ldap.entry.EntryAttribute;
    import org.apache.directory.shared.ldap.entry.Modification;
    import org.apache.directory.shared.ldap.entry.Value;
    import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
    import org.apache.directory.shared.ldap.entry.client.DefaultClientEntry;
    import org.apache.directory.shared.ldap.message.AttributeImpl;
    import org.apache.directory.shared.ldap.message.AttributesImpl;
    import org.apache.directory.shared.ldap.message.ModificationItemImpl;
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.schema.AttributeType;
    import org.apache.directory.shared.ldap.schema.MatchingRule;
    import org.apache.directory.shared.ldap.schema.NoOpNormalizer;
    File
    AttributeUtils.java
    Developer's decision
    Version 2
    Kind of conflict
    Import
    Chunk
    Conflicting content
                false, false, false, false, false, false, false, false  // 78 -> 7F
            };
    
    <<<<<<< HEAD
    =======
    
        /**
         * [0x01-0x1F] | 0x21 | [0x24-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
         */
        private static final boolean[] LUTF1 =
            { 
                false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
                true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
                true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
                true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
                false, true,  false, false, true,  true,  true,  true, // 20 -> 27 ( ' ', '"', '#' )
                true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
                true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
                true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
                true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
                true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
                true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
                true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
                true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
                true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
                true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
                true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
            };
    
    
        /**
         * [0x01-0x21] | [0x23-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
         */
        private static final boolean[] SUTF1 =
            { 
                false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
                true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
                true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
                true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
                true,  true,  false, true,  true,  true,  true,  true, // 20 -> 27 ( '"' )
                true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
                true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
                true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
                true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
                true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
                true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
                true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
                true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
                true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
                true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
                true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
            };
    
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        /**
         * ' ' | '"' | '#' | '+' | ',' | ';' | '<' | '=' | '>' | '\' |
         * 0x22 | 0x23 | 0x2B | 0x2C | 0x3B | 0x3C | 0x3D | 0x3E | 0x5C
    Solution content
                false, false, false, false, false, false, false, false  // 78 -> 7F
            };
    
    
        /**
         * [0x01-0x1F] | 0x21 | [0x24-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
         */
        private static final boolean[] LUTF1 =
            { 
                false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
                true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
                true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
                true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
                false, true,  false, false, true,  true,  true,  true, // 20 -> 27 ( ' ', '"', '#' )
                true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
                true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
                true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
                true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
                true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
                true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
                true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
                true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
                true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
                true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
                true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
            };
    
    
        /**
         * [0x01-0x21] | [0x23-0x2A] | [0x2D-0x3A] | 0x3D | [0x3F-0x5B] | [0x5D-0x7F]
         */
        private static final boolean[] SUTF1 =
            { 
                false, true,  true,  true,  true,  true,  true,  true, // 00 -> 07 '\0'
                true,  true,  true,  true,  true,  true,  true,  true, // 08 -> 0F
                true,  true,  true,  true,  true,  true,  true,  true, // 10 -> 17
                true,  true,  true,  true,  true,  true,  true,  true, // 18 -> 1F
                true,  true,  false, true,  true,  true,  true,  true, // 20 -> 27 ( '"' )
                true,  true,  true,  false, false, true,  true,  true, // 28 -> 2F ( '+', ',' )
                true,  true,  true,  true,  true,  true,  true,  true, // 30 -> 37 
                true,  true,  true,  false, false, true,  false, true, // 38 -> 3F ( ';', '<', '>' ) 
                true,  true,  true,  true,  true,  true,  true,  true, // 40 -> 47 
                true,  true,  true,  true,  true,  true,  true,  true, // 48 -> 4F
                true,  true,  true,  true,  true,  true,  true,  true, // 50 -> 57
                true,  true,  true,  true,  false, true,  true,  true, // 58 -> 5F ( '\' )
                true,  true,  true,  true,  true,  true,  true,  true, // 60 -> 67 
                true,  true,  true,  true,  true,  true,  true,  true, // 68 -> 6F
                true,  true,  true,  true,  true,  true,  true,  true, // 70 -> 77
                true,  true,  true,  true,  true,  true,  true,  true  // 78 -> 7F
            };
    
    
        /**
         * ' ' | '"' | '#' | '+' | ',' | ';' | '<' | '=' | '>' | '\' |
         * 0x22 | 0x23 | 0x2B | 0x2C | 0x3B | 0x3C | 0x3D | 0x3E | 0x5C
    File
    DNUtils.java
    Developer's decision
    Version 2
    Kind of conflict
    Array initializer
    Attribute
    Comment
    Chunk
    Conflicting content
        
        /**
    <<<<<<< HEAD
    =======
         * Check if the current character is a SUTF1 (Stringchar UTF ascii char)
    * <LUTF1> ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F * * @param bytes The buffer containing the data * @param index Current position in the buffer * @return true if the current character is a SUTF1 */ public static boolean isSUTF1( byte[] bytes, int index ) { if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) { return false; } byte c = bytes[index]; return ( ( ( c | 0x7F ) == 0x7F ) && SUTF1[c & 0x7f] ); } /** >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903 * Check if the given char is a pair char only * <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' *
    Solution content
        
        /**
         * Check if the current character is a SUTF1 (Stringchar UTF ascii char)
    * <LUTF1> ::= 0x01-20 | 0x23-2A | 0x2D-3A | 0x3D | 0x3F-5B | 0x5D-7F * * @param bytes The buffer containing the data * @param index Current position in the buffer * @return true if the current character is a SUTF1 */ public static boolean isSUTF1( byte[] bytes, int index ) { if ( ( bytes == null ) || ( bytes.length == 0 ) || ( index < 0 ) || ( index >= bytes.length ) ) { return false; } byte c = bytes[index]; return ( ( ( c | 0x7F ) == 0x7F ) && SUTF1[c & 0x7f] ); } /** * Check if the given char is a pair char only * <pairCharOnly> ::= ' ' | ',' | '=' | '+' | '<' | '>' | '#' | ';' | '\' | '"' *
    File
    DNUtils.java
    Developer's decision
    Version 2
    Kind of conflict
    Comment
    Method declaration
    Chunk
    Conflicting content
            throw new NotImplementedException();
        }
    <<<<<<< HEAD
    
    
        /**
         * Creates, fills and returns an Attributes instance using the LDIF encoded
         * within the property value. The LDIF should use '*' (asterisk) characters
         * as line delimiters within the property value. These are replaced with
         * newlines and fed to the LDIF parser. Also note that the LdifParser
         * deposites the DN as a property within the attributes object.
         * 
         * @param props
         *            the properties to get the ldif property from
         * @param key
         *            the key for the LDIF property
         * @return the attributes for the encoded LDIF entry
         */
        public static Attributes fillAttributes( Properties props, String key, Attributes values ) throws NamingException
        {
            if ( props == null || !props.containsKey( key ) || props.getProperty( key ) == null )
            {
                if ( values == null )
                {
                    return new AttributesImpl();
                }
    
                return values;
            }
    
            String ldif = props.getProperty( key ).trim().replace( '*', '\n' );
            
            LdifReader ldifReader = new LdifReader( new StringReader( ldif ) );
            
            LdifEntry entry = ldifReader.next();
            
            if ( entry != null )
            {
                values = entry.getAttributes();
            }
            return values;
        }
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    }
    Solution content
            throw new NotImplementedException();
        }
    }
    File
    PropertiesUtils.java
    Developer's decision
    Version 2
    Kind of conflict
    Comment
    Method declaration
    Chunk
    Conflicting content
                        continue;
                    }
                }
    <<<<<<< HEAD
    
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
                
                if ( escaped )
                {
    Solution content
                        continue;
                    }
                }
                
                if ( escaped )
                {
    File
    StringTools.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
                {
                    buf.append( str.charAt( ii ) );
                }
    <<<<<<< HEAD
            }
    
            if ( escaped )
            {
                // We should not have a '\' at the end of the string
                throw new InvalidNameException( "The DN must not ends with a '\\'." );
            }
    =======
            }
            
            if ( escaped )
            {
                // We should not have a '\' at the end of the string
                throw new InvalidNameException( "The DN must not ends with a '\\'." );
            }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            return buf.toString();
        }
    Solution content
                {
                    buf.append( str.charAt( ii ) );
                }
            }
            
            if ( escaped )
            {
                // We should not have a '\' at the end of the string
                throw new InvalidNameException( "The DN must not ends with a '\\'." );
            }
    
            return buf.toString();
        }
    File
    StringTools.java
    Developer's decision
    Version 1
    Kind of conflict
    If statement
    Chunk
    Conflicting content
    import org.apache.directory.shared.ldap.codec.util.LdapURL;
    import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
    import org.apache.directory.shared.ldap.name.LdapDN;
    <<<<<<< HEAD
    =======
    import org.junit.Test;
    import org.junit.Ignore;
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
    
    /**
    Solution content
    import org.apache.directory.shared.ldap.codec.util.LdapURL;
    import org.apache.directory.shared.ldap.codec.util.LdapURLEncodingException;
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.junit.Test;
    import org.junit.Ignore;
    
    
    /**
    File
    LdapUrlTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Import
    Chunk
    Conflicting content
            Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
        }
    
    <<<<<<< HEAD
    =======
        
        /**
         * test a LdapURL without a scheme
         *
         */
        @Test
        public void testLdapURLNoScheme()
        {
            try
            {
                new LdapURL( "/ou=system" );
                fail();
            }
            catch ( LdapURLEncodingException luee )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * test a LdapURL without a host but with a DN
         *
         */
        @Test
        public void testLdapURLNoHostDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap:///ou=system" );
                
                assertEquals( "ldap:///ou=system", url.toString() );
                
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a host, no port, and a DN
         *
         */
        @Test
        public void testLdapURLHostNoPortDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost/ou=system" );
                
                assertEquals( "ldap://localhost/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
        
        /**
         * test a LdapURL with no host, a port, and a DN
         *
         */
        @Test
        public void testLdapURLNoHostPortDN()
        {
            try
            {
                new LdapURL( "ldap://:123/ou=system" );
                
                fail();
            }
            catch ( LdapURLEncodingException luee )
            {
                assertTrue( true );
            }
        }
    
        
        /**
            {
    
        /**
         * test a LdapURL with no DN
         *
         */
        @Test
        public void testLdapURLNoDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN and no attributes 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrs()
        {
            try
                LdapURL url = new LdapURL( "ldap://localhost:123/?" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes and no scope 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope and no filter 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
        
        
        /**
         * test a LdapURL with no DN and attributes
         *
         */
        @Test
        public void testLdapURLDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system" );
                
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
        
        /**
         * test a LdapURL with a DN and attributes
         *
         */
        @Test
        public void testLdapURLDNAttrs()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,dc,cn" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,dc,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
         * test a LdapURL with no DN and attributes
         *
         */
        @Test
        public void testLdapURLNoDNAttrs()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,dc,cn" );
                
                assertEquals( "ldap://localhost:123/?ou,dc,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an scope
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub" );
                
                assertEquals( "ldap://localhost:123/??sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an scope base
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an default scope
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes an scope
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes an scope base
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base" );
                
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
            {
    
    
        /**
         * test a LdapURL with a DN, no attributes an default scope
         *
         */
        @Test
        public void testLdapURLDNNoAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??" );
                
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an scope
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?sub" );
                
                assertEquals( "ldap://localhost:123/?ou,cn?sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an scope base
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?base" );
                
                assertEquals( "ldap://localhost:123/?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an default scope
         *
         */
        @Test
        public void testLdapURLNoDNAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?" );
                
                assertEquals( "ldap://localhost:123/?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an scope
         *
         */
        @Test
        public void testLdapURLDNAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?sub" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn?sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an scope base
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?base" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an default scope
         *
         */
        @Test
        public void testLdapURLDNAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???(cn=test)" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system???(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc??(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/??sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc?sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc?sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc?base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,dc,ou??(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,dc,ou??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope and filter
         *
        public void testLdapURLDNAttrsScopeBaseFilter()
        {
                fail();
            try
            {
         */
        @Test
        public void testLdapURLDNAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, and filter
         *
         */
        @Test
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, no filter and no extension 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilterNoExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/????" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/????!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/??sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/??sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou???!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeNoFilterExtension()
        {
            try
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou?sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou?sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system????!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    }
    Solution content
            Assert.assertEquals( "ldap:///dc=example,dc=com", url.toString() );
        }
    
        
        /**
         * test a LdapURL without a scheme
         *
         */
        @Test
        public void testLdapURLNoScheme()
        {
            try
            {
                new LdapURL( "/ou=system" );
                fail();
            }
            catch ( LdapURLEncodingException luee )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * test a LdapURL without a host but with a DN
         *
         */
        @Test
        public void testLdapURLNoHostDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap:///ou=system" );
                
                assertEquals( "ldap:///ou=system", url.toString() );
                
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a host, no port, and a DN
         *
         */
        @Test
        public void testLdapURLHostNoPortDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost/ou=system" );
                
                assertEquals( "ldap://localhost/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
            }
                
            {
                fail();
            }
        }
    
        
        /**
         * test a LdapURL with no host, a port, and a DN
         *
         */
        @Test
        public void testLdapURLNoHostPortDN()
        {
            try
            {
                new LdapURL( "ldap://:123/ou=system" );
                
                fail();
            }
            }
            catch ( LdapURLEncodingException luee )
            {
                assertTrue( true );
            }
        }
    
        
        /**
         * test a LdapURL with no DN
         *
         */
        @Test
        public void testLdapURLNoDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN and no attributes 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrs()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes and no scope 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope and no filter 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
        
        
        /**
         * test a LdapURL with no DN and attributes
         *
         */
        @Test
        public void testLdapURLDN()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system" );
                
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
        
        /**
         * test a LdapURL with a DN and attributes
         *
         */
        @Test
        public void testLdapURLDNAttrs()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,dc,cn" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,dc,cn", url.toString() );
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN and attributes
         *
         */
        @Test
        public void testLdapURLNoDNAttrs()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,dc,cn" );
                
                assertEquals( "ldap://localhost:123/?ou,dc,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an scope
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub" );
                
                assertEquals( "ldap://localhost:123/??sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an scope base
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes an default scope
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes an scope
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub", url.toString() );
            }
        {
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes an scope base
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base" );
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes an default scope
         *
         */
        @Test
        public void testLdapURLDNNoAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??" );
                
                assertEquals( "ldap://localhost:123/ou=system", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an scope
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?sub" );
                
                assertEquals( "ldap://localhost:123/?ou,cn?sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an scope base
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBase()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?base" );
                
                assertEquals( "ldap://localhost:123/?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes an default scope
         *
         */
        @Test
        public void testLdapURLNoDNAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?ou,cn?" );
                
                assertEquals( "ldap://localhost:123/?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an scope
         *
         */
        @Test
        public void testLdapURLDNAttrsScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?sub" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn?sub", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an scope base
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBase()
        {
            try
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?base" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes an default scope
         *
         */
        @Test
        public void testLdapURLDNAttrsDefaultScope()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?ou,cn?" );
                
                assertEquals( "ldap://localhost:123/ou=system?ou,cn", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???(cn=test)" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system???(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc??(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope and filter
         *
         */
        @Test
            try
        public void testLdapURLNoDNNoAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/??sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
            {
         * test a LdapURL with no DN, no attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc?sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc?sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,ou,dc?base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, no scope and filter
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,dc,ou??(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,dc,ou??(cn=test)", url.toString() );
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope and filter
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, and filter
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBaseFilter()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base?(cn=test)" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, no filter and no extension 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilterNoExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/????" );
                
                assertEquals( "ldap://localhost:123/", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/????!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/???(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeNoFilterExtension()
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/??sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/??sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, no attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNNoAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/??base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou???!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
    
         * test a LdapURL with no DN, some attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
    
        /**
         * test a LdapURL with no DN, some attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou?sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou?sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with no DN, some attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLNoDNAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/?cn,dc,ou?base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/?cn,dc,ou??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system????!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsNoScopeFilterExtension()
        {
            try
            {
        }
    
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system????!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system??sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, no attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNNoAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system??base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system???(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, no scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
    
        /**
         * test a LdapURL with a DN, some attributes, no scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsNoScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub??!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, no filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBaseNoFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base??!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc???!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc?sub?(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    
    
        /**
         * test a LdapURL with a DN, some attributes, a base scope, a filter and some extensions 
         *
         */
        @Test
        public void testLdapURLDNAttrsScopeBaseFilterExtension()
        {
            try
            {
                LdapURL url = new LdapURL( "ldap://localhost:123/ou=system?cn,ou,dc?base?(cn=test)?!a=b,!c" );
                
                assertEquals( "ldap://localhost:123/ou=system?cn,ou,dc??(cn=test)?!a=b,!c", url.toString() );
            }
            catch ( LdapURLEncodingException luee )
            {
                fail();
            }
        }
    }
    File
    LdapUrlTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
            assertTrue( node instanceof EqualityNode );
        }
    
    <<<<<<< HEAD
    
    =======
        
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        /**
         * test a filter with a # in value
         */
    Solution content
            assertTrue( node instanceof EqualityNode );
        }
    
        
        /**
         * test a filter with a # in value
         */
    File
    FilterParserTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
        @Test
        public void testEqualsFilterWithPoundInValue() throws ParseException
        {
    <<<<<<< HEAD
            SimpleNode node = ( SimpleNode ) FilterParser.parse( "(uid=#f1)" );
    =======
            SimpleNode node = ( SimpleNode ) FilterParser.parse( "(uid=#f1)" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            assertEquals( "uid", node.getAttribute() );
            assertEquals( "#f1", node.getValue().get() );
            assertTrue( node instanceof EqualityNode );
    Solution content
        @Test
        public void testEqualsFilterWithPoundInValue() throws ParseException
        {
            SimpleNode node = ( SimpleNode ) FilterParser.parse( "(uid=#f1)" );
            assertEquals( "uid", node.getAttribute() );
            assertEquals( "#f1", node.getValue().get() );
            assertTrue( node instanceof EqualityNode );
    File
    FilterParserTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Cast expression
    Variable
    Chunk
    Conflicting content
            assertTrue( node instanceof EqualityNode );
        }
    
    <<<<<<< HEAD
    
    =======
        
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        /**
         * Test that special and non allowed chars into an assertionValue are not
         * accepted. ((cf DIRSERVER-1196)
    Solution content
            assertTrue( node instanceof EqualityNode );
        }
    
        
        /**
         * Test that special and non allowed chars into an assertionValue are not
         * accepted. ((cf DIRSERVER-1196)
    File
    FilterParserTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
            AttributesImpl attrs = new AttributesImpl( "objectClass", "person", true );
            attrs.get( "objectClass" ).add( "uidObject" );
    <<<<<<< HEAD
            
    =======
                    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            AttributeImpl attr = new AttributeImpl( "cn" );
            
            attr.add( "john doe" );
    Solution content
            AttributesImpl attrs = new AttributesImpl( "objectClass", "person", true );
            attrs.get( "objectClass" ).add( "uidObject" );
                    
            AttributeImpl attr = new AttributeImpl( "cn" );
            
            attr.add( "john doe" );
    File
    LdifUtilsTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
            attr.add( "jack doe" );
            
            attrs.put( attr );
    <<<<<<< HEAD
    =======
            
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            attrs.put( "sn", "doe" );
            attrs.put( "uid", "jdoe" );
    
    Solution content
            attr.add( "jack doe" );
            
            attrs.put( attr );
            
            attrs.put( "sn", "doe" );
            attrs.put( "uid", "jdoe" );
    
    File
    LdifUtilsTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
    <<<<<<< HEAD
    
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
    Solution content
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Blank
    Chunk
    Conflicting content
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    <<<<<<< HEAD
    
    =======
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
    Solution content
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
    <<<<<<< HEAD
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
    =======
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    Solution content
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    
    
        /**
    <<<<<<< HEAD
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    =======
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
    Solution content
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a=b", dn.toString() );
        }
    
    <<<<<<< HEAD
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    =======
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
    Solution content
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    <<<<<<< HEAD
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    =======
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
    Solution content
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    <<<<<<< HEAD
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    =======
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
    Solution content
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    <<<<<<< HEAD
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    =======
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
    Solution content
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    <<<<<<< HEAD
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
    =======
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
    =======
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
    =======
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    =======
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
    Solution content
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
    File
    LdapDNTest.java
    Developer's decision
    Combination
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
    <<<<<<< HEAD
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
    =======
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    =======
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
    Solution content
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
        {
    
        /**
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
         */
        }
    
    
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
        @Test
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
        @Test
        @Test
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
    
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            {
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
    
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
        }
        /**
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
        }
    
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    =======
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
    Solution content
    
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
         */
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
    
         * @throws Exception
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
    
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
                }
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            }
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
    
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
        {
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
            return out;
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
    =======
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    =======
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * Normalize a simple DN with a # on first position
    Solution content
         *
    
        /**
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
    
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *             anything goes wrong
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
            }
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
    
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
    
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
    
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
                {
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
    
            assertTrue( ( ( LdapDN ) result )
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        {
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            }
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
    <<<<<<< HEAD
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            }
            LdapDN ndn = dn.normalize( oidOids );
    =======
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
    Solution content
            {
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testNameEqualsIsInsensitiveToAttributesOrder() throws Exception
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
    
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
        @Test
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        {
    
            Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
            Name name2 = new LdapDN( "cn=WorkDir+cn=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
                {
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
                }
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
    
        /**
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
    
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
        }
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
                .equals(
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
         * Test for DIRSERVER-191
         */
         * Test for DIRSERVER-191
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
        /**
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        {
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Variable
    Chunk
    Conflicting content
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    =======
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
    Solution content
         */
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
    
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
         */
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
        @Test
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * 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 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
        @Test
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
            }
    
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
    
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( "dc = eXample" );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
    
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
    
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
        /**
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
    
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
            try
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
    <<<<<<< HEAD
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    =======
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a simple DN with a comma at the end
    Solution content
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
        @Test
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        {
    
        /**
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
        }
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
         *
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
         * @throws Exception
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
        /**
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
            assertSame( jName, jName.add( "cn=five" ) );
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
    
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Chunk
    Conflicting content
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
    <<<<<<< HEAD
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    =======
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        // REMOVE operation -------------------------------------------------------
    
    Solution content
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Try statement
    Chunk
    Conflicting content
        // REMOVE operation -------------------------------------------------------
    
        /**
    <<<<<<< HEAD
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    =======
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a remove from position 2
    Solution content
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
        @Test
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
        /**
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
         * @throws InvalidNameException
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
         */
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
         */
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        // STARTS WITH operations
        @Test
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         */
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
    
    
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
            Name name = new LdapDN();
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
    
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
                }
                try
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
    
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
    <<<<<<< HEAD
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    =======
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a remove from position 1 whith semi colon
    Solution content
        @Test
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
        {
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        /**
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
        @Test
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
            {
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
        }
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
    
    
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
    
    
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
    <<<<<<< HEAD
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    =======
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a remove out of bound
    Solution content
            {
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
         */
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
         * Get the suffix of an empty LdapName
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
         */
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
    
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        @Test
            // 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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
        public void testIsEmpty() throws Exception
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
                }
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
            assertTrue( name0.startsWith( name1 ) );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
    <<<<<<< HEAD
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    =======
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            try
            {
    Solution content
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Try statement
    Variable
    Chunk
    Conflicting content
            }
        }
    
    <<<<<<< HEAD
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    =======
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test a 3 size
    Solution content
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
         */
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
    
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
        }
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
                    oids );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
    
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
    
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
    <<<<<<< HEAD
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    =======
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
    Solution content
        {
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
                fail();
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
         */
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
        @Test
         */
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
        /**
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
            assertEquals( true, nc.hasMoreElements() );
    
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
            {
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        /**
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
            list.add( "dc=example" );
            list.add( "dc=com" );
        }
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
        {
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
    
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            assertEquals( "", name.getSuffix( 4 ).toString() );
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
    
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
    
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
    
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
                try
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
        /**
         * Test for DIRSERVER-191
                {
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        */
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
    
    
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            finally
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
            {
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( 1, dn.size() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    =======
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        /**
         * test size after operations
    Solution content
    
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
        }
    
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        }
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
        }
    
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
        {
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
        /**
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
         * Get the suffix out of bound
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        {
         * Test a startsWith a complex LdapDN
         */
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testJNDITutorialExample() throws Exception
        {
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
        @Test
         */
            // 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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
            assertEquals( 3, name3.size() );
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
        @Test
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            name.add( 2, "cn=John" );
    
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
                if ( i == 4 )
                {
         */
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
        @Test
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            String cn = new String( new byte[]
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
        /**
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
    
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
         * Test for DIRSERVER-191
         */
        @Test
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
        {
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            try
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
            assertTrue( LdapDN.isValid( "a=" ) );
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
                }
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
    <<<<<<< HEAD
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    =======
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
    Solution content
    import java.io.ByteArrayInputStream;
        }
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
        @Test
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
    
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
    
        /**
         * test a 1 size
         */
            dn.add( "e = f" );
        /**
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
        /**
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
    
         * Get the suffix of an empty LdapName
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
    
    
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
        @Test
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
            {
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testNameEqualsIsInsensitiveToAttributesOrder() throws Exception
        {
    
                }
        public void testNameComparisonIsInsensitiveToAttributesOrder() throws Exception
        {
    
                public int compare( Name obj1, Name obj2 )
                {
            Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
            Name name2 = new LdapDN( "cn=WorkDir+cn=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
            Name name1 = new LdapDN( "cn=HomeDir+cn=WorkDir" );
            Name name2 = new LdapDN( "cn=WorkDir+cn=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
        public void testGet() throws Exception
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
        /**
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
         * Class to test for Name addAll(Name)
         *
        @Test
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
            try
        @Test
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
        public void testDIRSERVER_184_2()
        {
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
        }
    
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
            
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( 0, dn.size() );
        }
    
    <<<<<<< HEAD
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    =======
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
    Solution content
         */
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
        @Test
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
         */
        @Test
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * azerty
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
            dn.remove( 0 );
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
    
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
        }
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
    
    
        /**
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
         * @throws InvalidNameException
            LdapDN dn2 = new LdapDN( "e = f" );
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            dn.remove( 0 );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
         * Test a startsWith an simple LdapDN
         */
        @Test
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
            LdapDN clone = ( LdapDN ) dn.clone();
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
            // Remove the second component from the head: ou=People
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testJNDITutorialExample() throws Exception
        {
            // Parse the name
            Name name = new LdapDN( "cn=John,ou=People,ou=Marketing" );
    
            String out = name.remove( 1 ).toString();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            Enumeration enum4 = name4.getAll();
    
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
        public void testAddAllNameExisting0() throws Exception
        {
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
         * Class to test for Name addAll(int, Name)
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
         */
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
        public void testGetPrefixName() throws NamingException
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
    
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
    
    
        /**
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
         * Test for DIRSERVER-184
         * @throws NamingException
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( 1, dn.size() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
    =======
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            assertEquals( 3, dn.size() );
        }
    
    Solution content
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
    
        // ~ Methods
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
    
            LdapDN dn = new LdapDN( "a = b" );
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
    
        // ADD Operations
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
        /**
         * Get the prefix at pos 1
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
        @Test
    
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
    
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
    
    
        /**
         * Test a startsWith a complex LdapDN
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
        }
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
            Name name1 = new LdapDN( "cn=HomeDir" );
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
                {
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
                {
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
         */
        @Test
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
                if ( i == 3 )
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
         *
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
        }
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
    
                "cn=seven,cn=six,cn=five" ) ) );
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
            Name name1 = LdapDN
                .normalize(
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
    
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
        /**
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
         * @throws NamingException
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
            finally
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
    
            {
                DnSerializer.serialize( dn, out );
                
                try
                {
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
            }
            
            long t3 = System.currentTimeMillis();
    
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    =======
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
        /**
         * test Add at the start of an existing LdapDN
    Solution content
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
            oids = new HashMap();
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        }
    
    
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
         */
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            // Check the normalization now
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
        @Test
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
            {
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
    
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
        /**
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
        /**
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
                fail();
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
            }
            catch ( IndexOutOfBoundsException aioob )
                    return super.hashCode();
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
         */
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
            assertEquals( true, enum6.hasMoreElements() );
    
    
    
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
        {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
    
                if ( i == 5 )
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        @Test
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
    
    
         *             when anything goes wrong
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
        @Test
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
    
        /**
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
        {
            try
            {
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         */
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
    
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
    <<<<<<< HEAD
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    =======
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
    Solution content
        /**
    
        /**
    
            oids.put( "domaincomponent", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
        /**
    /*
     *  Licensed to the Apache Software Foundation (ASF) under one
     *  or more contributor license agreements.  See the NOTICE file
     *  distributed with this work for additional information
        }
     *  regarding copyright ownership.  The ASF licenses this file
     *  to you 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.directory.shared.ldap.name;
    
    
    import java.io.ByteArrayInputStream;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.ObjectInputStream;
    import java.io.ObjectOutputStream;
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.Enumeration;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;
    import java.util.Properties;
    
    import javax.naming.CompoundName;
    import javax.naming.InvalidNameException;
    import javax.naming.Name;
    import javax.naming.NamingException;
    import javax.naming.ldap.LdapName;
    
    import org.apache.directory.shared.ldap.name.LdapDN;
    import org.apache.directory.shared.ldap.name.LdapDnParser;
    import org.apache.directory.shared.ldap.name.Rdn;
    import org.apache.directory.shared.ldap.schema.DeepTrimToLowerNormalizer;
    import org.apache.directory.shared.ldap.schema.OidNormalizer;
    import org.apache.directory.shared.ldap.util.StringTools;
    import org.junit.Before;
    import org.junit.Test;
    
    import static org.junit.Assert.assertTrue;
    import static org.junit.Assert.assertEquals;
    import static org.junit.Assert.assertFalse;
    import static org.junit.Assert.fail;
    import static org.junit.Assert.assertSame;
    
    
    /**
     * Test the class LdapDN
     *
     * @author Apache Directory Project
     * @version $Rev$, $Date$, 
     */
    public class LdapDNTest
    {
        private Map oids;
        private Map oidOids;
    
    
        /**
         * Initialize OIDs maps for normalization
         */
        @Before
        public void initMapOids()
        {
            oids = new HashMap();
    
            oids.put( "dc", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
        }
    
    
    
    
        /**
            // Check the normalization now
            oids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "dc", new DeepTrimToLowerNormalizer() ) );
    
            oids.put( "ou", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "organizationalUnitName", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
            oids.put( "2.5.4.11", new OidNormalizer( "ou", new DeepTrimToLowerNormalizer() ) );
    
            // Another map where we store OIDs instead of names.
            oidOids = new HashMap();
    
            oidOids.put( "dc", new OidNormalizer( "0.9.2342.19200300.100.1.25", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "domaincomponent", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "0.9.2342.19200300.100.1.25", new OidNormalizer( "0.9.2342.19200300.100.1.25",
                new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "ou", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "organizationalUnitName", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
            oidOids.put( "2.5.4.11", new OidNormalizer( "2.5.4.11", new DeepTrimToLowerNormalizer() ) );
        // ~ Methods
        // ------------------------------------------------------------------------------------
        // CONSTRUCTOR functions --------------------------------------------------
    
        /**
         * Test a null DN
         */
        @Test
        public void testLdapDNNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test an empty DN
         */
        @Test
        public void testLdapDNEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.getUpName() );
            assertTrue( dn.isEmpty() );
        }
    
    
        /**
         * test a simple DN : a = b
         */
        @Test
        public void testLdapDNSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
    
            assertTrue( LdapDN.isValid( "a = b" ) );
            assertEquals( "a = b", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a simple DN with some spaces : "a = b  "
         */
        @Test
        public void testLdapDNSimpleWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  " );
    
            assertTrue( LdapDN.isValid( "a = b  " ) );
            assertEquals( "a = b  ", dn.getUpName() );
            assertEquals( "a=b", dn.toString() );
        }
    
    
        /**
         * test a composite DN : a = b, d = e
         */
        @Test
        public void testLdapDNComposite() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
    
            assertTrue( LdapDN.isValid( "a = b, c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b, c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with spaces : a = b  , d = e
         */
        @Test
        public void testLdapDNCompositeWithSpaces() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b  , c = d" );
    
            assertTrue( LdapDN.isValid( "a = b  , c = d" ) );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a = b  , c = d", dn.getUpName() );
            assertEquals( "a=b;c=d,e=f", dn.getUpName() );
    
         * test a composite DN with or without spaces: a=b, a =b, a= b, a = b, a = b
         */
        @Test
        public void testLdapDNCompositeWithSpace() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, a =b, a= b, a = b, a  =  b" );
    
            assertTrue( LdapDN.isValid( "a=b, a =b, a= b, a = b, a  =  b" ) );
            assertEquals( "a=b,a=b,a=b,a=b,a=b", dn.toString() );
            assertEquals( "a=b, a =b, a= b, a = b, a  =  b", dn.getUpName() );
        }
    
    
        /**
         * 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 ',')
         */
        @Test
        public void testLdapDNCompositeSepators() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b;c=d,e=f" );
    
            assertTrue( LdapDN.isValid( "a=b;c=d,e=f" ) );
            assertEquals( "a=b,c=d,e=f", dn.toString() );
        }
    
    
        /**
         * test a simple DN with multiple NameComponents : a = b + c = d
         */
        @Test
        public void testLdapDNSimpleMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c = d" );
    
            assertTrue( LdapDN.isValid( "a = b + c = d" ) );
            assertEquals( "a=b+c=d", dn.toString() );
            assertEquals( "a = b + c = d", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with multiple NC and separators : a=b+c=d, e=f + g=h +
         * i=j
         */
        @Test
        public void testLdapDNCompositeMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, e=f + g=h + i=j" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, e=f + g=h + i=j" ) );
            assertEquals( "a=b+c=d,e=f+g=h+i=j", dn.toString() );
            assertEquals( "a=b+c=d, e=f + g=h + i=j", dn.getUpName() );
        }
    
    
        /**
        * Test to see if a DN with multiRdn values is preserved after an addAll.
        */
        @Test
        public void testAddAllWithMultivaluedAttribute() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "cn=Kate Bush+sn=Bush,ou=system" );
            LdapDN target = new LdapDN();
    
            assertTrue( LdapDN.isValid( "cn=Kate Bush+sn=Bush,ou=system" ) );
            target.addAll( target.size(), dn );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.toString() );
            assertEquals( "cn=Kate Bush+sn=Bush,ou=system", target.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (uppercase) : OID.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidUpper() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "OID.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "OID.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "OID.12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with an oid prefix (lowercase) : oid.12.34.56 = azerty
         */
        @Test
        public void testLdapDNOidLower() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "oid.12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "oid.12.34.56 = azerty" ) );
            assertEquals( "oid.12.34.56=azerty", dn.toString() );
            assertEquals( "oid.12.34.56 = azerty", dn.getUpName() );
        }
    
    
         * test a simple DN with an oid attribut without oid prefix : 12.34.56 =
         * azerty
         */
        @Test
        public void testLdapDNOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty" ) );
            assertEquals( "12.34.56=azerty", dn.toString() );
            assertEquals( "12.34.56 = azerty", dn.getUpName() );
        }
    
    
        /**
         * test a composite DN with an oid attribut wiithout oid prefix : 12.34.56 =
         * azerty; 7.8 = test
         */
        @Test
        public void testLdapDNCompositeOidWithoutPrefix() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "12.34.56 = azerty; 7.8 = test" );
    
            assertTrue( LdapDN.isValid( "12.34.56 = azerty; 7.8 = test" ) );
            assertEquals( "12.34.56=azerty,7.8=test", dn.toString() );
            assertEquals( "12.34.56 = azerty; 7.8 = test", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : a = \,\=\+\<\>\#\;\\\"\C4\8D"
         */
        @Test
        public void testLdapDNPairCharAttributeValue() throws InvalidNameException
        {
    
            LdapDN dn = new LdapDN( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" );
    
            assertTrue( LdapDN.isValid( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D" ) );
            assertEquals( "a=\\,=\\+\\<\\>#\\;\\\\\\\"\\C4\\8D", dn.toString() );
            assertEquals( "a = \\,\\=\\+\\<\\>\\#\\;\\\\\\\"\\C4\\8D", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with pair char attribute value : "SN=Lu\C4\8Di\C4\87"
         */
        @Test
        public void testLdapDNRFC253_Lucic() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "SN=Lu\\C4\\8Di\\C4\\87" );
    
            assertTrue( LdapDN.isValid( "SN=Lu\\C4\\8Di\\C4\\87" ) );
            assertEquals( "sn=Lu\\C4\\8Di\\C4\\87", dn.toString() );
            assertEquals( "SN=Lu\\C4\\8Di\\C4\\87", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with hexString attribute value : a = #0010A0AAFF
         */
        @Test
        public void testLdapDNHexStringAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = #0010A0AAFF" );
    
            assertTrue( LdapDN.isValid( "a = #0010A0AAFF" ) );
            assertEquals( "a=#0010A0AAFF", dn.toString() );
            assertEquals( "a = #0010A0AAFF", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a # on first position
         */
        @Test
        public void testLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "a = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "a = \\#this is a sharp" ) );
            assertEquals( "a=\\#this is a sharp", dn.toString() );
            assertEquals( "a = \\#this is a sharp", dn.getUpName() );
    
            Rdn rdn = dn.getRdn();
            assertEquals( "a = \\#this is a sharp", rdn.getUpName() );
        }
    
    
        /**
         * Normalize a simple DN with a # on first position
         */
        @Test
        public void testNormalizeLdapDNSharpFirst() throws InvalidNameException, NamingException
        {
            LdapDN dn = new LdapDN( "ou = \\#this is a sharp" );
    
            assertTrue( LdapDN.isValid( "ou = \\#this is a sharp" ) );
            assertEquals( "ou=\\#this is a sharp", dn.toString() );
            assertEquals( "ou = \\#this is a sharp", dn.getUpName() );
    
            LdapDN ndn = dn.normalize( oidOids );
    
            assertEquals( "ou = \\#this is a sharp", ndn.getUpName() );
            assertEquals( "2.5.4.11=\\#this is a sharp", ndn.toString() );
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #0010Z0AAFF
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue()
        {
            try
            {
                new LdapDN( "a = #0010Z0AAFF" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
    
                assertFalse( LdapDN.isValid( "a = #0010Z0AAFF" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a wrong hexString attribute value : a = #AABBCCDD3
         */
        @Test
        public void testLdapDNWrongHexStringAttributeValue2()
        {
            try
            {
                new LdapDN( "a = #AABBCCDD3" );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertFalse( LdapDN.isValid( "a = #AABBCCDD3" ) );
                assertTrue( true );
            }
        }
    
    
        /**
         * test a simple DN with a quote in attribute value : a = quoted \"value\"
         */
        @Test
        public void testLdapDNQuoteInAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = quoted \\\"value\\\"" );
    
            assertTrue( LdapDN.isValid( "a = quoted \\\"value\\\"" ) );
            assertEquals( "a=quoted \\\"value\\\"", dn.toString() );
            assertEquals( "a = quoted \\\"value\\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with quoted attribute value : a = \" quoted value \"
         */
        @Test
        public void testLdapDNQuotedAttributeValue() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = \\\" quoted value \\\"" );
    
            assertTrue( LdapDN.isValid( "a = \\\" quoted value \\\"" ) );
            assertEquals( "a=\\\" quoted value \\\"", dn.toString() );
            assertEquals( "a = \\\" quoted value \\\"", dn.getUpName() );
        }
    
    
        /**
         * test a simple DN with a comma at the end
         */
        @Test
        public void testLdapDNComaAtEnd()
        {
            assertFalse( LdapDN.isValid( "a = b," ) );
            assertFalse( LdapDN.isValid( "a = b, " ) );
    
            try
            {
                new LdapDN( "a = b," );
                fail();
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        // REMOVE operation -------------------------------------------------------
    
        /**
         * test a remove from position 0
         */
        @Test
        public void testLdapDNRemove0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "e=f", dn.remove( 0 ).toString() );
            assertEquals( "a=b,c=d", dn.toString() );
            assertEquals( "a=b, c=d", dn.getUpName() );
        }
         * test a remove from position 1
         */
        @Test
        public void testLdapDNRemove1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 2
         */
        @Test
        public void testLdapDNRemove2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( "a=b", dn.remove( 2 ).toString() );
            assertEquals( " c=d, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove from position 1 whith semi colon
         */
        @Test
        public void testLdapDNRemove1WithSemiColon() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
            assertEquals( "c=d", dn.remove( 1 ).toString() );
            assertEquals( "a=b, e=f", dn.getUpName() );
        }
    
    
        /**
         * test a remove out of bound
         */
        @Test
        public void testLdapDNRemoveOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d; e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d; e=f" ) );
    
            try
            {
                dn.remove( 4 );
                // We whould never reach this point
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        // SIZE operations
        /**
         * test a 0 size
         */
        @Test
        public void testLdapDNSize0()
        {
            LdapDN dn = new LdapDN();
    
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
        public void testLdapEmptyAdd() throws InvalidNameException
        {
    
        // ADD ALL Operations
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
    
        /**
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
    
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
            assertEquals( false, nc.hasMoreElements() );
         * Test a startsWith an simple LdapDN
         */
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        }
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
    
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
    
        }
    
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
            assertTrue( name2.compareTo( name3 ) < 0 );
        }
    
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
    
            for ( int i = 0; rdns.hasMoreElements(); i++ )
            {
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
    
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
            for ( int i = 0; enum2.hasMoreElements(); i++ )
            {
                String element = ( String ) enum2.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
            }
    
            Enumeration enum3 = name3.getAll();
            assertEquals( true, enum3.hasMoreElements() );
    
            for ( int i = 0; enum3.hasMoreElements(); i++ )
            {
                String element = ( String ) enum3.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
            }
    
            Enumeration enum4 = name4.getAll();
            assertEquals( true, enum4.hasMoreElements() );
    
            for ( int i = 0; enum4.hasMoreElements(); i++ )
            {
                String element = ( String ) enum4.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
            }
    
            Enumeration enum5 = name5.getAll();
            assertEquals( true, enum5.hasMoreElements() );
    
            for ( int i = 0; enum5.hasMoreElements(); i++ )
            {
                String element = ( String ) enum5.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
            }
    
            Enumeration enum6 = name6.getAll();
            assertEquals( true, enum6.hasMoreElements() );
    
            for ( int i = 0; enum6.hasMoreElements(); i++ )
            {
                String element = ( String ) enum6.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element );
                }
    
                if ( i == 5 )
                {
                    assertEquals( "cn=Airline", element );
                }
            }
        }
    
    
        /**
         * Class to test for getAllRdn
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAllRdn() throws Exception
        {
            LdapDN name = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration rdns = name.getAllRdn();
            assertEquals( true, rdns.hasMoreElements() );
                Rdn element = ( Rdn ) rdns.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=West", element.toString() );
                }
    
                if ( i == 1 )
                {
                    assertEquals( "ou=Marketing", element.toString() );
                }
    
                if ( i == 2 )
                {
                    assertEquals( "cn=John", element.toString() );
                }
    
                if ( i == 3 )
                {
                    assertEquals( "cn=HomeDir", element.toString() );
                }
    
                if ( i == 4 )
                {
                    assertEquals( "cn=Website", element.toString() );
                }
    
                if ( i == 5 )
                {
        {
                    assertEquals( "cn=Airline", element.toString() );
                }
            }
        }
    
    
        /**
         * Class to test for get
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGet() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "cn=HomeDir", name.get( 3 ) );
            assertEquals( "cn=John", name.get( 2 ) );
            assertEquals( "ou=Marketing", name.get( 1 ) );
            assertEquals( "ou=East", name.get( 0 ) );
        }
    
    
        /**
         * Class to test for getSuffix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetXSuffix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertEquals( "", name.getSuffix( 4 ).toString() );
            assertEquals( "cn=HomeDir", name.getSuffix( 3 ).toString() );
            assertEquals( "cn=HomeDir,cn=John", name.getSuffix( 2 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing", name.getSuffix( 1 ).toString() );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getSuffix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for getPrefix
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testGetPrefix() throws Exception
        {
            Name name = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.getPrefix( 4 ).toString() );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.getPrefix( 3 ).toString() );
            assertEquals( "ou=Marketing,ou=East", name.getPrefix( 2 ).toString() );
            assertEquals( "ou=East", name.getPrefix( 1 ).toString() );
            assertEquals( "", name.getPrefix( 0 ).toString() );
        }
    
    
        /**
         * Class to test for startsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testStartsWith() throws Exception
        {
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.startsWith( name1 ) );
            assertTrue( name0.startsWith( name2 ) );
            assertTrue( name0.startsWith( name3 ) );
            assertTrue( name0.startsWith( name4 ) );
            assertTrue( name0.startsWith( name5 ) );
    
            assertTrue( !name0.startsWith( name6 ) );
            assertTrue( !name0.startsWith( name7 ) );
            assertTrue( !name0.startsWith( name8 ) );
        }
    
    
        /**
         * Class to test for endsWith
         *
         * @throws Exception
         *             anything goes wrong
         */
        @Test
        public void testEndsWith() throws Exception
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "ou=East" );
            Name name5 = new LdapDN( "" );
    
            Name name6 = new LdapDN( "cn=HomeDir" );
            Name name7 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name8 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing" );
    
            assertTrue( name0.endsWith( name1 ) );
            assertTrue( !name0.endsWith( name2 ) );
            assertTrue( !name0.endsWith( name3 ) );
            assertTrue( !name0.endsWith( name4 ) );
            assertTrue( name0.endsWith( name5 ) );
    
            assertTrue( name0.endsWith( name6 ) );
            assertTrue( name0.endsWith( name7 ) );
            assertTrue( name0.endsWith( name8 ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            assertTrue( name0.equals( name.addAll( name0 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllNameExisting0() throws Exception
        {
            Name name1 = new LdapDN( "ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John" );
            Name nameAdded = new LdapDN( "cn=HomeDir,cn=John, ou=Marketing,ou=East" );
            assertTrue( nameAdded.equals( name1.addAll( name2 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(Name)
         *
         * @throws Exception
         *             when anything goes wrong
         */
        @Test
        public void testAddAllName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName0() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=HomeDir,cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
        }
    
    
        /**
         * Class to test for Name addAll(int, Name)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddAllintName1() throws Exception
        {
            Name name = new LdapDN();
            Name name0 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name0.equals( name.addAll( name0 ) ) );
            assertTrue( name2.equals( name.addAll( 2, name1 ) ) );
    
            Name name3 = new LdapDN( "cn=Airport" );
            Name name4 = new LdapDN( "cn=Airport,cn=HomeDir,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name4.equals( name.addAll( 4, name3 ) ) );
    
            Name name5 = new LdapDN( "cn=ABC123" );
            Name name6 = new LdapDN( "cn=Airport,cn=HomeDir,cn=ABC123,cn=John,ou=Marketing,ou=East" );
    
            assertTrue( name6.equals( name.addAll( 3, name5 ) ) );
        }
    
    
        /**
         * Class to test for Name add(String)
         *
         * @throws Exception
         *             when something goes wrong
         */
        @Test
        public void testAddString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( "cn=HomeDir" );
            assertEquals( name0, name );
        }
    
    
        /**
         * Class to test for Name add(int, String)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testAddintString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( name, new LdapDN( "" ) );
    
            Name name4 = new LdapDN( "ou=East" );
            name.add( "ou=East" );
            assertEquals( name4, name );
    
            Name name3 = new LdapDN( "ou=Marketing,ou=East" );
            name.add( 1, "ou=Marketing" );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            name.add( 2, "cn=John" );
            assertEquals( name2, name );
    
            Name name0 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            name.add( 3, "cn=HomeDir" );
            assertEquals( name0, name );
    
            Name name5 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,o=LL " + "Bean Inc." );
            name.add( 0, "o=LL Bean Inc." );
            assertEquals( name5, name );
    
            Name name6 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 1, "c=US" );
            assertEquals( name6, name );
    
            Name name7 = new LdapDN( "cn=HomeDir,cn=John,ou=Advertising,ou=Marketing," + "ou=East,c=US,o=LL " + "Bean Inc." );
            name.add( 4, "ou=Advertising" );
            assertEquals( name7, name );
        }
    
    
        /**
         * Class to test for remove
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testRemove() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( new LdapDN( "" ), name );
    
            Name name3 = new LdapDN( "ou=Marketing" );
            name.add( "ou=East" );
            name.add( 1, "ou=Marketing" );
            name.remove( 0 );
            assertEquals( name3, name );
    
            Name name2 = new LdapDN( "cn=HomeDir,ou=Marketing,ou=East" );
            name.add( 0, "ou=East" );
            name.add( 2, "cn=John" );
            name.add( "cn=HomeDir" );
            name.remove( 2 );
            assertEquals( name2, name );
    
            name.remove( 1 );
            Name name1 = new LdapDN( "cn=HomeDir,ou=East" );
            assertEquals( name1, name );
    
            name.remove( 1 );
            Name name0 = new LdapDN( "ou=East" );
            assertEquals( name0, name );
    
            name.remove( 0 );
            assertEquals( new LdapDN( "" ), name );
        }
    
    
        /**
         * Class to test for String toString()
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testToString() throws Exception
        {
            Name name = new LdapDN();
            assertEquals( "", name.toString() );
    
            name.add( "ou=East" );
            assertEquals( "ou=East", name.toString() );
    
            name.add( 1, "ou=Marketing" );
            assertEquals( "ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=John" );
            assertEquals( "cn=John,ou=Marketing,ou=East", name.toString() );
    
            name.add( "cn=HomeDir" );
            assertEquals( "cn=HomeDir,cn=John,ou=Marketing,ou=East", name.toString() );
        }
    
    
        /**
         * Class to test for boolean equals(Object)
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        public void testEqualsObject() throws Exception
        {
            assertTrue( new LdapDN( "ou=People" ).equals( new LdapDN( "ou=People" ) ) );
    
            assertTrue( !new LdapDN( "ou=People,dc=example,dc=com" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=people" ).equals( new LdapDN( "ou=People" ) ) );
            assertTrue( !new LdapDN( "ou=Groups" ).equals( new LdapDN( "ou=People" ) ) );
        }
    
    
        @Test
        public void testNameFrenchChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', 0x4A, ( byte ) 0xC3, ( byte ) 0xA9, 0x72, ( byte ) 0xC3, ( byte ) 0xB4, 0x6D, 0x65 },
                "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=J\\C3\\A9r\\C3\\B4me", name.toString() );
        }
            {
    
    
        @Test
        public void testNameGermanChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC3, ( byte ) 0x84, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0x9C,
                    ( byte ) 0xC3, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0xA4, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0xBC }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C3\\84\\C3\\96\\C3\\9C\\C3\\9F\\C3\\A4\\C3\\B6\\C3\\BC", name.toString() );
        }
    
    
        @Test
        public void testNameTurkishChars() throws Exception
        {
            String cn = new String( new byte[]
                { 'c', 'n', '=', ( byte ) 0xC4, ( byte ) 0xB0, ( byte ) 0xC4, ( byte ) 0xB1, ( byte ) 0xC5, ( byte ) 0x9E,
                    ( byte ) 0xC5, ( byte ) 0x9F, ( byte ) 0xC3, ( byte ) 0x96, ( byte ) 0xC3, ( byte ) 0xB6,
                    ( byte ) 0xC3, ( byte ) 0x9C, ( byte ) 0xC3, ( byte ) 0xBC, ( byte ) 0xC4, ( byte ) 0x9E,
                    ( byte ) 0xC4, ( byte ) 0x9F }, "UTF-8" );
    
            Name name = new LdapDN( cn );
    
            assertEquals( "cn=\\C4\\B0\\C4\\B1\\C5\\9E\\C5\\9F\\C3\\96\\C3\\B6\\C3\\9C\\C3\\BC\\C4\\9E\\C4\\9F", name
                .toString() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map)
         */
        @Test
        public void testLdapNameToName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Name result = LdapDN.normalize( name, oids );
    
            assertTrue( result.toString().equals( "ou=some people,dc=example,dc=com" ) );
        }
    
    
        @Test
        public void testRdnGetTypeUpName() throws Exception
        {
            List list = new ArrayList();
            list.add( "ou= Some   People   " );
            list.add( "dc = eXample" );
            list.add( "dc= cOm" );
            LdapDN name = new LdapDN( list.iterator() );
    
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn = name.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn.getUpName() );
            assertEquals( "ou", rdn.getNormType() );
            assertEquals( "ou", rdn.getUpType() );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result.getNormName().equals(
                "2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( name.getUpName().equals( "ou= Some   People   ,dc = eXample,dc= cOm" ) );
    
            Rdn rdn2 = result.getRdn();
    
            assertEquals( "ou= Some   People   ", rdn2.getUpName() );
            assertEquals( "2.5.4.11", rdn2.getNormType() );
            assertEquals( "ou", rdn2.getUpType() );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a NULL dn
         */
        @Test
        public void testLdapNameToNameEmpty() throws Exception
        {
            LdapDN name = new LdapDN();
    
            Name result = LdapDN.normalize( name, oids );
            assertTrue( result.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        @Test
        public void testLdapNameToNameMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" );
    
            Name result = LdapDN.normalize( name, oidOids );
    
            assertEquals(
                result.toString(),
                "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" );
            assertTrue( ( ( LdapDN ) result )
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + 0.9.2342.19200300.100.1.25=  And   Some anImAls,0.9.2342.19200300.100.1.25 = eXample,dc= cOm" ) );
        }
    
    
        /**
         * Class to test for toOid( Name, Map) with a multiple NameComponent
         */
        @Test
        public void testLdapNameToNameAliasMultiNC() throws Exception
        {
            LdapDN name = new LdapDN(
                "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" );
    
            LdapDN result = LdapDN.normalize( name, oidOids );
    
            assertTrue( result
                .toString()
                .equals(
                    "0.9.2342.19200300.100.1.25=and some animals+2.5.4.11=some people,0.9.2342.19200300.100.1.25=example,0.9.2342.19200300.100.1.25=com" ) );
            assertTrue( result
                .getUpName()
                .equals(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm" ) );
        }
    
    
        /**
         * Class to test for hashCode().
         */
        @Test
        public void testLdapNameHashCode() throws Exception
        {
            Name name1 = LdapDN
                .normalize(
                    "2.5.4.11= Some   People   + domainComponent=  And   Some anImAls,DomainComponent = eXample,0.9.2342.19200300.100.1.25= cOm",
                    oids );
    
            Name name2 = LdapDN
                .normalize(
                    "2.5.4.11=some people+domainComponent=and some animals,DomainComponent=example,0.9.2342.19200300.100.1.25=com",
                    oids );
    
            assertEquals( name1.hashCode(), name2.hashCode() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testName() throws NamingException
        {
            Name jName = new javax.naming.ldap.LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( aName.toString(), "cn=four,cn=three,cn=two,cn=one" );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetPrefixName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getPrefix( 0 ).toString(), aName.getPrefix( 0 ).toString() );
            assertEquals( jName.getPrefix( 1 ).toString(), aName.getPrefix( 1 ).toString() );
            assertEquals( jName.getPrefix( 2 ).toString(), aName.getPrefix( 2 ).toString() );
            assertEquals( jName.getPrefix( 3 ).toString(), aName.getPrefix( 3 ).toString() );
            assertEquals( jName.getPrefix( 4 ).toString(), aName.getPrefix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetSuffix() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.getSuffix( 0 ).toString(), aName.getSuffix( 0 ).toString() );
            assertEquals( jName.getSuffix( 1 ).toString(), aName.getSuffix( 1 ).toString() );
            assertEquals( jName.getSuffix( 2 ).toString(), aName.getSuffix( 2 ).toString() );
            assertEquals( jName.getSuffix( 3 ).toString(), aName.getSuffix( 3 ).toString() );
            assertEquals( jName.getSuffix( 4 ).toString(), aName.getSuffix( 4 ).toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddStringName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( "cn=five" ) );
            assertSame( aName, aName.add( "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddIntString() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.add( 0, "cn=zero" ) );
            assertSame( aName, aName.add( 0, "cn=zero" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( 2, "cn=one.5" ) );
            assertSame( aName, aName.add( 2, "cn=one.5" ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.add( jName.size(), "cn=five" ) );
            assertSame( aName, aName.add( aName.size(), "cn=five" ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( new LdapName( "cn=seven,cn=six" ) ) );
            assertSame( aName, aName.addAll( new LdapDN( "cn=seven,cn=six" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testAddAllIntName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertSame( jName, jName.addAll( 0, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 0, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( 2, new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( 2, new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
    
            assertSame( jName, jName.addAll( jName.size(), new LdapName( "cn=zero,cn=zero.5" ) ) );
            assertSame( aName, aName.addAll( aName.size(), new LdapDN( "cn=zero,cn=zero.5" ) ) );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testStartsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( "a=\"b,c\"", dn.getUpName() );
            assertEquals( jName.startsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.startsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.startsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.startsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testEndsWithName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.endsWith( new LdapName( "cn=seven,cn=six,cn=five" ) ), aName.endsWith( new LdapDN(
                "cn=seven,cn=six,cn=five" ) ) );
            assertEquals( jName.endsWith( new LdapName( "cn=three,cn=two,cn=one" ) ), aName.endsWith( new LdapDN(
                "cn=three,cn=two,cn=one" ) ) );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testRemoveName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            assertEquals( jName.remove( 0 ).toString(), aName.remove( 0 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
    
            assertEquals( jName.remove( jName.size() - 1 ).toString(), aName.remove( aName.size() - 1 ).toString() );
            assertEquals( jName.toString(), aName.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-191
         */
        @Test
        public void testGetAllName() throws NamingException
        {
            Name jName = new LdapName( "cn=four,cn=three,cn=two,cn=one" );
            Name aName = new LdapDN( "cn=four,cn=three,cn=two,cn=one" );
    
            Enumeration j = jName.getAll();
            Enumeration a = aName.getAll();
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642() throws NamingException
        {
            Name name1 = new LdapDN( "cn=\"Kylie Minogue\",dc=example,dc=com" );
            Name name2 = new LdapName( "cn=\"Kylie Minogue\",dc=example,dc=com" );
    
            Enumeration j = name1.getAll();
            Enumeration a = name2.getAll();
    
            while ( j.hasMoreElements() )
            {
                assertTrue( j.hasMoreElements() );
                assertEquals( j.nextElement(), a.nextElement() );
            }
        }
    
    
        /**
         * Test for DIRSERVER-642
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteInNameDIRSERVER_642_1() throws NamingException
        {
            LdapDN dn = new LdapDN( "cn=\" Kylie Minogue \",dc=example,dc=com" );
    
            assertEquals( "cn=\" Kylie Minogue \",dc=example,dc=com", dn.getUpName() );
            assertEquals( "cn=\\ Kylie Minogue\\ ,dc=example,dc=com", dn.toString() );
        }
    
    
        /**
         * Test for DIRSTUDIO-250
         * @throws NamingException
         */
        @Test
        public void testDoubleQuoteWithSpecialCharsInNameDIRSERVER_250() throws NamingException
        {
            LdapDN dn = new LdapDN( "a=\"b,c\"" );
    
        {
            try
            assertEquals( "a=b\\,c", dn.toString() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testLeadingAndTrailingSpacesDIRSERVER_184() throws NamingException
        {
            LdapDN name = new LdapDN( "dn= \\ four spaces leading and 3 trailing \\  " );
    
            assertEquals( "dn=\\ four spaces leading and 3 trailing \\ ", name.toString() );
            assertEquals( "dn= \\ four spaces leading and 3 trailing \\  ", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_1()
                new LdapDN( "dn=middle\\ spaces" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_2()
        {
            try
            {
                new LdapDN( "dn=# a leading pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_3() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=\\# a leading pound" );
    
            assertEquals( "dn=\\# a leading pound", name.toString() );
            assertEquals( "dn=\\# a leading pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_4() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a middle \\# pound" );
    
            assertEquals( "dn=a middle # pound", name.toString() );
            assertEquals( "dn=a middle \\# pound", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_5() throws NamingException
        {
            LdapDN name = new LdapDN( "dn=a trailing pound \\#" );
    
            assertEquals( "dn=a trailing pound #", name.toString() );
            assertEquals( "dn=a trailing pound \\#", name.getUpName() );
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
        @Test
        public void testDIRSERVER_184_6()
        {
            try
            {
                new LdapDN( "dn=a middle # pound" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Test for DIRSERVER-184
         * @throws NamingException
         */
    
        public void testDIRSERVER_184_7()
        {
            try
            {
                new LdapDN( "dn=a trailing pound #" );
            }
            catch ( InvalidNameException ine )
            {
                assertTrue( true );
            }
        }
    
    
        @Test
        public void testDIRSERVER_631_1() throws NamingException
        {
            LdapDN name = new LdapDN( "cn=Bush\\, Kate,dc=example,dc=com" );
    
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.toString() );
            assertEquals( "cn=Bush\\, Kate,dc=example,dc=com", name.getUpName() );
    
        }
    
    
        /**
         * Added a test to check the parsing of a DN with more than one RDN
         * which are OIDs, and with one RDN which has more than one atav.
         * @throws NamingException
         */
        @Test
        public void testDNWithMultiOidsRDN() throws NamingException
        {
            LdapDN name = new LdapDN(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us" );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .toString() );
            assertEquals(
                "0.9.2342.19200300.100.1.1=00123456789+2.5.4.3=pablo picasso,2.5.4.11=search,2.5.4.10=imc,2.5.4.6=us", name
                    .getUpName() );
        }
    
    
        @Test
        public void testNameAddAll() throws NamingException
        {
            Properties props = new Properties();
            props.setProperty( "jndi.syntax.direction", "right_to_left" );
            props.setProperty( "jndi.syntax.separator", "," );
            props.setProperty( "jndi.syntax.ignorecase", "true" );
            props.setProperty( "jndi.syntax.trimblanks", "true" );
    
            Name dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            LdapDN ldapDn = new LdapDN();
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=blah,dc=example,dc=com", ldapDn.toString() );
    
            dn = new CompoundName( "cn=blah,dc=example,dc=com", props );
            ldapDn = new LdapDN( "cn=xyz" );
            ldapDn.addAll( 0, dn );
    
            assertEquals( "cn=xyz,cn=blah,dc=example,dc=com", ldapDn.toString() );
        }
    
    
        @Test
        public void testDNEquals() throws NamingException
        {
            LdapDN dn1 = new LdapDN( "a=b,c=d,e=f" );
            LdapDN dn2 = new LdapDN( "a=b\\,c\\=d,e=f" );
    
            assertFalse( dn1.toString().equals( dn2.toString() ) );
        }
    
    
        @Test
        public void testDNAddEmptyString() throws NamingException
        {
            LdapDN dn = new LdapDN();
            assertTrue( dn.size() == 0 );
            assertTrue( dn.add( "" ).size() == 0 );
        }
    
    
        /**
         * This leads to the bug in DIRSERVER-832.
         */
        @Test
        public void testPreserveAttributeIdCase() throws NamingException
        {
            LdapDN dn = new LdapDN( "uID=kevin" );
            assertEquals( "uID", dn.getRdn().getUpType() );
        }
    
    
        /**
         * Tests the LdapDN.isValid() method.
         */
        @Test
        public void testIsValid()
        {
            assertTrue( LdapDN.isValid( "" ) );
    
            assertFalse( LdapDN.isValid( "a" ) );
            assertFalse( LdapDN.isValid( "a " ) );
    
            assertTrue( LdapDN.isValid( "a=" ) );
            assertTrue( LdapDN.isValid( "a= " ) );
    
            assertFalse( LdapDN.isValid( "=" ) );
            assertFalse( LdapDN.isValid( " = " ) );
            assertFalse( LdapDN.isValid( " = a" ) );
        }
    
    
        private ByteArrayOutputStream serializeDN( LdapDN dn ) throws IOException
        {
            ObjectOutputStream oOut = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
    
            try
            {
                oOut = new ObjectOutputStream( out );
                oOut.writeObject( dn );
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oOut != null )
                    {
                        oOut.flush();
                        oOut.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
    
            return out;
        }
    
    
        private LdapDN deserializeDN( ByteArrayOutputStream out ) throws IOException, ClassNotFoundException
        {
            ObjectInputStream oIn = null;
            ByteArrayInputStream in = new ByteArrayInputStream( out.toByteArray() );
    
            try
            {
                oIn = new ObjectInputStream( in );
    
                LdapDN dn = ( LdapDN ) oIn.readObject();
    
                return dn;
            }
            catch ( IOException ioe )
            {
                throw ioe;
            }
            finally
            {
                try
                {
                    if ( oIn != null )
                    {
                        oIn.close();
                    }
                }
                catch ( IOException ioe )
                {
                    throw ioe;
                }
            }
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        @Test
        public void testSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    
    
        /**
         * Test the serialization of a DN
         *
         * @throws Exception
         */
        @Test
        public void testNameStaticSerialization() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
        }
    
    
        /*
        @Test public void testSerializationPerfs() throws Exception
        {
            LdapDN dn = new LdapDN( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
            dn.normalize( oids );
    
            long t0 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000; i++ )
            {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream out = new ObjectOutputStream( baos );
                DnSerializer.serialize( dn, out );
                
                byte[] data = baos.toByteArray();
                ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                LdapDN dn1 = DnSerializer.deserialize( in );
            }
            
            long t1 = System.currentTimeMillis();
            
            System.out.println( "delta :" + ( t1 - t0) );
    
            long t2 = System.currentTimeMillis();
            
            for ( int i = 0; i < 1000000; i++ )
            {
                //ByteArrayOutputStream baos = new ByteArrayOutputStream();
                //ObjectOutputStream out = new ObjectOutputStream( baos );
    
                //DnSerializer.serializeString( dn, out );
                
                //byte[] data = baos.toByteArray();
                //ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
                
                //LdapDN dn1 = DnSerializer.deserializeString( in, oids );
                dn.normalize( oids );
            }
            
            long t3 = System.currentTimeMillis();
    
            System.out.println( "delta :" + ( t3 - t2) );
    
            //assertEquals( dn, DnSerializer.deserialize( in ) );
        }
        */
    
        @Test
        public void testStaticSerializeEmptyDN() throws Exception
        {
            LdapDN dn = LdapDN.EMPTY_LDAPDN;
    
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    
            assertEquals( dn, LdapDNSerializer.deserialize( in ) );
            assertEquals( dn, deserializeDN( serializeDN( dn ) ) );
        }
    }
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            assertEquals( 3, dn.size() );
        }
    
    <<<<<<< HEAD
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
    =======
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
        }
    
    
         */
        @Test
        // GET operations
        /**
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        @Test
        @Test
         */
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * 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 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        public void testLdapDNGetSuffixPos4() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
    
            try
            {
                dn.getSuffix( 4 );
    
        /**
         * Test a startsWith a complex LdapDN
                // We should not reach this point.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
        @Test
        @Test
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
            assertTrue( LdapDN.isValid( "" ) );
            assertEquals( 0, dn.size() );
        }
    
    
        /**
         * test a 1 size
         */
        @Test
        public void testLdapDNSize1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
    
            assertTrue( LdapDN.isValid( "a=b" ) );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test a 3 size
         */
        @Test
        public void testLdapDNSize3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test a 3 size with NameComponents
         */
        @Test
        public void testLdapDNSize3NC() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b+c=d, c=d, e=f" );
    
            assertTrue( LdapDN.isValid( "a=b+c=d, c=d, e=f" ) );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test size after operations
         */
        @Test
        public void testLdapResizing() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            assertEquals( 0, dn.size() );
    
            dn.add( "e = f" );
            assertEquals( 1, dn.size() );
    
            dn.add( "c = d" );
            assertEquals( 2, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 1, dn.size() );
    
            dn.remove( 0 );
            assertEquals( 0, dn.size() );
        }
    
    
        // ADD Operations
        /**
         * test Add on a new LdapDN
         */
        @Test
        public void testLdapEmptyAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
    
            dn.add( "e = f" );
            assertEquals( "e=f", dn.toString() );
            assertEquals( "e = f", dn.getUpName() );
            assertEquals( 1, dn.size() );
        }
    
    
        /**
         * test Add to an existing LdapDN
         */
        @Test
        public void testLdapDNAdd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( "e = f" );
            assertEquals( "e=f,a=b,c=d", dn.toString() );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add a composite RDN to an existing LdapDN
         */
        @Test
        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.
            assertEquals( "e=f+g=h,a=b,c=d", dn.toString() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the end of an existing LdapDN
         */
        @Test
        public void testLdapDNAddEnd() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( dn.size(), "e = f" );
            assertEquals( "e = f,a=b, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        /**
         * test Add at the start of an existing LdapDN
         */
        @Test
        public void testLdapDNAddStart() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 0, "e = f" );
            assertEquals( "a=b, c=d,e = f", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Manual
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        }
    
    
        /**
        @Test
    
    
        /**
    <<<<<<< HEAD
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         */
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
        /**
         */
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        /**
         * Get the suffix at pos 0
         */
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a endsWith which returns false
         */
        @Test
            LdapDN dn = new LdapDN( "a=b" );
    
        // GET ALL operations
        public void testLdapDNEndsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
        }
    
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
         * Class to test for void LdapName(String)
         *
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
    =======
         * Class to test for isEmpty
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
         *
         * @throws Exception
         *             if anything goes wrong.
    Solution content
    
        /**
         * test Add at the middle of an existing LdapDN
         */
        @Test
        public void testLdapDNAddMiddle() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
    
            dn.add( 1, "e = f" );
            assertEquals( "a=b,e = f, c=d", dn.getUpName() );
            assertEquals( 3, dn.size() );
        }
    
    
        // ADD ALL Operations
        /**
         * Test AddAll
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll with an empty added name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt0AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b,c = d", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at position 1
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAt1AddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN( "c = d" );
            dn.addAll( 1, dn2 );
            assertEquals( "c = d,a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll at the middle
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAtTheMiddleAddAll() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b, c = d" );
            LdapDN dn2 = new LdapDN( "e = f" );
            dn.addAll( 1, dn2 );
            assertEquals( "a = b,e = f, c = d", dn.getUpName() );
        }
    
    
        /**
         */
        /**
         */
         * Get the suffix at pos 0
        // GET PREFIX actions
        /**
         * Get the prefix at pos 0
         * Test AddAll with an empty added name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0AddedNameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            LdapDN dn2 = new LdapDN();
            dn.addAll( 0, dn2 );
            assertEquals( "a=b", dn.toString() );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        /**
         * Test AddAll to an empty name at position 0
         *
         * @throws InvalidNameException
         */
        @Test
        public void testLdapDNAddAllAt0NameEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN();
            LdapDN dn2 = new LdapDN( "a = b" );
            dn.addAll( 0, dn2 );
            assertEquals( "a = b", dn.getUpName() );
        }
    
    
        @Test
        public void testLdapDNGetPrefixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 1
         */
        @Test
        public void testLdapDNGetPrefixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 1 ) );
            assertEquals( "e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 2
         */
        @Test
        public void testLdapDNGetPrefixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 2 ) );
            assertEquals( " c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix at pos 3
         */
        @Test
        public void testLdapDNGetPrefixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 3 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the prefix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the prefix of an empty LdapName
         */
        @Test
        public void testLdapDNGetPrefixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getPrefix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // GET SUFFIX operations
        @Test
        public void testLdapDNGetSuffixPos0() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "a=b, c=d,e = f", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 1
         */
        @Test
        public void testLdapDNGetSuffixPos1() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 1 ) );
            assertEquals( "a=b, c=d", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 2
         */
        @Test
        public void testLdapDNGetSuffixPos2() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 2 ) );
            assertEquals( "a=b", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix at pos 3
         */
        @Test
        public void testLdapDNGetSuffixPos3() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 3 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        /**
         * Get the suffix out of bound
         */
        @Test
        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.
                fail();
            }
            catch ( ArrayIndexOutOfBoundsException aoobe )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Get the suffix of an empty LdapName
         */
        @Test
        public void testLdapDNGetSuffixEmptyDN()
        {
            LdapDN dn = new LdapDN();
            LdapDN newDn = ( ( LdapDN ) dn.getSuffix( 0 ) );
            assertEquals( "", newDn.getUpName() );
        }
    
    
        // IS EMPTY operations
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNIsEmpty()
        {
            LdapDN dn = new LdapDN();
            assertEquals( true, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNNotEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            assertEquals( false, dn.isEmpty() );
        }
    
    
        /**
         * Test that a LdapDN is empty
         */
        @Test
        public void testLdapDNRemoveIsEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d" );
            dn.remove( 0 );
            dn.remove( 0 );
    
            assertEquals( true, dn.isEmpty() );
        }
    
    
        // STARTS WITH operations
         * Test a startsWith a complex LdapDN
        /**
         * Test a startsWith a null LdapDN
         */
        @Test
        public void testLdapDNStartsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( null ) );
        }
    
    
        /**
         * Test a startsWith an empty LdapDN
         */
        @Test
        public void testLdapDNStartsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a startsWith an simple LdapDN
         */
        @Test
        public void testLdapDNStartsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "e=f" ) ) );
        }
    
    
        /**
         */
        @Test
        public void testLdapDNStartsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a complex LdapDN
         */
        @Test
        public void testLdapDNStartsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  D, E =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith a full LdapDN
         */
        @Test
        public void testLdapDNStartsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.startsWith( new LdapDN( "a=  b; c =  d, e =  f" ) ) );
        }
    
    
        /**
         * Test a startsWith which returns false
         */
        @Test
        public void testLdapDNStartsWithWrong() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.startsWith( new LdapDN( "c =  t, e =  f" ) ) );
        }
    
    
        // ENDS WITH operations
        /**
         * Test a endsWith a null LdapDN
         */
        @Test
        public void testLdapDNEndsWithNull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( null ) );
        }
    
    
        /**
         * Test a endsWith an empty LdapDN
         */
        @Test
        public void testLdapDNEndsWithEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN() ) );
        }
    
    
        /**
         * Test a endsWith an simple LdapDN
         */
        @Test
        public void testLdapDNEndsWithSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a=b" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
        @Test
         */
        @Test
        public void testLdapDNEndsWithComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( true, dn.endsWith( new LdapDN( "a =  b, c =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a complex LdapDN
         */
        @Test
        public void testLdapDNEndsWithComplexMixedCase() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  B, C =  d" ) ) );
        }
    
    
        /**
         * Test a endsWith a full LdapDN
         */
        @Test
        public void testLdapDNEndsWithFull() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b, c=d,e = f" );
            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" );
            assertEquals( false, dn.endsWith( new LdapDN( "a =  b, e =  f" ) ) );
        }
    
    
        // GET ALL operations
        /**
         * test a getAll operation on a null DN
         */
        @Test
        public void testLdapDNGetAllNull()
        {
            LdapDN dn = new LdapDN();
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on an empty DN
         */
        @Test
        public void testLdapDNGetAllEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            Enumeration nc = dn.getAll();
    
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a simple DN
         */
        @Test
        public void testLdapDNGetAllSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        /**
         * test a getAll operation on a complex DN
         */
        @Test
        public void testLdapDNGetAllComplexOrdered() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "g=h+e=f,a=b,c=d" );
            Enumeration nc = dn.getAll();
    
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "c=d", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
            assertEquals( "a=b", nc.nextElement() );
            assertEquals( true, nc.hasMoreElements() );
    
            // The lowest atav should be the first one
            assertEquals( "e=f+g=h", nc.nextElement() );
            assertEquals( false, nc.hasMoreElements() );
        }
    
    
        // CLONE Operation
        /**
         * test a clone operation on a empty DN
         */
        @Test
        public void testLdapDNCloneEmpty()
        {
            LdapDN dn = new LdapDN();
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a simple DN
         */
        @Test
        public void testLdapDNCloneSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a=b" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "a=b", clone.getUpName() );
            dn.remove( 0 );
            assertEquals( "a=b", clone.getUpName() );
        }
    
    
        /**
         * test a clone operation on a complex DN
         */
        @Test
        public void testLdapDNCloneComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "e=f+g=h,a=b,c=d" );
            LdapDN clone = ( LdapDN ) dn.clone();
    
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
            dn.remove( 2 );
            assertEquals( "e=f+g=h,a=b,c=d", clone.getUpName() );
        }
    
    
        // GET operations
        /**
         * test a get in a null DN
         */
        @Test
        public void testLdapDNGetNull()
        {
            LdapDN dn = new LdapDN();
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in an empty DN
         */
        @Test
        public void testLdapDNGetEmpty() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "" );
            assertEquals( "", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a simple DN
         */
        @Test
        public void testLdapDNGetSimple() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b" );
            assertEquals( "a=b", dn.get( 0 ) );
        }
    
    
        /**
         * test a get in a complex DN
         */
        @Test
        public void testLdapDNGetComplex() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
            assertEquals( "g=h", dn.get( 0 ) );
            assertEquals( "e=f", dn.get( 1 ) );
            assertEquals( "a=b+c=d", dn.get( 2 ) );
        }
    
    
        /**
         * test a get out of bound
         */
        @Test
        public void testLdapDNGetOutOfBound() throws InvalidNameException
        {
            LdapDN dn = new LdapDN( "a = b + c= d, e= f; g =h" );
    
            try
        {
            List list = new ArrayList();
            {
                dn.get( 4 );
                fail();
            }
            catch ( IndexOutOfBoundsException aioob )
            {
                assertTrue( true );
            }
        }
    
    
        /**
         * Tests the examples from the JNDI tutorials to make sure LdapName behaves
         * appropriately. The example can be found online here.
         *
         * @throws Exception
         *             if anything goes wrong
         */
        @Test
        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();
    
            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 );
        }
    
    
        @Test
        public void testAttributeEqualsIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertTrue( name1.equals( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        public void testAttributeComparisonIsCaseInSensitive() throws Exception
        {
            Name name1 = new LdapDN( "cn=HomeDir" );
            Name name2 = new LdapDN( "CN=HomeDir" );
    
            assertEquals( 0, name1.compareTo( name2 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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 ) );
        }
    
    
        @Test
        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
         */
        @Test
        public void testNameToBytes() throws Exception
        {
            LdapDN dn = new LdapDN( "cn = John, ou = People, OU = Marketing" );
    
            byte[] bytes = LdapDN.getBytes( dn );
    
            assertEquals( 30, LdapDN.getNbBytes( dn ) );
            assertEquals( "cn=John,ou=People,ou=Marketing", new String( bytes, "UTF-8" ) );
        }
    
    
        @Test
        public void testStringParser() throws Exception
        {
    
            String dn = StringTools.utf8ToString( new byte[]
                { 'C', 'N', ' ', '=', ' ', 'E', 'm', 'm', 'a', 'n', 'u', 'e', 'l', ' ', ' ', 'L', ( byte ) 0xc3,
                    ( byte ) 0xa9, 'c', 'h', 'a', 'r', 'n', 'y' } );
    
            Name name = LdapDnParser.getNameParser().parse( dn );
    
            assertEquals( dn, ( ( LdapDN ) name ).getUpName() );
            assertEquals( "cn=Emmanuel  L\\C3\\A9charny", name.toString() );
        }
    
    
        /**
         * Class to test for void LdapName(String)
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testLdapNameString() throws Exception
        {
            Name name = new LdapDN( "" );
            Name name50 = new LdapDN();
            assertEquals( name50, name );
    
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
        }
    
    
        /**
         * Class to test for void LdapName()
         */
        @Test
        public void testLdapName()
        {
            Name name = new LdapDN();
            assertTrue( name.toString().equals( "" ) );
        }
    
    
        /**
         * Class to test for void LdapName(List)
         */
        @Test
        public void testLdapNameList() throws InvalidNameException
        {
            List list = new ArrayList();
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for void LdapName(Iterator)
         */
        @Test
        public void testLdapNameIterator() throws InvalidNameException
            list.add( "ou=People" );
            list.add( "dc=example" );
            list.add( "dc=com" );
            Name name = new LdapDN( list.iterator() );
            assertTrue( name.toString().equals( "ou=People,dc=example,dc=com" ) );
        }
    
    
        /**
         * Class to test for Object clone()
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testClone() throws Exception
        {
            String strName = "cn=HomeDir,cn=John,ou=Marketing,ou=East";
            Name name = new LdapDN( strName );
            assertEquals( name, name.clone() );
        }
    
    
        /**
         * Class to test for compareTo
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testCompareTo() throws Exception
        {
            Name name0 = new LdapDN( "ou=Marketing,ou=East" );
            Name copy = new LdapDN( "ou=Marketing,ou=East" );
            Name name1 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name2 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name4 = new LdapDN( "cn=Website,cn=John,ou=Marketing,ou=West" );
            Name name5 = new LdapDN( "cn=Airline,cn=John,ou=Marketing,ou=West" );
    
            assertTrue( name0.compareTo( copy ) == 0 );
            assertTrue( name0.compareTo( name1 ) < 0 );
            assertTrue( name0.compareTo( name2 ) < 0 );
            assertTrue( name1.compareTo( name2 ) < 0 );
            assertTrue( name2.compareTo( name1 ) > 0 );
            assertTrue( name2.compareTo( name0 ) > 0 );
            assertTrue( name2.compareTo( name3 ) < 0 );
            assertTrue( name2.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name4 ) < 0 );
            assertTrue( name3.compareTo( name5 ) > 0 );
            assertTrue( name4.compareTo( name5 ) > 0 );
            assertTrue( name2.compareTo( name5 ) < 0 );
    
            List list = new ArrayList();
    
            Comparator comparator = new Comparator()
            {
                public int compare( Name obj1, Name obj2 )
                {
                    Name n1 = obj1;
                    Name n2 = obj2;
                    return n1.compareTo( n2 );
                }
    
    
                public boolean equals( Object obj )
                {
                    return super.equals( obj );
                }
    
    
                /**
                 * Compute the instance's hash code
                 * @return the instance's hash code 
                 */
                public int hashCode()
                {
                    return super.hashCode();
                }
            };
    
            list.add( name0 );
            list.add( name1 );
            list.add( name2 );
            list.add( name3 );
            list.add( name4 );
            list.add( name5 );
            Collections.sort( list, comparator );
    
            assertEquals( name0, list.get( 0 ) );
            assertEquals( name1, list.get( 1 ) );
            assertEquals( name2, list.get( 2 ) );
            assertEquals( name5, list.get( 3 ) );
            assertEquals( name3, list.get( 4 ) );
            assertEquals( name4, list.get( 5 ) );
        }
    
    
        /**
         * Class to test for size
         *
         * @throws Exception
         *             if anything goes wrong.
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
         *             if anything goes wrong.
         */
        @Test
    <<<<<<< HEAD
        public void testSize() throws Exception
    =======
        public void testIsEmpty() throws Exception
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
    Solution content
         *             if anything goes wrong.
         */
        @Test
        public void testSize() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Method signature
    Chunk
    Conflicting content
            assertEquals( false, name5.isEmpty() );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
    <<<<<<< HEAD
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
    =======
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name6.isEmpty() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( 0, name0.size() );
            assertEquals( 1, name1.size() );
            assertEquals( 2, name2.size() );
            assertEquals( 3, name3.size() );
            assertEquals( 4, name4.size() );
            assertEquals( 5, name5.size() );
            assertEquals( 6, name6.size() );
        }
    
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Method invocation
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
         * Class to test for isEmpty
    =======
         * Class to test for getAll
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
         *
         * @throws Exception
         *             if anything goes wrong.
    Solution content
    
        /**
         * Class to test for isEmpty
         *
         * @throws Exception
         *             if anything goes wrong.
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Comment
    Chunk
    Conflicting content
         *             if anything goes wrong.
         */
        @Test
    <<<<<<< HEAD
        public void testIsEmpty() throws Exception
    =======
        public void testGetAll() throws Exception
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
    Solution content
         *             if anything goes wrong.
         */
        @Test
        public void testIsEmpty() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Method signature
    Chunk
    Conflicting content
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    <<<<<<< HEAD
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    Solution content
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            assertEquals( true, name0.isEmpty() );
            assertEquals( false, name1.isEmpty() );
            assertEquals( false, name2.isEmpty() );
            assertEquals( false, name3.isEmpty() );
            assertEquals( false, name4.isEmpty() );
            assertEquals( false, name5.isEmpty() );
            assertEquals( false, name6.isEmpty() );
        }
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Method invocation
    Chunk
    Conflicting content
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
    <<<<<<< HEAD
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
    =======
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
                {
                    assertEquals( "ou=East", element );
                }
            }
    
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
    Solution content
                {
                    assertEquals( "ou=East", element );
                }
            }
    
        /**
         * Class to test for getAll
         *
         * @throws Exception
         *             if anything goes wrong.
         */
        @Test
        public void testGetAll() throws Exception
        {
            Name name0 = new LdapDN( "" );
            Name name1 = new LdapDN( "ou=East" );
            Name name2 = new LdapDN( "ou=Marketing,ou=East" );
            Name name3 = new LdapDN( "cn=John,ou=Marketing,ou=East" );
            Name name4 = new LdapDN( "cn=HomeDir,cn=John,ou=Marketing,ou=East" );
            Name name5 = new LdapDN( "cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
            Name name6 = new LdapDN( "cn=Airline,cn=Website,cn=HomeDir,cn=John,ou=Marketing,ou=West" );
    
            Enumeration enum0 = name0.getAll();
            assertEquals( false, enum0.hasMoreElements() );
    
            Enumeration enum1 = name1.getAll();
            assertEquals( true, enum1.hasMoreElements() );
    
            for ( int i = 0; enum1.hasMoreElements(); i++ )
            {
                String element = ( String ) enum1.nextElement();
    
                if ( i == 0 )
    
            Enumeration enum2 = name2.getAll();
            assertEquals( true, enum2.hasMoreElements() );
    
    File
    LdapDNTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    For statement
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
    <<<<<<< HEAD
    =======
            out.flush();
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    Solution content
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    File
    LdapDNTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Method invocation
    Chunk
    Conflicting content
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
    <<<<<<< HEAD
    =======
            out.flush();
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    Solution content
            ObjectOutputStream out = new ObjectOutputStream( baos );
    
            LdapDNSerializer.serialize( dn, out );
            out.flush();
    
            byte[] data = baos.toByteArray();
            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
    File
    LdapDNTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Method invocation
    Chunk
    Conflicting content
            assertTrue( rdn5.compareTo( rdn6 ) < 0 );
            assertTrue( rdn6.compareTo( rdn5 ) > 0 );
            assertEquals( 0, rdn5.compareTo( rdn6 ) + rdn6.compareTo( rdn5 ) );
    <<<<<<< HEAD
        }
    
    
        /**
         * Test for DIRSHARED-2.
         * The compare operation should return a correct value (1 or -1)
         * depending on the ATAVs, not on their position.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareIndependentFromOrder() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b + c = d " );
            Rdn rdn2 = new Rdn( " c = d + a = b " );
            assertEquals( 0, rdn1.compareTo( rdn2 ) );
    
            rdn1 = new Rdn( " a = b + c = e " );
            rdn2 = new Rdn( " c = d + a = b " );
            assertTrue( rdn1.compareTo( rdn2 ) > 0 );
            assertTrue( rdn2.compareTo( rdn1 ) < 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
            rdn1 = new Rdn( " a = b + c = d " );
            rdn2 = new Rdn( " e = f + g = h " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
        }
    
    
        /**
         * Test for DIRSHARED-3.
         * Tests that compareTo() is invertable for single-valued RDNs.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareInvertableNC2NC() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b " );
            Rdn rdn2 = new Rdn( " a = c " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
    
            assertTrue( rdn6.compareTo( rdn5 ) > 0 );
            assertEquals( 0, rdn5.compareTo( rdn6 ) + rdn6.compareTo( rdn5 ) );
            assertTrue( rdn5.compareTo( rdn6 ) < 0 );
        }
        /**
         * Test for DIRSHARED-2.
         * The compare operation should return a correct value (1 or -1)
         * depending on the ATAVs, not on their position.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareIndependentFromOrder() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b + c = d " );
            Rdn rdn2 = new Rdn( " c = d + a = b " );
            assertEquals( 0, rdn1.compareTo( rdn2 ) );
    
            rdn1 = new Rdn( " a = b + c = e " );
            rdn2 = new Rdn( " c = d + a = b " );
            assertTrue( rdn1.compareTo( rdn2 ) > 0 );
            assertTrue( rdn2.compareTo( rdn1 ) < 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
            rdn1 = new Rdn( " a = b + c = d " );
            rdn2 = new Rdn( " e = f + g = h " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
        }
    
    
        /**
         * Test for DIRSHARED-3.
         * Tests that compareTo() is invertable for single-valued RDNs.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareInvertableNC2NC() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b " );
            Rdn rdn2 = new Rdn( " a = c " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
        }
    
    
    File
    RdnTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Method invocation
    Method signature
    Variable
    Chunk
    Conflicting content
    
        /**
    <<<<<<< HEAD
    =======
         * Test for DIRSHARED-2.
         * The compare operation should return a correct value (1 or -1)
         * depending on the ATAVs, not on their position.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareIndependentFromOrder() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b + c = d " );
            Rdn rdn2 = new Rdn( " c = d + a = b " );
            assertEquals( 0, rdn1.compareTo( rdn2 ) );
    
            rdn1 = new Rdn( " a = b + c = e " );
            rdn2 = new Rdn( " c = d + a = b " );
            assertTrue( rdn1.compareTo( rdn2 ) > 0 );
            assertTrue( rdn2.compareTo( rdn1 ) < 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
            rdn1 = new Rdn( " a = b + c = d " );
            rdn2 = new Rdn( " e = f + g = h " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
        }
    
    
        /**
         * Test for DIRSHARED-3.
         * Tests that compareTo() is invertable for single-valued RDNs.
         * 
         * @throws InvalidNameException
         */
        @Test
        public void testCompareInvertableNC2NC() throws InvalidNameException
        {
            Rdn rdn1 = new Rdn( " a = b " );
            Rdn rdn2 = new Rdn( " a = c " );
            assertTrue( rdn1.compareTo( rdn2 ) < 0 );
            assertTrue( rdn2.compareTo( rdn1 ) > 0 );
            assertEquals( 0, rdn1.compareTo( rdn2 ) + rdn2.compareTo( rdn1 ) );
    
        }
    
    
        /**
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
         * Test for DIRSHARED-3.
         * Tests that compareTo() is invertable for multi-valued RDNs with different values.
         * 
    Solution content
    
        /**
         * Test for DIRSHARED-3.
         * Tests that compareTo() is invertable for multi-valued RDNs with different values.
         * 
    File
    RdnTest.java
    Developer's decision
    Version 1
    Kind of conflict
    Annotation
    Comment
    Method declaration
    Chunk
    Conflicting content
            assertTrue( RdnParser.isValid( "a=\"b\\,c\"" ) );
            Rdn rdn = new Rdn( "a=\"b\\,c\"" );
    <<<<<<< HEAD
            assertEquals( "a=\"b\\,c\"", new Rdn( "a=\"b\\,c\"" ).getUpName() );
            assertEquals( "a=b\\,c", new Rdn( "a=\"b\\,c\"" ).toString() );
    =======
            assertEquals( "a=\"b\\,c\"", rdn.getUpName() );
            assertEquals( "a=b\\,c", rdn.toString() );
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
        }
    
    
    Solution content
            assertTrue( RdnParser.isValid( "a=\"b\\,c\"" ) );
            Rdn rdn = new Rdn( "a=\"b\\,c\"" );
            assertEquals( "a=\"b\\,c\"", rdn.getUpName() );
            assertEquals( "a=b\\,c", rdn.toString() );
        }
    
    
    File
    RdnTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Method invocation
    Chunk
    Conflicting content
        static class SyntaxImpl extends AbstractSyntax
        {
    <<<<<<< HEAD
            @SuppressWarnings ( { "AnalyzingVariableNaming" } )
    =======
    >>>>>>> 24aa11f9a3ba90c4ae12b678db88b8e69462a903
            private static final long serialVersionUID = 1L;
            
            protected SyntaxImpl(String oid)
    Solution content
        static class SyntaxImpl extends AbstractSyntax
        {
            private static final long serialVersionUID = 1L;
            
            protected SyntaxImpl(String oid)
    File
    SchemaUtilsTest.java
    Developer's decision
    Version 2
    Kind of conflict
    Annotation