directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1074677 [2/2] - in /directory: apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/ apacheds/trunk/core-api/src/test/java/org/apache/directory/server/core/ apacheds/trunk/core-integ/src/main/java/org/apache/directory/ser...
Date Fri, 25 Feb 2011 19:36:04 GMT
Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/DnSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/DnSerializer.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/DnSerializer.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/DnSerializer.java
Fri Feb 25 19:36:02 2011
@@ -27,8 +27,8 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 
-import org.apache.directory.shared.i18n.I18n;
-import org.apache.directory.shared.util.Strings;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -112,22 +112,13 @@ public final class DnSerializer
         Unicode.writeUTF(out, dn.getName());
 
         // Write the NormName if different
-        if ( dn.isNormalized() )
+        if ( dn.getName().equals( dn.getNormName() ) )
         {
-            if ( dn.getName().equals( dn.getNormName() ) )
-            {
-                Unicode.writeUTF(out, "");
-            }
-            else
-            {
-                Unicode.writeUTF(out, dn.getNormName());
-            }
+            Unicode.writeUTF(out, "");
         }
         else
         {
-            String message = I18n.err( I18n.ERR_04212, dn );
-            LOG.error( message );
-            throw new IOException( message );
+            Unicode.writeUTF(out, dn.getNormName());
         }
 
         // Should we store the byte[] ???
@@ -155,12 +146,13 @@ public final class DnSerializer
      * @return a deserialized Dn
      * @throws IOException If the stream can't be read
      */
-    public static Dn deserialize( byte[] bytes ) throws IOException
+    public static Dn deserialize( SchemaManager schemaManager, byte[] bytes ) 
+        throws IOException, LdapInvalidDnException
     {
         ByteArrayInputStream bais = new ByteArrayInputStream( bytes );
         ObjectInputStream in = new ObjectInputStream( bais );
     
-        return deserialize( in );
+        return deserialize( schemaManager, in );
     }
     
 
@@ -171,11 +163,13 @@ public final class DnSerializer
      * read is exposed in the {@link DnSerializer#serialize(Dn, ObjectOutput)}
      * method<p>
      *
+     * @param schemaManager The SchemaManager (can be null)
      * @param in The input stream from which the Dn is read
      * @return a deserialized Dn
      * @throws IOException If the stream can't be read
      */
-    public static Dn deserialize( ObjectInput in ) throws IOException
+    public static Dn deserialize( SchemaManager schemaManager, ObjectInput in ) 
+        throws IOException, LdapInvalidDnException
     {
         // Read the UPName
         String upName = Unicode.readUTF(in);
@@ -191,19 +185,19 @@ public final class DnSerializer
             normName = upName;
         }
 
-        // Should we read the byte[] ???
-        byte[] bytes = Strings.getBytesUtf8(upName);
-
         // Read the RDNs. Is it's null, the number will be -1.
         int nbRdns = in.readInt();
-        Dn dn = new Dn( upName, normName, bytes );
-
+        
+        Rdn[] rdns = new Rdn[nbRdns];
+        
         for ( int i = 0; i < nbRdns; i++ )
         {
-            Rdn rdn = RdnSerializer.deserialize( in );
-            dn = dn.addInternal( 0, rdn );
+            Rdn rdn = RdnSerializer.deserialize( schemaManager, in );
+            rdns[i] = rdn;
         }
 
+        Dn dn = new Dn( schemaManager, upName, normName, rdns );
+        
         return dn;
     }
 }

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/FastDnParser.java
Fri Feb 25 19:36:02 2011
@@ -179,7 +179,7 @@ public enum FastDnParser
 
         Ava ava = new Ava( type, type, new StringValue( upValue ),
             new StringValue( value ), upName );
-        rdn.addAVA( ava );
+        rdn.addAVA( null, ava );
 
         rdn.setUpName( upName );
         rdn.normalize();

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/Rdn.java
Fri Feb 25 19:36:02 2011
@@ -25,6 +25,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -284,7 +285,7 @@ public final class Rdn implements Clonea
     {
         this.schemaManager = schemaManager;
 
-        addAVA( upType, normType, new StringValue( upValue ), new StringValue( normValue
) );
+        addAVA( schemaManager, upType, normType, new StringValue( upValue ), new StringValue(
normValue ) );
 
         upName = upType + '=' + upValue;
 
@@ -332,7 +333,7 @@ public final class Rdn implements Clonea
      */
     public Rdn( SchemaManager schemaManager, String upType, String upValue ) throws LdapInvalidDnException
     {
-        addAVA( upType, upType, new StringValue( upValue ), new StringValue( upValue ) );
+        addAVA( schemaManager, upType, upType, new StringValue( upValue ), new StringValue(
upValue ) );
 
         upName = upType + '=' + upValue;
 
@@ -368,28 +369,12 @@ public final class Rdn implements Clonea
 
 
     /**
-     * A constructor that constructs a Rdn from a type, a position and a length.
-     *
-     * @param start the starting point for this Rdn in the user provided Dn
-     * @param length the Rdn's length
-     * @param upName the user provided name
-     * @param normName the normalized name
-     */
-    Rdn(int start, int length, String upName, String normName)
-    {
-        this.upName = upName;
-        this.normName = normName;
-        normalized = true;
-    }
-
-
-    /**
      * Constructs an Rdn from the given rdn. The contents of the rdn are simply
      * copied into the newly created
      *
      * @param rdn The non-null Rdn to be copied.
      */
-    public Rdn(Rdn rdn)
+    public Rdn( Rdn rdn )
     {
         nbAtavs = rdn.getNbAtavs();
         this.normName = rdn.normName;
@@ -505,6 +490,43 @@ public final class Rdn implements Clonea
             return this;
         }
     }
+    
+    
+    /* no qualifier */ Rdn( SchemaManager schemaManager, String upName, String normName,
Ava... atavs )
+    {
+        this.upName = upName;
+        this.normName = normName;
+        this.schemaManager = schemaManager;
+        this.normalized = (schemaManager != null );
+        
+        if ( atavs != null )
+        {
+            nbAtavs = atavs.length;
+            
+            switch ( nbAtavs )
+            {
+                case 0 :
+                    break;
+                    
+                case 1 :
+                    atav = atavs[ 0 ];
+                    atavTypes.put( atav.getUpType(), atav );
+                    atavTypes.put( atav.getNormType(), atav );
+                    break;
+                    
+                default :
+                    this.atavs = Arrays.asList( atavs );
+                    
+                    for ( Ava ava : atavs )
+                    {
+                        atavTypes.put( ava.getUpType(), ava );
+                        atavTypes.put( ava.getNormType(), ava );
+                    }
+                    
+                    break;
+            }
+        }
+    }
 
 
     /**
@@ -517,20 +539,19 @@ public final class Rdn implements Clonea
      * @throws LdapInvalidDnException
      *             If the Rdn is invalid
      */
-    // WARNING : The protection level is left unspecified intentionally.
-    // We need this method to be visible from the DnParser class, but not
-    // from outside this package.
-    /* Unspecified protection */void addAVA( String upType, String type, Value<?> upValue,
+    private void addAVA( SchemaManager schemaManager, String upType, String type, Value<?>
upValue,
         Value<?> value ) throws LdapInvalidDnException
     {
         // First, let's normalize the type
         Value<?> normalizedValue = value;
         String normalizedType = Strings.lowerCaseAscii(type);
+        this.schemaManager = schemaManager;
 
-        if( schemaManager != null )
+        if ( schemaManager != null )
         {
             OidNormalizer oidNormalizer = schemaManager.getNormalizerMapping().get( normalizedType
);
             normalizedType = oidNormalizer.getAttributeTypeOid();
+            
             try
             {
                 normalizedValue = oidNormalizer.getNormalizer().normalize( value );
@@ -545,7 +566,7 @@ public final class Rdn implements Clonea
         {
             case 0:
                 // This is the first AttributeTypeAndValue. Just stores it.
-                atav = new Ava( upType, normalizedType, upValue, normalizedValue );
+                atav = new Ava( schemaManager, upType, normalizedType, upValue, normalizedValue
);
                 nbAtavs = 1;
                 atavType = normalizedType;
                 return;
@@ -568,7 +589,7 @@ public final class Rdn implements Clonea
 
             default:
                 // add a new AttributeTypeAndValue
-                Ava newAtav = new Ava( upType, normalizedType, upValue, normalizedValue );
+                Ava newAtav = new Ava( schemaManager, upType, normalizedType, upValue, normalizedValue
);
                 atavs.add( newAtav );
                 atavTypes.put( normalizedType, newAtav );
 
@@ -587,8 +608,9 @@ public final class Rdn implements Clonea
     // WARNING : The protection level is left unspecified intentionally.
     // We need this method to be visible from the DnParser class, but not
     // from outside this package.
-    /* Unspecified protection */void addAVA( Ava value )
+    /* Unspecified protection */void addAVA( SchemaManager schemaManager, Ava value )
     {
+        this.schemaManager = schemaManager;
         String normalizedType = value.getNormType();
 
         switch ( nbAtavs )
@@ -623,7 +645,6 @@ public final class Rdn implements Clonea
 
                 nbAtavs++;
                 break;
-
         }
     }
 
@@ -1551,6 +1572,17 @@ public final class Rdn implements Clonea
                 break;
         }
     }
+    
+    
+    /**
+     * Get the associated SchemaManager if any.
+     * 
+     * @return The SchemaManager
+     */
+    public SchemaManager getSchemaManager()
+    {
+        return schemaManager;
+    }
 
 
     /**
@@ -1560,5 +1592,4 @@ public final class Rdn implements Clonea
     {
         return upName == null ? "" : upName;
     }
-
 }

Modified: directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/RdnSerializer.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/RdnSerializer.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/RdnSerializer.java
(original)
+++ directory/shared/trunk/ldap-model/src/main/java/org/apache/directory/shared/ldap/model/name/RdnSerializer.java
Fri Feb 25 19:36:02 2011
@@ -23,6 +23,8 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Strings;
 import org.apache.directory.shared.util.Unicode;
 import org.slf4j.Logger;
@@ -54,17 +56,15 @@ public final class RdnSerializer
      * We should write all those ATAVs sequencially, following the 
      * structure :
      * 
-     * <li>nbAtavs</li> The number of ATAVs to write. Can't be 0.
-     * <li>upName</li> The User provided Rdn
-     * <li>normName</li> The normalized Rdn. It can be empty if the normalized
-     * name equals the upName.
+     * <li>nbAtavs : The number of ATAVs to write. Can't be 0.</li>
+     * <li>upName< : The User provided Rdn</li>
+     * <li>normName : The normalized Rdn. It can be empty if the normalized
+     * name equals the upName.</li>
      * <li>atavs</li>
      * <p>
      * For each ATAV :<p>
-     * <li>start</li> The position of this ATAV in the upName string
-     * <li>length</li> The ATAV user provided length
-     * <li>Call the ATAV write method</li> The ATAV itself
-     *  
+     * <li>Call the ATAV write method :The ATAV itself</li>
+     * <br/>
      * @param rdn The Rdn to serialize
      * @param out the stream in which the Rdn will be serialized
      * @throws IOException If we can't write in this stream
@@ -94,15 +94,17 @@ public final class RdnSerializer
     /**
      * Deserialize a Rdn instance
      * 
-     * We read back the data to create a new RDB. The structure 
+     * We read back the data to create a new Rdn. The structure 
      * read is exposed in the {@link Rdn#writeExternal(ObjectOutput)}
      * method<p>
      * 
+     * @param schemaManager The SchemaManager (can be null)
      * @param in The input stream from which the Rdn is read
      * @return a deserialized Rdn
      * @throws IOException If the stream can't be read
      */
-    public static Rdn deserialize( ObjectInput in ) throws IOException
+    public static Rdn deserialize( SchemaManager schemaManager, ObjectInput in )
+        throws IOException, LdapInvalidDnException
     {
         // Read the ATAV number
         int nbAtavs = in.readInt();
@@ -118,30 +120,33 @@ public final class RdnSerializer
             normName = upName;
         }
         
-        // Now creates the Rdn
-        Rdn rdn = new Rdn( 0, 0, upName, normName );
+        Rdn rdn = null;
 
         // Read through the Atavs
         switch ( nbAtavs )
         {
             case 0 :
-                return rdn;
+                rdn = new Rdn( schemaManager, upName, normName, (Ava[])null );
+                break;
                 
             case 1 :
-                Ava atav = AvaSerializer.deserialize(in);
+                Ava ava = AvaSerializer.deserialize( schemaManager, in );
                 
-                rdn.addAVA( atav );
-
-                return rdn;
+                rdn = new Rdn( schemaManager, upName, normName, ava );
+                break;
                 
             default :
+                Ava[] avas = new Ava[nbAtavs];
+                
                 for ( int i = 0; i < nbAtavs; i++  )
                 {
-                    atav = AvaSerializer.deserialize(in);
-                    rdn.addAVA( atav );
+                    ava = AvaSerializer.deserialize( schemaManager, in );
+                    avas[i] = ava;
                 }
-            
-                return rdn;
+
+                rdn = new Rdn( schemaManager, upName, normName, avas );
         }
+
+        return rdn;
     }
 }

Modified: directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
(original)
+++ directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/AvaTest.java
Fri Feb 25 19:36:02 2011
@@ -32,6 +32,8 @@ import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -49,8 +51,9 @@ import com.mycila.junit.concurrent.Concu
 @Concurrency()
 public class AvaTest
 {
-    // ~ Methods
-    // ------------------------------------------------------------------------------------
+    /** A null schemaManager used in tests */
+    SchemaManager schemaManager = null;
+    
     /**
      * Test a null AttributeTypeAndValue
      */
@@ -71,7 +74,7 @@ public class AvaTest
     {
         try
         {
-            new Ava( null, null, (String)null, (String)null );
+            new Ava( schemaManager, null, (String)null );
             fail();
         }
         catch ( LdapException ine )
@@ -89,7 +92,7 @@ public class AvaTest
     {
         try
         {
-            new Ava( "  ", " ", (String)null, (String)null );
+            new Ava( schemaManager, "  ", (String)null );
             fail();
         }
         catch ( LdapException ine )
@@ -105,26 +108,25 @@ public class AvaTest
     @Test
     public void testAttributeTypeAndValueValidType() throws LdapException
     {
-        Ava atav = new Ava( "A", "a", (String)null, (String)null );
+        Ava atav = new Ava( schemaManager, "A", (String)null );
         assertEquals( "A=", atav.toString() );
         assertEquals( "a=", atav.getNormName() );
         assertEquals( "A=", atav.getUpName() );
         
-        atav = new Ava( "  A  ", "a", (String)null, (String)null );
+        atav = new Ava( schemaManager, "  A  ", (String)null );
         assertEquals( "a=", atav.getNormName() );
         assertEquals( "  A  =", atav.toString() );
         assertEquals( "  A  =", atav.getUpName() );
         
-        atav = new Ava( "  A  ", null, (String)null, (String)null );
-        assertEquals( "a=", atav.getNormName() );
-        assertEquals( "  A  =", atav.toString() );
-        assertEquals( "  A  =", atav.getUpName() );
-        
-        atav = new Ava( null, "a", (String)null, (String)null );
-        assertEquals( "a=", atav.getNormName() );
-        assertEquals( "a=", atav.toString() );
-        assertEquals( "a=", atav.getUpName() );
-        
+        try
+        {
+            atav = new Ava( schemaManager, null, (String)null );
+            fail();
+        }
+        catch ( LdapInvalidDnException lide )
+        {
+            assertTrue( true );
+        }
     }
 
     /**
@@ -135,7 +137,7 @@ public class AvaTest
     {
         try
         {
-            new Ava( "", "", "", "" );
+            new Ava( schemaManager, "", "" );
             fail( "Should not occurs ... " );
         }
         catch ( LdapException ine )
@@ -151,7 +153,7 @@ public class AvaTest
     @Test
     public void testLdapRDNSimple() throws LdapException
     {
-        Ava atav = new Ava( "a", "a", "b", "b" );
+        Ava atav = new Ava( schemaManager, "a", "b" );
         assertEquals( "a=b", atav.toString() );
         assertEquals( "a=b", atav.getUpName() );
     }
@@ -163,8 +165,8 @@ public class AvaTest
     @Test
     public void testCompareToEquals() throws LdapException
     {
-        Ava atav1 = new Ava( "a", "a","b", "b" );
-        Ava atav2 = new Ava( "a", "a","b", "b" );
+        Ava atav1 = new Ava( schemaManager, "a", "b" );
+        Ava atav2 = new Ava( schemaManager, "a", "b" );
 
         assertTrue( atav1.equals( atav2 ) );
     }
@@ -176,8 +178,8 @@ public class AvaTest
     @Test
     public void testCompareToEqualsCase() throws LdapException
     {
-        Ava atav1 = new Ava( "a", "a", "b", "b" );
-        Ava atav2 = new Ava( "A", "A", "b", "b" );
+        Ava atav1 = new Ava( schemaManager, "a", "b" );
+        Ava atav2 = new Ava( schemaManager, "A", "b" );
 
         assertTrue( atav1.equals( atav2 ) );
     }
@@ -190,9 +192,9 @@ public class AvaTest
     @Test
     public void testCompareAtav1TypeSuperior() throws LdapException
     {
-        Ava atav1 = new Ava( "b", "b", "b", "b" );
+        Ava atav1 = new Ava( schemaManager, "b", "b" );
             
-        Ava atav2 = new Ava( "a", "a", "b", "b" );
+        Ava atav2 = new Ava( schemaManager, "a", "b" );
 
         assertFalse( atav1.equals( atav2 ) );
     }
@@ -205,8 +207,8 @@ public class AvaTest
     @Test
     public void testCompareAtav2TypeSuperior() throws LdapException
     {
-        Ava atav1 = new Ava( "a", "a", "b", "b" );
-        Ava atav2 = new Ava( "b", "b", "b", "b" );
+        Ava atav1 = new Ava( schemaManager, "a", "b" );
+        Ava atav2 = new Ava( schemaManager, "b", "b" );
 
         assertFalse( atav1.equals( atav2 ) );
     }
@@ -219,8 +221,8 @@ public class AvaTest
     @Test
     public void testCompareAtav1ValueSuperior() throws LdapException
     {
-        Ava atav1 = new Ava( "a", "a", "b", "b" );
-        Ava atav2 = new Ava( "a", "a", "a", "a" );
+        Ava atav1 = new Ava( schemaManager, "a", "b" );
+        Ava atav2 = new Ava( schemaManager, "a", "a" );
 
         assertFalse( atav1.equals( atav2 ) );
     }
@@ -233,8 +235,8 @@ public class AvaTest
     @Test
     public void testCompareAtav2ValueSuperior() throws LdapException
     {
-        Ava atav1 = new Ava( "a", "a", "a", "a" );
-        Ava atav2 = new Ava( "a", "a", "b", "b" );
+        Ava atav1 = new Ava( schemaManager, "a", "a" );
+        Ava atav2 = new Ava( schemaManager, "a", "b" );
 
         assertFalse( atav1.equals( atav2 ) );
     }
@@ -243,7 +245,7 @@ public class AvaTest
     @Test
     public void testNormalize() throws LdapException
     {
-        Ava atav = new Ava( " A ", " A ", "a", "a" );
+        Ava atav = new Ava( schemaManager, " A ", "a" );
 
         assertEquals( "a=a", atav.normalize() );
 
@@ -258,7 +260,7 @@ public class AvaTest
     @Test
     public void testStringAtavSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "cn", "CN", "test", "Test" );
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
 
         atav.normalize();
 
@@ -282,9 +284,8 @@ public class AvaTest
     public void testBinaryAtavSerialization() throws LdapException, IOException, ClassNotFoundException
     {
         byte[] upValue = Strings.getBytesUtf8("  Test  ");
-        byte[] normValue = Strings.getBytesUtf8("Test");
 
-        Ava atav = new Ava( "cn", "CN", upValue, normValue );
+        Ava atav = new Ava( schemaManager, "CN", upValue );
 
         atav.normalize();
 
@@ -330,7 +331,7 @@ public class AvaTest
     @Test
     public void testNullNormValueSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", "test", (String)null );
+        Ava atav = new Ava( schemaManager, "CN", (String)null );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -343,7 +344,7 @@ public class AvaTest
         catch ( IOException ioe )
         {
             String message = ioe.getMessage();
-            assertEquals( "Cannot serialize an wrong ATAV, the value should not be null",
message );
+            assertEquals( "Cannot serialize an wrong ATAV, the upValue should not be null",
message );
         }
     }
 
@@ -351,7 +352,7 @@ public class AvaTest
     @Test
     public void testNullUpValueSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", null, "test" );
+        Ava atav = new Ava( schemaManager, "CN", (String)null );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -372,7 +373,7 @@ public class AvaTest
     @Test
     public void testEmptyNormValueSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", "test", "" );
+        Ava atav = new Ava( schemaManager, "CN", "test" );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -393,7 +394,7 @@ public class AvaTest
     @Test
     public void testEmptyUpValueSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", "", "test" );
+        Ava atav = new Ava( schemaManager, "CN", "" );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -417,7 +418,7 @@ public class AvaTest
     @Test
     public void testStringAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "cn", "CN", "test", "Test" );
+        Ava atav = new Ava( schemaManager, "CN", "Test" );
 
         atav.normalize();
 
@@ -432,7 +433,7 @@ public class AvaTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Ava atav2 = AvaSerializer.deserialize(in);
+        Ava atav2 = AvaSerializer.deserialize( schemaManager, in );
 
         assertEquals( atav, atav2 );
     }
@@ -442,9 +443,8 @@ public class AvaTest
     public void testBinaryAtavStaticSerialization() throws LdapException, IOException, ClassNotFoundException
     {
         byte[] upValue = Strings.getBytesUtf8("  Test  ");
-        byte[] normValue = Strings.getBytesUtf8("Test");
 
-        Ava atav = new Ava( "cn", "CN", upValue, normValue );
+        Ava atav = new Ava( schemaManager, "CN", upValue );
 
         atav.normalize();
 
@@ -459,7 +459,7 @@ public class AvaTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Ava atav2 = AvaSerializer.deserialize(in);
+        Ava atav2 = AvaSerializer.deserialize( schemaManager, in );
 
         assertEquals( atav, atav2 );
     }
@@ -489,30 +489,9 @@ public class AvaTest
 
 
     @Test
-    public void testNullNormValueStaticSerialization() throws LdapException, IOException,
ClassNotFoundException
-    {
-        Ava atav = new Ava( "CN", "cn", "test", (String)null );
-
-        ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        ObjectOutputStream out = new ObjectOutputStream( baos );
-
-        try
-        {
-            AvaSerializer.serialize(atav, out);
-            fail();
-        }
-        catch ( IOException ioe )
-        {
-            String message = ioe.getMessage();
-            assertEquals( "Cannot serialize an wrong ATAV, the value should not be null",
message );
-        }
-    }
-
-
-    @Test
     public void testNullUpValueStaticSerialization() throws LdapException, IOException, ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", null, "test" );
+        Ava atav = new Ava( schemaManager, "CN", (String)null );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -533,7 +512,7 @@ public class AvaTest
     @Test
     public void testEmptyNormValueStaticSerialization() throws LdapException, IOException,
ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", "test", "" );
+        Ava atav = new Ava( schemaManager, "CN", "" );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -546,7 +525,7 @@ public class AvaTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Ava atav2 = AvaSerializer.deserialize(in);
+        Ava atav2 = AvaSerializer.deserialize( schemaManager, in );
 
         assertEquals( atav, atav2 );
     }
@@ -555,7 +534,7 @@ public class AvaTest
     @Test
     public void testEmptyUpValueStaticSerialization() throws LdapException, IOException,
ClassNotFoundException
     {
-        Ava atav = new Ava( "CN", "cn", "", "test" );
+        Ava atav = new Ava( schemaManager, "CN", "" );
 
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         ObjectOutputStream out = new ObjectOutputStream( baos );
@@ -568,7 +547,7 @@ public class AvaTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Ava atav2 = AvaSerializer.deserialize(in);
+        Ava atav2 = AvaSerializer.deserialize( schemaManager, in );
 
         assertEquals( atav, atav2 );
     }

Modified: directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java?rev=1074677&r1=1074676&r2=1074677&view=diff
==============================================================================
--- directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
(original)
+++ directory/shared/trunk/ldap-model/src/test/java/org/apache/directory/shared/ldap/model/name/RdnTest.java
Fri Feb 25 19:36:02 2011
@@ -34,6 +34,8 @@ import java.io.ObjectOutputStream;
 import java.util.Iterator;
 
 import org.apache.directory.shared.ldap.model.exception.LdapException;
+import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -51,8 +53,9 @@ import com.mycila.junit.concurrent.Concu
 @Concurrency()
 public class RdnTest
 {
-    // ~ Methods
-    // ------------------------------------------------------------------------------------
+    /** A null schemaManager used in tests */
+    SchemaManager schemaManager = null;
+    
     /**
      * Test a null Rdn
      */
@@ -1149,14 +1152,14 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
 
 
     @Test
-    public void testNullRdnStaticSerialization() throws IOException, ClassNotFoundException
+    public void testNullRdnStaticSerialization() throws IOException, ClassNotFoundException,
LdapInvalidDnException
     {
         Rdn rdn = new Rdn();
 
@@ -1173,7 +1176,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1199,7 +1202,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1225,7 +1228,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1251,7 +1254,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1277,7 +1280,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1304,7 +1307,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }
@@ -1331,7 +1334,7 @@ public class RdnTest
         byte[] data = baos.toByteArray();
         in = new ObjectInputStream( new ByteArrayInputStream( data ) );
 
-        Rdn rdn2 = RdnSerializer.deserialize( in );
+        Rdn rdn2 = RdnSerializer.deserialize( schemaManager, in );
 
         assertEquals( rdn, rdn2 );
     }



Mime
View raw message