directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r581271 - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/common/ test/java/org/apache/directory/shared/ldap/common/
Date Tue, 02 Oct 2007 14:59:44 GMT
Author: elecharny
Date: Tue Oct  2 07:59:42 2007
New Revision: 581271

URL: http://svn.apache.org/viewvc?rev=581271&view=rev
Log:
- Removed warnings by adding <?> to Value
- Removed a warning using @SuppressWarnings unchecked
- Added some tests in ServerEntryTest
- Fixed some potential NPE is ServerAttributeImpl getClonedValue() method
- Fixed some bad code in ServerAttributeImpl.add() method : we were testing the value nullity,
not the content of the value nullity.

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AbstractValue.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttribute.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntry.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntryImpl.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/Value.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AbstractValue.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AbstractValue.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AbstractValue.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/AbstractValue.java
Tue Oct  2 07:59:42 2007
@@ -111,9 +111,9 @@
     /**
      * Normalize the value
      */
+    @SuppressWarnings(value = "unchecked")
     public void normalize( Normalizer normalizer ) throws NamingException
     {
-        //noinspection unchecked
         normValue = ( T ) normalizer.normalize( value );
     }
     
@@ -121,10 +121,10 @@
     /**
      * Clone the value.
      */
-    public Value clone() throws CloneNotSupportedException
+    public Value<?> clone() throws CloneNotSupportedException
     {
         // Simply clone the object
-        return ( Value ) super.clone();
+        return (Value<?>)super.clone();
     }
     
     

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttribute.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttribute.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttribute.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttribute.java
Tue Oct  2 07:59:42 2007
@@ -77,7 +77,7 @@
      * @param val a new value to be added which may be null
      * @return true if a value was added, otherwise false
      */
-    boolean add( Value val );
+    boolean add( Value<?> val );
     
     
     /**
@@ -124,7 +124,7 @@
      * 
      * @return a deep clone of this attribute
      */
-    Object clone();
+    ServerAttribute clone();
 
    
     /**
@@ -133,7 +133,7 @@
      * @param val the value which may be null
      * @return true if this attribute contains the value, otherwise false
      */
-    boolean contains( Value val );
+    boolean contains( Value<?> val );
     
 
     /**
@@ -166,7 +166,7 @@
      * @return a value of this attribute
      * @throws NamingException If the attribute has no value.
      */
-    Value get() throws NamingException;
+    Value<?> get() throws NamingException;
 
 
     /**
@@ -182,7 +182,7 @@
      * @return an enumeration of all values of the attribute
      * @throws NamingException If any <code>NamingException</code> occurs.
      */
-    Iterator<Value> getAll() throws NamingException;
+    Iterator<Value<?>> getAll() throws NamingException;
 
 
     /**
@@ -222,7 +222,7 @@
      * @param val the value to be removed
      * @return true if the value is removed, otherwise false
      */
-    boolean remove( Value val );
+    boolean remove( Value<?> val );
     
 
     /**

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerAttributeImpl.java
Tue Oct  2 07:59:42 2007
@@ -58,10 +58,10 @@
     private OID oid;
 
     /** In case we have only one value, just use this container */
-    private Value value;
+    private Value<?> value;
     
     /** the list of attribute values, if unordered */
-    private List<Value> values;
+    private List<Value<?>> values;
     
     /** A size to handle the number of values, as one of them can be null */
     private int size;
@@ -123,7 +123,7 @@
      * @param val the attribute's value
      * @throws NamingException if the id is invalid
      */
-    public ServerAttributeImpl( String id, Value val ) throws NamingException
+    public ServerAttributeImpl( String id, Value<?> val ) throws NamingException
     {
         if ( StringTools.isEmpty( id ) )
         {
@@ -146,7 +146,7 @@
      * @param val the attribute's value
      * @throws NamingException if the oid is invalid
      */
-    public ServerAttributeImpl( OID oid, Value val ) throws NamingException
+    public ServerAttributeImpl( OID oid, Value<?> val ) throws NamingException
     {
         if ( oid == null )
         {
@@ -292,13 +292,13 @@
                     
                 default :
                     value = null;
-                    values = new ArrayList<Value>( copy.size() );
+                    values = new ArrayList<Value<?>>( copy.size() );
                     
-                    Iterator<Value> vals = copy.getAll();
+                    Iterator<Value<?>> vals = copy.getAll();
                     
                     while ( vals.hasNext() )
                     {
-                        Value val = vals.next();
+                        Value<?> val = vals.next();
                         values.add( val );
                     }
                     
@@ -345,7 +345,7 @@
                     break;
                     
                 default :   
-                    NamingEnumeration vals = attribute.getAll();
+                    NamingEnumeration<?> vals = attribute.getAll();
                     
                     while ( vals.hasMoreElements() )
                     {
@@ -386,15 +386,19 @@
      * @param value the value to clone
      * @return the value that was cloned
      */
-    private Value getClonedValue( Value value )
+    private Value<?> getClonedValue( Value<?> value )
     {
+        if ( value == null )
+        {
+            return new StringValue( null );
+        }
         try
         {
-            return (Value)value.clone();
+            return value.clone();
         }
         catch ( CloneNotSupportedException csne )
         {
-            return null;
+            return new StringValue( null );
         }
     }
     
@@ -407,11 +411,11 @@
      * 
      * @return the Iterator wrapped as a NamingEnumberation.
      */
-    public Iterator<Value> getAll()
+    public Iterator<Value<?>> getAll()
     {
         if ( size < 2 )
         {
-            return new Iterator<Value>()
+            return new Iterator<Value<?>>()
             {
                 private boolean more = (value != null);
                     
@@ -420,7 +424,7 @@
                     return more;
                 }
                 
-                public Value next() 
+                public Value<?> next() 
                 {
                     more = false;
                     return value;
@@ -445,7 +449,7 @@
      * 
      * @return the first value or null.
      */
-    public Value get()
+    public Value<?> get()
     {
         switch ( size )
         {
@@ -500,7 +504,7 @@
      * @param val the value to test for
      * @return true if val is in the list backing store, false otherwise
      */
-    public boolean contains( Value val )
+    public boolean contains( Value<?> val )
     {
         switch ( size )
         {
@@ -511,7 +515,7 @@
                 return AttributeUtils.equals( value, val );
                 
             default :
-                for ( Value value:values )
+                for ( Value<?> value:values )
                 {
                     if ( AttributeUtils.equals( value, val ) )
                     {
@@ -556,7 +560,7 @@
      * @return true if val is added to the list backing store, false if it
      *         already existed there.
      */
-    public boolean add( Value val )
+    public boolean add( Value<?> val )
     {
         if ( contains( val ) )
         {
@@ -576,21 +580,23 @@
                 
             case 1 :
                 // We can't store different kind of Values in the attribute
-                // The null value is an exception
-                if ( ( value != null) && ( val != null ) && 
+                // The null value is an exception, as it is not associated
+                // with a StringValue or a BinaryValue
+                if ( ( value.getValue() != null) && ( val.getValue() != null ) &&

                      ( value.getClass() != val.getClass() ) )
                 {
                     return false;
                 }
 
-                if ( value != null && value.equals( val ) )
+                // value is never null.
+                if ( value.equals( val ) )
                 {
                     // Don't add two times the same value
                     return true;
                 }
                 else
                 {
-                    values = new ArrayList<Value>();
+                    values = new ArrayList<Value<?>>();
                     values.add( value );
                     values.add( val );
                     value = null;
@@ -599,7 +605,7 @@
                 }
                 
             default :
-                Value firstValue = values.get( 0 );
+                Value<?> firstValue = values.get( 0 );
             
                 if ( firstValue.getValue() == null )
                 {
@@ -607,8 +613,7 @@
                 }
                 
                 // We can't store different kind of Values in the attribute
-                // The null value is an exception
-                if ( ( val != null ) && ( val.getValue() != null ) &&
+                if ( ( val.getValue() != null ) &&
                      ( firstValue.getValue().getClass() != val.getClass() ) )
                 {
                     return false;
@@ -664,7 +669,7 @@
      * @return true if val is remove from the list backing store, false if
      *         never existed there.
      */
-    public boolean remove( Value val )
+    public boolean remove( Value<?> val )
     {
         if ( contains( val) )
         {
@@ -752,7 +757,7 @@
      * @return a copy of this attribute using the same parent lock and id
      *         containing references to all the values of the original.
      */
-    public Object clone()
+    public ServerAttribute clone()
     {
         try
         {
@@ -763,15 +768,15 @@
             
             if ( size < 2 )
             {
-                clone.value = (Value)value.clone();
+                clone.value = value.clone();
             }
             else
             {
-                clone.values = new ArrayList<Value>( values.size() );
+                clone.values = new ArrayList<Value<?>>( values.size() );
                 
-                for ( Value value:values )
+                for ( Value<?> value:values )
                 {
-                    Value newValue = (Value)value.clone();
+                    Value<?> newValue = value.clone();
                     clone.values.add( newValue );
                 }
             }
@@ -833,11 +838,11 @@
                 return ( value.equals( attr.get() ) );
             
             default :
-                Iterator<Value> vals = getAll();
+                Iterator<Value<?>> vals = getAll();
                 
                 while ( vals.hasNext() )
                 {
-                    Value val = vals.next();
+                    Value<?> val = vals.next();
                     
                     if ( !attr.contains( val ) )
                     {
@@ -909,7 +914,7 @@
             default :
                 boolean isFirst = true;
             
-                for ( Value value:values )
+                for ( Value<?> value:values )
                 {
                     if ( !isFirst )
                     {

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntry.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntry.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntry.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntry.java
Tue Oct  2 07:59:42 2007
@@ -71,7 +71,22 @@
      * 
      * @return a deep copy of this <code>Attributes</code> instance
      */
-    Object clone();
+    ServerEntry clone();
+
+
+    /**
+     * Places a non-null attribute in the attribute collection. If there is
+     * already an attribute with the same OID as the new attribute, the old one
+     * is removed from the collection and is returned by this method. If there
+     * was no attribute with the same OID the return value is <code>null</code>.
+     * 
+     * This method clone the attribute.
+     * 
+     * @param attribute the attribute to be copied
+     * @return the old attribute with the same OID, if exists; otherwise
+     *         <code>null</code>
+     */
+    ServerAttribute copy( ServerAttribute attr );
 
 
     /**
@@ -150,7 +165,7 @@
      *         <code>null</code>
      * @throws NamingException If the oid is null.
      */
-    ServerAttribute put( OID oid, Value val ) throws NamingException;
+    ServerAttribute put( OID oid, Value<?> val ) throws NamingException;
     
 
     /**

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntryImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntryImpl.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntryImpl.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/ServerEntryImpl.java
Tue Oct  2 07:59:42 2007
@@ -106,7 +106,7 @@
      * 
      * @return a deep copy of this <code>Attributes</code> instance
      */
-    public Object clone()
+    public ServerEntry clone()
     {
         try
         {
@@ -138,6 +138,29 @@
 
 
     /**
+     * Places a non-null attribute in the attribute collection. If there is
+     * already an attribute with the same OID as the new attribute, the old one
+     * is removed from the collection and is returned by this method. If there
+     * was no attribute with the same OID the return value is <code>null</code>.
+     * 
+     * This method clone the attribute.
+     * 
+     * @param attribute the attribute to be copied
+     * @return the old attribute with the same OID, if exists; otherwise
+     *         <code>null</code>
+     */
+    public ServerAttribute copy( ServerAttribute attr )
+    {
+        if ( attr == null )
+        {
+            return null;
+        }
+        
+        return put( attr.clone() );
+    }
+    
+    
+    /**
      * Returns the attribute with the specified OID. The return value
      * is <code>null</code> if no match is found.
      * 
@@ -390,7 +413,7 @@
      *         <code>null</code>
      * @throws NamingException If the oid is null.
      */
-    public ServerAttribute put( OID oid, Value val ) throws NamingException
+    public ServerAttribute put( OID oid, Value<?> val ) throws NamingException
     {
         return put( new ServerAttributeImpl( oid, val ) );
     }

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/Value.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/Value.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/Value.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/common/Value.java
Tue Oct  2 07:59:42 2007
@@ -88,5 +88,5 @@
      * @return A non-null copy of the Value.
      * @throws CloneNotSupportedException if the clone operation is not supported
      */
-    Object clone() throws CloneNotSupportedException;
+    Value<?> clone() throws CloneNotSupportedException;
 }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/BinaryValueTest.java
Tue Oct  2 07:59:42 2007
@@ -70,7 +70,7 @@
         
         BinaryValue value = new BinaryValue( bytes );
         
-        Value clone = (Value)value.clone();
+        Value<?> clone = value.clone();
         
         assertTrue( clone instanceof BinaryValue );
         assertTrue( clone.getValue() instanceof byte[] );

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerAttributeImplTest.java
Tue Oct  2 07:59:42 2007
@@ -115,7 +115,7 @@
         assertEquals( 2, attr.size() );
         assertEquals( "test1", attr.get().getValue() );
         
-        Iterator<Value> vals = attr.getAll();
+        Iterator<Value<?>> vals = attr.getAll();
         int i = 1;
         
         while ( vals.hasNext() )
@@ -140,7 +140,7 @@
         assertEquals( 2, attr.size() );
         assertTrue( Arrays.equals( b1, (byte[])attr.get().getValue() ) );
         
-        Iterator<Value> vals = attr.getAll();
+        Iterator<Value<?>> vals = attr.getAll();
         int i = 1;
         
         while ( vals.hasNext() )
@@ -280,7 +280,7 @@
     {
         ServerAttribute attr1 = new ServerAttributeImpl( "test", "test1" );
         
-        Value v = attr1.get();
+        Value<?> v = attr1.get();
         assertEquals( "test1", v.getValue() );
 
         attr1.add( "test2" );
@@ -369,12 +369,12 @@
         String[] expectedLC = new String[]{ "test1", "test2", null };
         String[] expectedUC = new String[]{ "TEST1", "TEST2", null };
         
-        Iterator<Value> iter = attr.getAll();
+        Iterator<Value<?>> iter = attr.getAll();
         int i = 0;
         
         while ( iter.hasNext() )
         {
-            Value v = iter.next();
+            Value<?> v = iter.next();
             assertEquals( expectedLC[i], v.getNormValue() );
             assertEquals( expectedUC[i], v.getValue() );
             
@@ -485,7 +485,7 @@
         
         assertNotSame( clone, attr );
         assertEquals( 3, clone.size() );
-        Value v = clone.get();
+        Value<?> v = clone.get();
         assertEquals( "TEST1", v.getValue() );
         assertEquals( "test1", v.getNormValue() );
         assertEquals( oid, clone.getOid() );
@@ -501,14 +501,14 @@
         attr.add(  "test2" );
         attr.add( (String)null );
         
-        Iterator<Value> iter = attr.getAll();
+        Iterator<Value<?>> iter = attr.getAll();
         assertNotNull( iter );
         
         int i = 0;
         
         while ( iter.hasNext() )
         {
-            Value v = iter.next();
+            Value<?> v = iter.next();
             
             assertNotNull( v );
             i++;

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/ServerEntryTest.java
Tue Oct  2 07:59:42 2007
@@ -30,13 +30,9 @@
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
 
 /**
  * A class to test ServerEntry
@@ -210,4 +206,117 @@
         
         assertEquals( dn, entry2.getDN() );
     }
+    
+
+
+
+    /**
+     * Test the getOIDs method
+     */
+    @Test public void testGetOIDs() throws InvalidNameException, DecoderException, NamingException
+    {
+        LdapDN dn = new LdapDN( "dc=example, dc=org" );
+        
+        ServerEntry entry = new ServerEntryImpl( dn );
+        
+        OID oid1 = new OID( "1.2.3" ); 
+        OID oid2 = new OID( "1.2.4" ); 
+        OID oid3 = new OID( "1.2.5" );
+        
+        OID[] expectedOIDs = new OID[]{ oid1, oid2, oid3 };
+        
+        ServerAttribute attr1 = new ServerAttributeImpl( oid1, oid1.toString() );
+        ServerAttribute attr2 = new ServerAttributeImpl( oid2, oid2.toString() );
+
+        entry.put( attr1 );
+        entry.put( attr2 );
+        entry.put( oid3, oid3.toString() );
+        
+        Iterator<OID> iterOids = entry.getOIDs();
+        int i = 0;
+        
+        while ( iterOids.hasNext() )
+        {
+            OID oid = iterOids.next();
+            assertEquals( expectedOIDs[i], oid );
+            i++;
+        }
+    }
+
+    
+    /**
+     * Test the clear method
+     */
+    @Test public void testClear() throws InvalidNameException, DecoderException, NamingException
+    {
+        LdapDN dn = new LdapDN( "dc=example, dc=org" );
+        
+        ServerEntry entry = new ServerEntryImpl( dn );
+        
+        OID oid1 = new OID( "1.2.3" ); 
+        OID oid2 = new OID( "1.2.4" ); 
+        OID oid3 = new OID( "1.2.5" );
+        
+        entry.put( oid1, oid1.toString() );
+        entry.put( oid2, oid2.toString() );
+        entry.put( oid3, oid3.toString() );
+     
+        assertEquals( 3, entry.size() );
+
+        // Now, clear the entry
+        entry.clear();
+        
+        assertEquals( 0, entry.size() );
+        assertNull( entry.remove( oid2 ) );
+    }
+
+    /**
+     * Test the clone method
+     */
+    @Test public void testClone() throws InvalidNameException, DecoderException, NamingException
+    {
+        LdapDN dn = new LdapDN( "dc=example, dc=org" );
+        
+        ServerEntry entry = new ServerEntryImpl( dn );
+        
+        OID oid1 = new OID( "1.2.3" ); 
+        OID oid2 = new OID( "1.2.4" ); 
+        OID oid3 = new OID( "1.2.5" );
+        
+        // Create three attributes : two StringValues and one BinaryValue
+        ServerAttribute attr1 = new ServerAttributeImpl( oid1, oid1.toString() );
+        ServerAttribute attr2 = new ServerAttributeImpl( oid2, StringTools.getBytesUtf8(
"test" ) );
+        ServerAttribute attr3 = new ServerAttributeImpl( oid3, oid2.toString() );
+        
+        entry.put( attr1 );
+        entry.put( attr2 );
+        entry.put( attr3 );
+     
+        assertEquals( 3, entry.size() );
+
+        // Now, clone the entry
+        ServerEntry clone = (ServerEntry)entry.clone();
+        
+        assertEquals( 3, clone.size() );
+        assertEquals( attr1, clone.get( oid1 ) );
+        assertEquals( attr2, clone.get( oid2 ) );
+        assertEquals( attr3, clone.get( oid3 ) );
+        
+        // Modify the inital attribute
+        entry.remove( oid1 );
+        assertNull( entry.get( oid1 ) );
+        assertEquals( attr1, clone.get( oid1 ) );
+        
+        // modify the clone
+        clone.remove( oid3 );
+        assertNull( clone.get( oid3 ) );
+        assertEquals( attr3, entry.get( oid3 ) );
+        
+        // Modify an attribute : the clone should not change
+        ServerAttribute attr = entry.get( oid2 );
+        ServerAttribute clonedAttr = (ServerAttribute)attr.clone();
+        attr.clear();
+        
+        assertEquals( clonedAttr, clone.get( oid2 ) );
+    }    
 }

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java?rev=581271&r1=581270&r2=581271&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/common/StringValueTest.java
Tue Oct  2 07:59:42 2007
@@ -63,7 +63,7 @@
     {
         StringValue value = new StringValue( "Test1" );
         
-        Value clone = (Value)value.clone();
+        Value<?> clone = value.clone();
         
         assertTrue( clone instanceof StringValue );
         assertTrue( clone.getValue() instanceof String );



Mime
View raw message