directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1423968 [7/27] - in /directory/shared/branches/shared-refact: dsml/engine/src/main/java/org/apache/directory/shared/dsmlv2/engine/ dsml/parser/src/main/java/org/apache/directory/shared/dsmlv2/ dsml/parser/src/main/java/org/apache/directory...
Date Wed, 19 Dec 2012 17:24:42 GMT
Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/DnTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/MultiThreadedTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/MultiThreadedTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/MultiThreadedTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/MultiThreadedTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,141 @@
+/*
+ *  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.api.ldap.model.name;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.api.ldap.model.name.Ava;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.name.Rdn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.junit.tools.MultiThreadedMultiInvoker;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Multi-threaded 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class MultiThreadedTest
+{
+    @Rule
+    public MultiThreadedMultiInvoker i = new MultiThreadedMultiInvoker( 100, 1000 );
+
+    private static Dn referenceDn;
+    private static Dn sharedDn;
+    private static Rdn referenceRdn;
+    private static Rdn sharedRdn;
+    private static Ava referenceAva;
+    private static Ava sharedAva;
+
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+
+        referenceDn = new Dn( "dc=example,dc=com" );
+        referenceDn.apply( schemaManager );
+        sharedDn = new Dn( "dc=example,dc=com" );
+        sharedDn.apply( schemaManager );
+
+        referenceRdn = new Rdn( "ou=system" );
+        referenceRdn.apply( schemaManager );
+        sharedRdn = new Rdn( "ou=system" );
+        sharedRdn.apply( schemaManager );
+
+        referenceAva = new Ava( schemaManager, "ou", "System" );
+        sharedAva = new Ava( schemaManager, "ou", "System" );
+    }
+
+
+    @Test
+    public void testNormalize() throws Exception
+    {
+        sharedAva.normalize();
+
+        sharedRdn.apply( schemaManager );
+        assertTrue( sharedRdn.isSchemaAware() );
+
+        sharedDn.apply( schemaManager );
+        assertTrue( sharedDn.isSchemaAware() );
+    }
+
+
+    @Test
+    public void testNormalizeHashCode() throws Exception
+    {
+        assertEquals( referenceAva.hashCode(), sharedAva.hashCode() );
+
+        sharedRdn.apply( schemaManager );
+        assertEquals( referenceRdn.hashCode(), sharedRdn.hashCode() );
+
+        sharedDn.apply( schemaManager );
+        assertEquals( referenceDn.hashCode(), sharedDn.hashCode() );
+    }
+
+
+    @Test
+    public void testNormalizeEquals() throws Exception
+    {
+        assertEquals( referenceAva, sharedAva );
+        assertTrue( referenceAva.equals( sharedAva ) );
+        assertTrue( sharedAva.equals( referenceAva ) );
+
+        sharedRdn.apply( schemaManager );
+        assertEquals( referenceRdn, sharedRdn );
+        assertTrue( referenceRdn.equals( sharedRdn ) );
+        assertTrue( sharedRdn.equals( referenceRdn ) );
+
+        sharedDn.apply( schemaManager );
+        assertEquals( referenceDn, sharedDn );
+        assertTrue( referenceDn.equals( sharedDn ) );
+        assertTrue( sharedDn.equals( referenceDn ) );
+    }
+
+
+    @Test
+    public void testNormalizeCompare() throws Exception
+    {
+        assertTrue( sharedAva.equals( referenceAva ) );
+        assertTrue( referenceAva.equals( sharedAva ) );
+
+        assertTrue( referenceRdn.equals( sharedRdn ) );
+        assertTrue( sharedRdn.equals( referenceRdn ) );
+
+        assertEquals( referenceDn, sharedDn );
+        assertEquals( sharedDn, referenceDn );
+    }
+
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/MultiThreadedTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/RdnTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/RdnTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/RdnTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,173 @@
+/*
+ *  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.api.ldap.model.name;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Rdn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import static org.junit.Assert.assertEquals;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+/**
+ * Tests for the schemaAware Rdn class
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class RdnTest
+{
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+    @Test
+    public void testRdnValuesNoSchema() throws LdapException
+    {
+        String errors = null;
+        
+        Rdn rdn = new Rdn( "OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST" );
+        
+        if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.getName() ) )
+        {
+            errors += "\nRdn.getName fails '" + rdn.getName() + "'";
+        }
+        
+        if ( !"ou=Exemple \\+ Rdn\\C3\\A4\\ +cn=TEST" .equals( rdn.getNormName() ) )
+        {
+            errors = "\nRdn.getNormName fails '" + rdn.getNormName() + "'";
+        }
+        
+        if ( !"ou".equals( rdn.getNormType() ) )
+        {
+            errors += "\nRdn.getNormType fails '" + rdn.getNormType() + "'";
+        }
+        
+        if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getNormValue().getString() ) )
+        {
+            errors += "\nRdn.getNormValue fails '" + rdn.getNormValue().getString() + "'";
+        }
+        
+        if ( !"OU".equals( rdn.getType() ) )
+        {
+            errors += "\nRdn.getUpType fails '" + rdn.getType() + "'";
+        }
+        
+        if ( !"Exemple + Rdn\u00E4".equals( rdn.getValue().getString() ) )
+        {
+            errors += "\nRdn.getUpValue fails '" + rdn.getValue() + "'";
+        }
+        
+        if ( !"Exemple + Rdn\u00E4 ".equals( rdn.getValue( "ou" ) ) )
+        {
+            errors += "\nRdn.getValue( 'ou' ) fails '" + rdn.getValue( "ou" ) + "'";
+        }
+        
+        if ( !"TEST".equals( rdn.getValue( "cn" ) ) )
+        {
+            errors += "\nRdn.getValue( 'test' ) fails '" + rdn.getValue( "cn" ) + "'";
+        }
+        
+        if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.toString() ) )
+        {
+            errors += "\nRdn.toString fails '" + rdn.toString() + "'";
+        }
+        
+        assertEquals( null, errors );
+    }
+    
+    
+    @Test
+    public void testRdnValuesSchemaAware() throws LdapException
+    {
+        String errors = null;
+        
+        Rdn rdn = new Rdn( schemaManager, "OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST" );
+        
+        if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.getName() ) )
+        {
+            errors += "\nRdn.getName fails '" + rdn.getName() + "'";
+        }
+        
+        if ( !"2.5.4.11=exemple \\+ rdn\\C3\\A4+2.5.4.3=test" .equals( rdn.getNormName() ) )
+        {
+            errors = "\nRdn.getNormName fails '" + rdn.getNormName() + "'";
+        }
+        
+        if ( !"2.5.4.11".equals( rdn.getNormType() ) )
+        {
+            errors += "\nRdn.getNormType fails '" + rdn.getNormType() + "'";
+        }
+        
+        if ( !"exemple + rdn\u00E4".equals( rdn.getNormValue().getString() ) )
+        {
+            errors += "\nRdn.getNormValue fails '" + rdn.getNormValue().getString() + "'";
+        }
+        
+        if ( !"OU".equals( rdn.getType() ) )
+        {
+            errors += "\nRdn.getUpType fails '" + rdn.getType() + "'";
+        }
+        
+        if ( !"Exemple + Rdn\u00E4".equals( rdn.getValue().getString() ) )
+        {
+            errors += "\nRdn.getUpValue fails '" + rdn.getValue().getString() + "'";
+        }
+        
+        if ( !"exemple + rdn\u00E4".equals( rdn.getValue( "ou" ) ) )
+        {
+            errors += "\nRdn.getValue( 'ou' ) fails '" + (String)rdn.getValue( "ou" ) + "'";
+        }
+        
+        if ( !"test".equals( rdn.getValue( "cn" ) ) )
+        {
+            errors += "\nRdn.getValue( 'cn' ) fails '" + (String)rdn.getValue( "cn" ) + "'";
+        }
+        
+        if ( !"OU = Exemple \\+ Rdn\\C3\\A4\\ +cn= TEST".equals( rdn.toString() ) )
+        {
+            errors += "\nRdn.toString fails '" + rdn.toString() + "'";
+        }
+        
+        assertEquals( null, errors );
+    }
+    
+    
+    @Test
+    public void testRdnMultipleAvas() throws Exception
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=doe+gn=john" );
+        Rdn rdn2 = new Rdn( schemaManager, "gn=john+cn=doe" );
+        
+        assertEquals( rdn1, rdn2 );
+        assertEquals( rdn1.getNormName(), rdn2.getNormName() );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/RdnTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareAvaSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareAvaSerializationTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareAvaSerializationTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareAvaSerializationTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,286 @@
+/*
+ *  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.api.ldap.model.name;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Ava;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the class AttributeTypeAndValue
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareAvaSerializationTest
+{
+
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testStringAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testBinaryAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        byte[] normValue = Strings.getBytesUtf8( "Test" );
+
+        Ava atav = new Ava( schemaManager, "userPKCS12", normValue );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testNullAtavSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test
+    public void testNullUpValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "dc", ( String ) null );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            String message = ioe.getMessage();
+            assertEquals( "Cannot serialize an wrong ATAV, the upValue should not be null", message );
+        }
+    }
+
+
+    @Test
+    public void testEmptyNormValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "DC", "" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test serialization of a simple ATAV
+     */
+    @Test
+    public void testStringAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    @Test
+    public void testBinaryAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        byte[] upValue = Strings.getBytesUtf8( "  Test  " );
+
+        Ava atav = new Ava( schemaManager, "userPKCS12", upValue );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+
+
+    /**
+     * Test static serialization of a simple ATAV
+     */
+    @Test
+    public void testNullAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        try
+        {
+            atav.writeExternal( out );
+            fail();
+        }
+        catch ( IOException ioe )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test(expected = IOException.class)
+    public void testNullNormValueStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "DC", ( String ) null );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+        fail();
+    }
+
+
+    @Test
+    public void testEmptyNormValueStaticSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Ava atav = new Ava( schemaManager, "DC", ( String ) "" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        atav.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Ava atav2 = new Ava( schemaManager );
+        atav2.readExternal( in );
+
+        assertEquals( atav, atav2 );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareAvaSerializationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareDnSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareDnSerializationTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareDnSerializationTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareDnSerializationTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,277 @@
+/*
+ *  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.api.ldap.model.name;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Dn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the Dn Serialization
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareDnSerializationTest
+{
+    private static SchemaManager schemaManager;
+
+
+    /**
+     * Initialize OIDs maps for normalization
+     */
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+
+    @Test
+    public void testDnFullSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager, "gn=john + cn=doe, dc=example, dc=com" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+    }
+
+
+    @Test
+    public void testDnEmptySerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+    }
+
+
+    @Test
+    public void testDnSimpleSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Dn dn1 = new Dn( schemaManager, "Cn = Doe" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn1, dn2 );
+        assertEquals( "Cn = Doe", dn2.getName() );
+        assertEquals( "2.5.4.3=doe", dn2.getNormName() );
+    }
+
+
+    /**
+     * Test the serialization of a Dn
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testNameSerialization() throws Exception
+    {
+        Dn dn = new Dn( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
+        dn.apply( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn.writeExternal( out );
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn, dn2 );
+    }
+
+
+    @Test
+    public void testSerializeEmptyDN() throws Exception
+    {
+        Dn dn = Dn.EMPTY_DN;
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn.writeExternal( out );
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn, dn2 );
+    }
+
+
+    /**
+     * Test the serialization of a Dn
+     *
+     * @throws Exception
+     */
+    @Test
+    public void testNameStaticSerialization() throws Exception
+    {
+        Dn dn = new Dn( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
+        dn.apply( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn.writeExternal( out );
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn, dn2 );
+    }
+
+
+    @Ignore
+    @Test
+    public void testSerializationPerfs() throws Exception
+    {
+        Dn dn = new Dn( "ou= Some   People   + dc=  And   Some anImAls,dc = eXample,dc= cOm" );
+        dn.apply( schemaManager );
+
+        long t0 = System.currentTimeMillis();
+
+        for ( int i = 0; i < 1000; i++ )
+        {
+            ByteArrayOutputStream baos = new ByteArrayOutputStream();
+            ObjectOutputStream out = new ObjectOutputStream( baos );
+
+            dn.writeExternal( out );
+
+            byte[] data = baos.toByteArray();
+            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+            Dn dn1 = new Dn( schemaManager );
+            dn1.readExternal( 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 );
+
+            dn.writeExternal( out );
+
+            byte[] data = baos.toByteArray();
+            ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+            Dn dn1 = new Dn( schemaManager );
+            dn1.readExternal( in );
+
+            dn.apply( schemaManager );
+        }
+
+        long t3 = System.currentTimeMillis();
+
+        System.out.println( "delta :" + ( t3 - t2 ) );
+
+        //assertEquals( dn, DnSerializer.deserialize( in ) );
+    }
+
+
+    @Test
+    public void testStaticSerializeEmptyDN() throws Exception
+    {
+        Dn dn = Dn.EMPTY_DN;
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        dn.writeExternal( out );
+
+        byte[] data = baos.toByteArray();
+        ObjectInputStream in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Dn dn2 = new Dn( schemaManager );
+        dn2.readExternal( in );
+
+        assertEquals( dn, dn2 );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareDnSerializationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnSerializationTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnSerializationTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnSerializationTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnSerializationTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,131 @@
+/*
+ *  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.api.ldap.model.name;
+
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Rdn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the Rdn Serialization
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareRdnSerializationTest
+{
+    private static SchemaManager schemaManager;
+
+
+    /**
+     * Initialize OIDs maps for normalization
+     */
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+
+    @Test
+    public void testRdnFullSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "gn=john + cn=doe" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+    }
+
+
+    @Test
+    public void testRdnEmptySerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+    }
+
+
+    @Test
+    public void testRdnSimpleSerialization() throws IOException, LdapException, ClassNotFoundException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=Doe" );
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn1.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn1, rdn2 );
+        assertEquals( "doe", rdn2.getValue( "cn" ) );
+        assertEquals( "Doe", rdn2.getValue().getString() );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnSerializationTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,1225 @@
+/*
+ *  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.api.ldap.model.name;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.util.Iterator;
+
+import org.apache.directory.api.ldap.model.exception.LdapException;
+import org.apache.directory.api.ldap.model.name.Ava;
+import org.apache.directory.api.ldap.model.name.Rdn;
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.api.util.Strings;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test the Schema aware Rdn class
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class SchemaAwareRdnTest
+{
+    /** A null schemaManager used in tests */
+    private static SchemaManager schemaManager;
+
+
+    @BeforeClass
+    public static void setup() throws Exception
+    {
+        schemaManager = new DefaultSchemaManager();
+    }
+
+
+    /**
+     * Test a null Rdn
+     */
+    @Test
+    public void testRdnNull()
+    {
+        assertEquals( "", new Rdn( schemaManager ).toString() );
+    }
+
+
+    /**
+     * test an empty Rdn
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnEmpty() throws LdapException
+    {
+        assertEquals( "", new Rdn( schemaManager, "" ).toString() );
+    }
+
+
+    /**
+     * test a simple Rdn : cn = b
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnSimple() throws LdapException
+    {
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn = b" ).getNormName() );
+    }
+
+
+    /**
+     * test a composite Rdn : cn = b, sn = e
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnComposite() throws LdapException
+    {
+        assertEquals( "2.5.4.3=b+2.5.4.4=d", new Rdn( schemaManager, "cn = b + sn = d" ).getNormName() );
+    }
+
+
+    /**
+     * test a composite Rdn with or without spaces: cn=b, cn =b, cn= b, cn = b, cn =
+     * b
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnCompositeWithSpace() throws LdapException
+    {
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn=b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn=b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn =b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn= b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn=b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn =b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn= b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn=b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn = b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn =b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn= b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn = b" ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn =b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn= b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, "cn = b " ).getNormName() );
+        assertEquals( "2.5.4.3=b", new Rdn( schemaManager, " cn = b " ).getNormName() );
+    }
+
+
+    /**
+     * test a simple Rdn with differents separators : cn = b + sn = d
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnSimpleMultivaluedAttribute() throws LdapException
+    {
+        String result = new Rdn( schemaManager, "cn = b + sn = d" ).getNormName();
+        assertEquals( "2.5.4.3=b+2.5.4.4=d", result );
+    }
+
+
+    /**
+     * test a composite Rdn with differents separators : cn=b+sn=d, gn=f + l=h +
+     * c=j
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnCompositeMultivaluedAttribute() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn =b+sn=d + gn=f + l  =h + c =j " );
+
+        // NameComponent are not ordered
+        assertEquals( "b", rdn.getValue( "CommonName" ) );
+        assertEquals( "d", rdn.getValue( "2.5.4.4" ) );
+        assertEquals( "f", rdn.getValue( "  gn  " ) );
+        assertEquals( "h", rdn.getValue( "L" ) );
+        assertEquals( "j", rdn.getValue( "c" ) );
+    }
+
+
+    /**
+     * test a simple Rdn with an oid prefix (uppercase) : OID.2.5.4.3 = azerty
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnOidUpper() throws LdapException
+    {
+        assertEquals( "2.5.4.3=azerty", new Rdn( schemaManager, "OID.2.5.4.3 =  azerty" ).getNormName() );
+    }
+
+
+    /**
+     * test a simple Rdn with an oid prefix (lowercase) : oid.12.34.56 = azerty
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnOidLower() throws LdapException
+    {
+        assertEquals( "2.5.4.3=azerty", new Rdn( schemaManager, "oid.2.5.4.3 = azerty" ).getNormName() );
+    }
+
+
+    /**
+     * test a simple Rdn with an oid attribut wiithout oid prefix : 2.5.4.3 =
+     * azerty
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnOidWithoutPrefix() throws LdapException
+    {
+        assertEquals( "2.5.4.3=azerty", new Rdn( schemaManager, "2.5.4.3 = azerty" ).getNormName() );
+    }
+
+
+    /**
+     * test a composite Rdn with an oid attribut wiithout oid prefix : 2.5.4.3 =
+     * azerty; 2.5.4.4 = test
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnCompositeOidWithoutPrefix() throws LdapException
+    {
+        String result = new Rdn( schemaManager, "2.5.4.3 = azerty + 2.5.4.4 = test" ).getNormName();
+        assertEquals( "2.5.4.3=azerty+2.5.4.4=test", result );
+    }
+
+
+    /**
+     * test a simple Rdn with pair char attribute value : l = \,\=\+\<\>\#\;\\\"\C3\A9"
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnPairCharAttributeValue() throws LdapException
+    {
+        String rdn = Strings.utf8ToString( new byte[]
+            { 'l', '=', '\\', ',', '\\', '=', '\\', '+', '\\', '<', '\\', '>', '#', '\\', ';', '\\', '\\', '\\', '"', '\\',
+                'C', '3', '\\', 'A', '9' } );
+        assertEquals( "2.5.4.7=\\,\\=\\+\\<\\>#\\;\\\\\\\"\\C3\\A9", new Rdn( schemaManager, rdn ).getNormName() );
+    }
+
+
+    /**
+     * test a simple Rdn with hexString attribute value : userCertificate = #0010A0AAFF
+     */
+    @Test
+    public void testRdnHexStringAttributeValue() throws LdapException
+    {
+        assertEquals( "2.5.4.36=#0010A0AAFF", new Rdn( schemaManager, "userCertificate = #0010A0AAFF" ).getNormName() );
+    }
+
+
+    /**
+     * test exception from illegal hexString attribute value : cn=#zz.
+     */
+    @Test
+    public void testBadRdnHexStringAttributeValue() throws LdapException
+    {
+        try
+        {
+            new Rdn( schemaManager, "cn=#zz" );
+            fail();
+        }
+        catch ( LdapException ine )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * test a simple Rdn with quoted attribute value : cn = "quoted \"value"
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRdnQuotedAttributeValue() throws LdapException
+    {
+        assertEquals( "2.5.4.3=quoted \\\"value", new Rdn( schemaManager, "cn = quoted \\\"value" ).getNormName() );
+    }
+
+
+    /**
+     * Test the clone method for a Rdn.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCloningOneNameComponent() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "CN", "B" );
+
+        Rdn rdnClone = rdn.clone();
+
+        rdn = new Rdn( schemaManager, "cn=d" );
+
+        assertEquals( "b", rdnClone.getValue( "Cn" ) );
+    }
+
+
+    /**
+     * Test the creation of a new Rdn
+     * 
+     * @throws org.apache.directory.api.ldap.model.exception.LdapException
+     */
+    @Test
+    public void testRDNCreation() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "CN", "  b  " );
+        assertEquals( "2.5.4.3=b", rdn.getNormName() );
+        assertEquals( "CN=  b  ", rdn.getName() );
+    }
+
+
+    /**
+     * Test the clone method for a Rdn.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCloningTwoNameComponent() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn = b + sn = bb" );
+
+        Rdn rdnClone = rdn.clone();
+
+        rdn.clear();
+        rdn = new Rdn( schemaManager, "l=d" );
+
+        assertEquals( "b", rdnClone.getValue( "2.5.4.3" ) );
+        assertEquals( "bb", rdnClone.getValue( "SN" ) );
+        assertEquals( "", rdnClone.getValue( "l" ) );
+    }
+
+
+    /**
+     * Test the equals method for a Rdn.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNull() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d + l = f + gn = h " );
+        Rdn rdn2 = null;
+        assertFalse( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NC to a single NC.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNCS2NC() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d + l = f + gn = h " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b " );
+        assertFalse( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a single NC to a composite NC.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNC2NCS() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " sn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + sn = d + l = f + gn = h " );
+
+        assertFalse( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NCS to a composite NCS in the same order.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSOrdered() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d + gn = f + l = h " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + sn = d + gn = f + l = h " );
+
+        assertTrue( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NCS to a composite NCS in a different order.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSUnordered() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + gn = f + l = h + sn = d " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + sn = d + gn = f + l = h " );
+
+        assertTrue( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a composite NCS to a different composite NCS.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNCS2NCSNotEquals() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = f + sn = h + l = d " );
+        Rdn rdn2 = new Rdn( schemaManager, " l = d + cn = h + sn = h " );
+
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+    }
+
+
+    /**
+     * Test for DIRSHARED-2.
+     * The first ATAV is equal, the second or following ATAV differs.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testCompareSecondAtav() throws LdapException
+    {
+        // the second ATAV differs
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + sn = y " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+
+        // the third ATAV differs
+        Rdn rdn3 = new Rdn( schemaManager, " cn = b + sn = d + l = f " );
+        Rdn rdn4 = new Rdn( schemaManager, " cn = b + sn = d + l = y " );
+        assertFalse( rdn3.equals( rdn4 ) );
+        assertFalse( rdn4.equals( rdn3 ) );
+
+        // the second ATAV differs in value only
+        Rdn rdn5 = new Rdn( schemaManager, " cn = b + sn = c " );
+        Rdn rdn6 = new Rdn( schemaManager, " cn = b + sn = y " );
+        assertFalse( rdn5.equals( rdn6 ) );
+        assertFalse( rdn6.equals( rdn5 ) );
+    }
+
+
+    /**
+     * Test for DIRSHARED-2.
+     * The compare operation should return a correct value (1 or -1)
+     * depending on the ATAVs, not on their position.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testCompareIndependentFromOrder() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d " );
+        Rdn rdn2 = new Rdn( schemaManager, " sn = d + cn = b " );
+        assertTrue( rdn1.equals( rdn2 ) );
+
+        rdn1 = new Rdn( schemaManager, " cn = b + sn = e " );
+        rdn2 = new Rdn( schemaManager, " sn = d + cn = b " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+
+        rdn1 = new Rdn( schemaManager, " cn = b + sn = d " );
+        rdn2 = new Rdn( schemaManager, " l = f + gn = h " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+    }
+
+
+    /**
+     * Test for DIRSHARED-3.
+     * Tests that equals() is invertable for single-valued RDNs.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testCompareInvertableNC2NC() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = c " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+
+    }
+
+
+    /**
+     * Test for DIRSHARED-3.
+     * Tests that equals() is invertable for multi-valued RDNs with different values.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testCompareInvertableNCS2NCSDifferentValues() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = c " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + sn = y " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+    }
+
+
+    /**
+     * Test for DIRSHARED-3.
+     * Tests that equals() is invertable for multi-valued RDNs with different types.
+     * 
+     * @throws org.apache.directory.api.ldap.model.exception.LdapException
+     */
+    @Test
+    public void testCompareInvertableNCS2NCSDifferentTypes() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b + sn = d  " );
+        Rdn rdn2 = new Rdn( schemaManager, " l = f + gn = h " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+    }
+
+
+    /**
+     * Test for DIRSHARED-3.
+     * Tests that equals() is invertable for multi-valued RDNs with different order.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testCompareInvertableNCS2NCSUnordered() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " sn = d + cn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b + l = f " );
+        assertFalse( rdn1.equals( rdn2 ) );
+        assertFalse( rdn2.equals( rdn1 ) );
+    }
+
+
+    /**
+     * Compares with a null Rdn.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNullRdn() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b " );
+
+        assertFalse( rdn1.equals( null ) );
+    }
+
+
+    /**
+     * Compares a simple NC to a simple NC.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNC2NC() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " cn = b " );
+
+        assertTrue( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a simple NC to a simple NC in UperCase.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNC2NCUperCase() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " CN = b " );
+
+        assertTrue( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * Compares a simple NC to a different simple NC.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testRDNCompareToNC2NCNotEquals() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, " cn = b " );
+        Rdn rdn2 = new Rdn( schemaManager, " CN = d " );
+
+        assertFalse( rdn1.equals( rdn2 ) );
+    }
+
+
+    /**
+     * 
+     * Test the getValue method.
+     *
+     * @throws LdapException
+     */
+    @Test
+    public void testGetValue() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, " cn = b + sn = f + gn = h + l = d " );
+
+        assertEquals( "b", rdn.getNormValue().getString() );
+    }
+
+
+    /**
+     * 
+     * Test the getType method.
+     *
+     * @throws LdapException
+     */
+    @Test
+    public void testGetType() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, " cn = b + sn = f + gn = h + l = d " );
+
+        assertEquals( "2.5.4.3", rdn.getNormType() );
+    }
+
+
+    /**
+     * Test the getSize method.
+     *
+     * @throws LdapException
+     */
+    @Test
+    public void testGetSize() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, " cn = b + sn = f + gn = h + l = d " );
+
+        assertEquals( 4, rdn.size() );
+    }
+
+
+    /**
+     * Test the getSize method.
+     *
+     */
+    @Test
+    public void testGetSize0()
+    {
+        Rdn rdn = new Rdn( schemaManager );
+
+        assertEquals( 0, rdn.size() );
+    }
+
+
+    /**
+     * Test the equals method
+     *
+     * @throws LdapException
+     */
+    @Test
+    public void testEquals() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=b + sn=d + gn=f" );
+
+        assertFalse( rdn.equals( null ) );
+        assertFalse( rdn.equals( "test" ) );
+        assertFalse( rdn.equals( new Rdn( schemaManager, "cn=c + sn=d + gn=f" ) ) );
+        assertFalse( rdn.equals( new Rdn( schemaManager, "cn=b" ) ) );
+        assertTrue( rdn.equals( new Rdn( schemaManager, "cn=b + sn=d + gn=f" ) ) );
+        assertTrue( rdn.equals( new Rdn( schemaManager, "cn=b + SN=d + GN=f" ) ) );
+        assertTrue( rdn.equals( new Rdn( schemaManager, "sn=d + gn=f + CN=b" ) ) );
+    }
+
+
+    @Test
+    public void testUnescapeValueHexa()
+    {
+        byte[] res = ( byte[] ) Rdn.unescapeValue( "#fF" );
+
+        assertEquals( "0xFF ", Strings.dumpBytes( res ) );
+
+        res = ( byte[] ) Rdn.unescapeValue( "#0123456789aBCDEF" );
+        assertEquals( "0x01 0x23 0x45 0x67 0x89 0xAB 0xCD 0xEF ", Strings.dumpBytes( res ) );
+    }
+
+
+    @Test
+    public void testUnescapeValueHexaWrong()
+    {
+        try
+        {
+            Rdn.unescapeValue( "#fF1" );
+            fail(); // Should not happen
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    @Test
+    public void testUnescapeValueString()
+    {
+        String res = ( String ) Rdn.unescapeValue( "azerty" );
+
+        assertEquals( "azerty", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringSpecial()
+    {
+        String res = ( String ) Rdn.unescapeValue( "\\\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ " );
+
+        assertEquals( "\\#,+;<>=\" ", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithSpaceInTheMiddle()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a b" );
+
+        assertEquals( "a b", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithSpaceInAtTheBeginning()
+    {
+        String res = ( String ) Rdn.unescapeValue( "\\ a b" );
+
+        assertEquals( " a b", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithSpaceInAtTheEnd()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a b\\ " );
+
+        assertEquals( "a b ", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithPoundInTheMiddle()
+    {
+        String res = ( String ) Rdn.unescapeValue( "a#b" );
+
+        assertEquals( "a#b", res );
+    }
+
+
+    @Test
+    public void testUnescapeValueStringWithPoundAtTheEnd()
+    {
+        String res = ( String ) Rdn.unescapeValue( "ab#" );
+
+        assertEquals( "ab#", res );
+    }
+
+
+    @Test
+    public void testEscapeValueString()
+    {
+        String res = Rdn.escapeValue( Strings.getBytesUtf8( "azerty" ) );
+
+        assertEquals( "azerty", res );
+    }
+
+
+    @Test
+    public void testEscapeValueStringSpecial()
+    {
+        String res = Rdn.escapeValue( Strings.getBytesUtf8( "\\#,+;<>=\" " ) );
+
+        assertEquals( "\\\\#\\,\\+\\;\\<\\>\\=\\\"\\ ", res );
+    }
+
+
+    @Test
+    public void testEscapeValueNumeric()
+    {
+        String res = Rdn.escapeValue( new byte[]
+            { '-', 0x00, '-', 0x1F, '-', 0x7F, '-' } );
+
+        assertEquals( "-\\00-\\1F-\\7F-", res );
+    }
+
+
+    @Test
+    public void testEscapeValueMix()
+    {
+        String res = Rdn.escapeValue( new byte[]
+            { '\\', 0x00, '-', '+', '#', 0x7F, '-' } );
+
+        assertEquals( "\\\\\\00-\\+#\\7F-", res );
+    }
+
+
+    @Test
+    public void testDIRSERVER_703() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=Kate Bush+sn=Bush" );
+        assertEquals( "cn=Kate Bush+sn=Bush", rdn.getName() );
+    }
+
+
+    @Test
+    public void testMultiValuedIterator() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=Kate Bush+sn=Bush" );
+        Iterator<Ava> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    @Test
+    public void testSingleValuedIterator() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=Kate Bush" );
+        Iterator<Ava> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertTrue( iterator.hasNext() );
+        assertNotNull( iterator.next() );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    @Test
+    public void testEmptyIterator()
+    {
+        Rdn rdn = new Rdn( schemaManager );
+        Iterator<Ava> iterator = rdn.iterator();
+        assertNotNull( iterator );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    @Test
+    public void testRdnWithSpaces() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=a\\ b\\ c" );
+        assertEquals( "2.5.4.3=a b c", rdn.getNormName() );
+    }
+
+
+    @Test
+    public void testEscapedSpaceInValue() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=a b c" );
+        Rdn rdn2 = new Rdn( schemaManager, "cn=a\\ b\\ c" );
+        assertEquals( "2.5.4.3=a b c", rdn1.getNormName() );
+        assertEquals( "2.5.4.3=a b c", rdn2.getNormName() );
+        assertTrue( rdn1.equals( rdn2 ) );
+
+        Rdn rdn3 = new Rdn( schemaManager, "cn=\\ a b c\\ " );
+        Rdn rdn4 = new Rdn( schemaManager, "cn=\\ a\\ b\\ c\\ " );
+        assertEquals( "2.5.4.3=a b c", rdn3.getNormName() );
+        assertEquals( "cn=\\ a b c\\ ", rdn3.getName() );
+        assertEquals( "2.5.4.3=a b c", rdn4.getNormName() );
+        assertEquals( "cn=\\ a\\ b\\ c\\ ", rdn4.getName() );
+        assertTrue( rdn3.equals( rdn4 ) );
+    }
+
+
+    @Test
+    public void testEscapedHashInValue() throws LdapException
+    {
+        Rdn rdn1 = new Rdn( schemaManager, "cn=a#b#c" );
+        Rdn rdn2 = new Rdn( schemaManager, "cn=a\\#b\\#c" );
+        assertEquals( "2.5.4.3=a#b#c", rdn1.getNormName() );
+        assertEquals( "2.5.4.3=a#b#c", rdn2.getNormName() );
+        assertTrue( rdn1.equals( rdn2 ) );
+
+        Rdn rdn3 = new Rdn( schemaManager, "cn=\\#a#b#c\\#" );
+        Rdn rdn4 = new Rdn( schemaManager, "cn=\\#a\\#b\\#c\\#" );
+        assertEquals( "2.5.4.3=\\#a#b#c#", rdn3.getNormName() );
+        assertEquals( "2.5.4.3=\\#a#b#c#", rdn4.getNormName() );
+        assertTrue( rdn3.equals( rdn4 ) );
+    }
+
+
+    @Test
+    public void testEscapedAttributeValue()
+    {
+        // space doesn't need to be escaped in the middle of a string
+        assertEquals( "a b", Rdn.escapeValue( "a b" ) );
+        assertEquals( "a b c", Rdn.escapeValue( "a b c" ) );
+        assertEquals( "a b c d", Rdn.escapeValue( "a b c d" ) );
+
+        // space must be escaped at the beginning and the end of a string
+        assertEquals( "\\ a b", Rdn.escapeValue( " a b" ) );
+        assertEquals( "a b\\ ", Rdn.escapeValue( "a b " ) );
+        assertEquals( "\\ a b\\ ", Rdn.escapeValue( " a b " ) );
+        assertEquals( "\\  a  b \\ ", Rdn.escapeValue( "  a  b  " ) );
+
+        // hash doesn't need to be escaped in the middle and the end of a string
+        assertEquals( "a#b", Rdn.escapeValue( "a#b" ) );
+        assertEquals( "a#b#", Rdn.escapeValue( "a#b#" ) );
+        assertEquals( "a#b#c", Rdn.escapeValue( "a#b#c" ) );
+        assertEquals( "a#b#c#", Rdn.escapeValue( "a#b#c#" ) );
+        assertEquals( "a#b#c#d", Rdn.escapeValue( "a#b#c#d" ) );
+        assertEquals( "a#b#c#d#", Rdn.escapeValue( "a#b#c#d#" ) );
+
+        // hash must be escaped at the beginning of a string
+        assertEquals( "\\#a#b", Rdn.escapeValue( "#a#b" ) );
+        assertEquals( "\\##a#b", Rdn.escapeValue( "##a#b" ) );
+    }
+
+
+    /** Serialization tests ------------------------------------------------- */
+
+    /**
+     * Test serialization of an empty Rdn
+     */
+    @Test
+    public void testEmptyRDNSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, "" );
+
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        out.writeObject( rdn );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = ( Rdn ) in.readObject();
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    @Test
+    public void testNullRdnSerialization() throws IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager );
+
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        out.writeObject( rdn );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = ( Rdn ) in.readObject();
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn
+     */
+    @Test
+    public void testSimpleRdnSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, "cn=b" );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn
+     */
+    @Test
+    public void testSimpleRdn2Serialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN  = DEF " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with no value
+     */
+    @Test
+    public void testSimpleRdnNoValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN  =" );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with one value
+     */
+    @Test
+    public void testSimpleRdnOneValueSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN  = def " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with three values
+     */
+    @Test
+    public void testSimpleRdnThreeValuesSerialization() throws LdapException, IOException, ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN = a + SN = b + GN = c " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * Test serialization of a simple Rdn with three unordered values
+     */
+    @Test
+    public void testSimpleRdnThreeValuesUnorderedSerialization() throws LdapException, IOException,
+        ClassNotFoundException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN = b + SN = a + GN = c " );
+        rdn.normalize();
+
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+
+        rdn.writeExternal( out );
+
+        ObjectInputStream in = null;
+
+        byte[] data = baos.toByteArray();
+        in = new ObjectInputStream( new ByteArrayInputStream( data ) );
+
+        Rdn rdn2 = new Rdn( schemaManager );
+        rdn2.readExternal( in );
+
+        assertEquals( rdn, rdn2 );
+    }
+
+
+    /**
+     * test an Rdn with empty value
+     */
+    @Test
+    public void testRdnWithEmptyValue() throws LdapException
+    {
+        assertTrue( Rdn.isValid( "cn=" ) );
+        assertTrue( Rdn.isValid( "cn=\"\"" ) );
+        assertEquals( "2.5.4.3=", new Rdn( schemaManager, "cn=\"\"" ).getNormName() );
+        assertEquals( "2.5.4.3=", new Rdn( schemaManager, "cn=" ).getNormName() );
+    }
+
+
+    /**
+     * test an Rdn with escaped comma
+     */
+    @Test
+    public void testRdnWithEscapedComa() throws LdapException
+    {
+        assertTrue( Rdn.isValid( "cn=b\\,c" ) );
+        assertEquals( "2.5.4.3=b\\,c", new Rdn( schemaManager, "cn=b\\,c" ).getNormName() );
+
+        assertTrue( Rdn.isValid( "cn=\"b,c\"" ) );
+        assertEquals( "2.5.4.3=b\\,c", new Rdn( schemaManager, "cn=\"b,c\"" ).getNormName() );
+        assertEquals( "cn=\"b,c\"", new Rdn( schemaManager, "cn=\"b,c\"" ).getName() );
+
+        assertTrue( Rdn.isValid( "cn=\"b\\,c\"" ) );
+        Rdn rdn = new Rdn( schemaManager, "cn=\"b\\,c\"" );
+        assertEquals( "cn=\"b\\,c\"", rdn.getName() );
+        assertEquals( "2.5.4.3=b\\,c", rdn.getNormName() );
+    }
+
+
+    /**
+     * Tests the equals and equals results of cloned multi-valued RDNs.
+     * Test for DIRSHARED-9.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testComparingOfClonedMultiValuedRDNs() throws LdapException
+    {
+        // Use upper case attribute types to test if normalized types are used
+        // for comparison
+        Rdn rdn = new Rdn( schemaManager, " CN = b + SN = d" );
+        Rdn clonedRdn = rdn.clone();
+
+        assertTrue( rdn.equals( clonedRdn ) );
+    }
+
+
+    /**
+     * Tests the equals and equals results of copy constructed multi-valued RDNs.
+     * Test for DIRSHARED-9.
+     * 
+     * @throws LdapException
+     */
+    @Test
+    public void testComparingOfCopyConstructedMultiValuedRDNs() throws LdapException
+    {
+        // Use upper case attribute types to test if normalized types are used
+        // for comparison
+        Rdn rdn = new Rdn( schemaManager, " CN = b + SN = d" );
+        Rdn copiedRdn = new Rdn( rdn );
+
+        assertTrue( rdn.equals( copiedRdn ) );
+    }
+
+
+    /**
+     * test the UpName method on a Rdn with more than one atav
+     */
+    @Test
+    public void testGetUpNameMultipleAtav() throws LdapException
+    {
+        Rdn rdn = new Rdn( schemaManager, " CN = b + SN = d " );
+
+        assertEquals( " CN = b + SN = d ", rdn.getName() );
+    }
+
+
+    @Test
+    public void testSchemaAware() throws LdapException
+    {
+        Rdn rdn = new Rdn( "cn=John" );
+
+        assertFalse( rdn.isSchemaAware() );
+
+        rdn.apply( schemaManager );
+
+        assertTrue( rdn.isSchemaAware() );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/model/name/SchemaAwareRdnTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/schema/syntaxCheckers/ACIItemSyntaxCheckerTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/schema/syntaxCheckers/ACIItemSyntaxCheckerTest.java?rev=1423968&view=auto
==============================================================================
--- directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/schema/syntaxCheckers/ACIItemSyntaxCheckerTest.java (added)
+++ directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/schema/syntaxCheckers/ACIItemSyntaxCheckerTest.java Wed Dec 19 17:24:08 2012
@@ -0,0 +1,295 @@
+/*
+ *  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.api.ldap.schema.syntaxCheckers;
+
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.directory.api.ldap.model.schema.SchemaManager;
+import org.apache.directory.shared.ldap.aci.ACIItemSyntaxChecker;
+import org.apache.directory.shared.ldap.schemaloader.JarLdifSchemaLoader;
+import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import com.mycila.junit.concurrent.Concurrency;
+import com.mycila.junit.concurrent.ConcurrentJunitRunner;
+
+
+/**
+ * Test cases for ACIItemSyntaxChecker.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+@RunWith(ConcurrentJunitRunner.class)
+@Concurrency()
+public class ACIItemSyntaxCheckerTest
+{
+    private static ACIItemSyntaxChecker checker;
+
+
+    @BeforeClass
+    public static void init() throws Exception
+    {
+        JarLdifSchemaLoader loader = new JarLdifSchemaLoader();
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+        schemaManager.loadAllEnabled();
+        checker = new org.apache.directory.shared.ldap.aci.ACIItemSyntaxChecker();
+        checker.setSchemaManager( schemaManager );
+    }
+
+
+    @Test
+    public void testNullString()
+    {
+        assertFalse( checker.isValidSyntax( null ) );
+    }
+
+
+    @Test
+    public void testEmptyString()
+    {
+        assertFalse( checker.isValidSyntax( "" ) );
+    }
+
+
+    @Test
+    public void testOid()
+    {
+        assertEquals( "1.3.6.1.4.1.1466.115.121.1.1", checker.getOid() );
+    }
+
+
+    @Test
+    public void testCorrectCase()
+    {
+    }
+
+
+    /**
+     * Tests the checker with an ACIItem of ItemFirst main component.
+     */
+    @Test
+    public void testItemFirst()
+    {
+        String spec = " {  identificationTag  \"id1\" , precedence 114  , authenticationLevel simple  , "
+            + "itemOrUserFirst itemFirst  :{ protectedItems  { entry  , attributeType { 1.2.3    , ou }  , "
+            + " attributeValue { ou=people  , cn=Ersin  }  , rangeOfValues (cn=ErsinEr) , "
+            + "classes and : { item: xyz , or:{item:X,item:Y}   }}  , "
+            + "itemPermissions { { userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } },"
+            + "{ precedence 10, userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } } } }}";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    /**
+     * Tests the checker with an ACIItem of UserFirst main component.
+     */
+    @Test
+    public void testUserFirst()
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {cn=y,sn=n,dc=l} , "
+            + "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } } }  }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testAllowAddAllUsers()
+    {
+        String spec = "{ identificationTag \"addAci\", " + "precedence 14, " + "authenticationLevel none, "
+            + "itemOrUserFirst userFirst: { " + "userClasses { allUsers }, "
+            + "userPermissions { { protectedItems {entry}, " + "grantsAndDenials { grantAdd } } } } }";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testCombo()
+    {
+        String spec = "{ identificationTag \"addAci\", " + "precedence 14, " + "authenticationLevel none, "
+            + "itemOrUserFirst userFirst: { " + "userClasses { allUsers, name { \"ou=blah\" } }, "
+            + "userPermissions { { protectedItems {entry}, " + "grantsAndDenials { grantAdd } } } } }";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testOrderOfProtectedItemsDoesNotMatter()
+    {
+        String spec = " {  identificationTag  \"id1\" , precedence 114  , authenticationLevel simple  , "
+            + "itemOrUserFirst itemFirst  :{ protectedItems  { attributeType { 1.2.3    , ou }, entry , "
+            + " rangeOfValues (cn=ErsinEr) , attributeValue { ou=people  , cn=Ersin  },"
+            + "classes and : { item: xyz , or:{item:X,item:Y}   }}  , "
+            + "itemPermissions { { userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } },"
+            + "{ precedence 10, userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } } } }}";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testOrderOfUserClassesDoesNotMatter()
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userClasses {  name { \"ou=people,cn=ersin\" }, allUsers, "
+            + "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {cn=y,sn=n,dc=l} , "
+            + "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } } }  }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testItemPermissionComponentsOrderDoesNotMatter()
+    {
+        String spec = " {  identificationTag  \"id1\" , precedence 114  , authenticationLevel simple  , "
+            + "itemOrUserFirst itemFirst  :{ protectedItems  { attributeType { 1.2.3    , ou }, entry , "
+            + " rangeOfValues (cn=ErsinEr) , attributeValue { ou=people  , cn=Ersin  },"
+            + "classes and : { item: xyz , or:{item:X,item:Y}   }}  , "
+            + "itemPermissions { { grantsAndDenials  {  denyCompare  , grantModify }, userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   },"
+            + "{ precedence 10, userClasses {allUsers  , userGroup { \"2.5.4.3=y,dc=t\"  , \"cn=b,dc=d\" } "
+            + " , subtree { { base \"ou=people\" } } }   , grantsAndDenials  {  denyCompare  , grantModify } } } }}";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testUserPermissionComponentsOrderDoesNotMatter()
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { grantsAndDenials { grantBrowse }, protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {cn=y,sn=n,dc=l} , "
+            + "rangeOfValues (cn=ErsinEr) }  } } }  }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testOrderOfMainACIComponentsDoesNotMatter()
+    {
+        String spec = "{   itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue {cn=y,sn=n,dc=l} , "
+            + "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } } }, "
+            + " identificationTag \"id2\"   , authenticationLevel none, precedence 14 }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testRestrictedValueComponentsOrderDoesNotMatter()
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ base \"ou=system\"}, { base \"ou=ORGANIZATIONUNIT\"," + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { protectedItems{ entry  , "
+            + "maxValueCount { { type 10.11.12, maxCount 10 }, { maxCount 20, type 11.12.13  } } "
+            + " }  , grantsAndDenials { grantBrowse } } } }  }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    @Test
+    public void testMaxValueCountComponentsOrderDoesNotMatter()
+    {
+        String spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\"," + "minimum  1, maximum   2 } } }  , "
+            + "userPermissions { { protectedItems{ entry  , "
+            + "restrictedBy { { type 10.11.12, valuesIn ou }, { valuesIn cn, type 11.12.13  } } "
+            + " }  , grantsAndDenials { grantBrowse } } } }  }   ";
+
+        assertTrue( checker.isValidSyntax( spec ) );
+    }
+
+
+    /**
+     * Test case for DIRSERVER-891
+     */
+    @Test
+    public void testInvalidAttributeValue()
+    {
+        String spec;
+
+        // no name-value-pair
+        spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue { must_be_a_name_value_pair } , "
+            + "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } }, userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ minimum 7, maximum 9, base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + " maximum   2, minimum  1 } } }  }  }   ";
+        assertFalse( checker.isValidSyntax( spec ) );
+
+        // no name-value-pair
+        spec = "{ identificationTag \"id2\"   , precedence 14, authenticationLevel none  , "
+            + "itemOrUserFirst userFirst:  { userPermissions { { protectedItems{ entry  , attributeType { cn  , ou }  , attributeValue { x=y,m=n,k=l,x } , "
+            + "rangeOfValues (cn=ErsinEr) }  , grantsAndDenials { grantBrowse } } }, userClasses {  allUsers  , name { \"ou=people,cn=ersin\" }, "
+            + "subtree {{ minimum 7, maximum 9, base \"ou=system\" }, { base \"ou=ORGANIZATIONUNIT\","
+            + " maximum   2, minimum  1 } } }  }  }   ";
+        assertFalse( checker.isValidSyntax( spec ) );
+    }
+
+
+    /**
+     * Test case for DIRSERVER-891
+     */
+    @Test
+    public void testIncomplete()
+    {
+        String spec;
+
+        spec = "{ }";
+        assertFalse( checker.isValidSyntax( spec ) );
+
+        spec = "{ identificationTag \"id2\" }";
+        assertFalse( checker.isValidSyntax( spec ) );
+
+        spec = "{ identificationTag \"id2\", precedence 14 } ";
+        assertFalse( checker.isValidSyntax( spec ) );
+
+        spec = "{ identificationTag \"id2\", precedence 14, authenticationLevel none } ";
+        assertFalse( checker.isValidSyntax( spec ) );
+    }
+}

Propchange: directory/shared/branches/shared-refact/integ/src/test/java/org/apache/directory/api/ldap/schema/syntaxCheckers/ACIItemSyntaxCheckerTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message