directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r499013 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/message/ test/java/org/apache/directory/shared/ldap/message/
Date Tue, 23 Jan 2007 13:08:58 GMT
Author: elecharny
Date: Tue Jan 23 05:08:57 2007
New Revision: 499013

URL: http://svn.apache.org/viewvc?view=rev&rev=499013
Log:
Fixed tests and clone/copy implementation

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributesImplTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java?view=diff&rev=499013&r1=499012&r2=499013
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
Tue Jan 23 05:08:57 2007
@@ -31,6 +31,7 @@
 import javax.naming.NamingException;
 import javax.naming.OperationNotSupportedException;
 import javax.naming.directory.Attribute;
+import javax.naming.directory.BasicAttribute;
 import javax.naming.directory.DirContext;
 
 import org.apache.directory.shared.ldap.util.AttributeUtils;
@@ -138,7 +139,7 @@
             size = clone.size;
             value = clone.value;
         }
-        else if ( attribute instanceof AttributeImpl )
+        else if ( attribute instanceof BasicAttribute )
         {
             upId = attribute.getID();
             

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java?view=diff&rev=499013&r1=499012&r2=499013
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributesImpl.java
Tue Jan 23 05:08:57 2007
@@ -243,7 +243,8 @@
             ignoreCase = attributes.isCaseIgnored();
             
             NamingEnumeration attrs = attributes.getAll();
-            
+            keyMap = new HashMap<String, Holder>();
+
             while ( attrs.hasMoreElements() )
             {
                 Attribute attribute = new AttributeImpl( (Attribute)attrs.nextElement() );

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributesImplTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributesImplTest.java?view=diff&rev=499013&r1=499012&r2=499013
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributesImplTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/message/AttributesImplTest.java
Tue Jan 23 05:08:57 2007
@@ -20,7 +20,10 @@
 package org.apache.directory.shared.ldap.message;
 
 
+import javax.naming.NamingException;
+import javax.naming.directory.Attribute;
 import javax.naming.directory.Attributes;
+import javax.naming.directory.BasicAttributes;
 
 import junit.framework.TestCase;
 
@@ -156,15 +159,95 @@
         AttributesImpl attrs0 = new AttributesImpl();
         attrs0.put( "attr0", "value0" );
         attrs0.put( "attr1", "value1" );
-        attrs0.put( "attr2", "value2" );
-        attrs0.put( "attr2", "value3" );
+
+        Attribute attr0 = new AttributeImpl( "attr2" );
+        attr0.add( "value2" );
+        attr0.add( "value3" );
+        attrs0.put( attr0 );
 
         Attributes attrs1 = new AttributesImpl( true );
         attrs1.put( "attr0", "value0" );
         attrs1.put( "attr1", "value1" );
-        attrs1.put( "attr2", "value2" );
-        attrs1.put( "attr2", "value3" );
+
+        Attribute attr1 = new AttributeImpl( "attr2" );
+        attr1.add( "value2" );
+        attr1.add( "value3" );
+        attrs1.put( attr1 );
 
         assertTrue( "both implementations should produce the same outcome", attrs0.equals(
attrs1 ) );
+    }
+    
+    public void testCloneAttributes() throws NamingException
+    {
+        AttributesImpl attrs = new AttributesImpl();
+        attrs.put( "attr0", "value0" );
+        attrs.put( "attr1", "value1" );
+        
+        Attribute attr = new AttributeImpl( "attr2" );
+        attr.add( "value2" );
+        attr.add( "value3" );
+        attrs.put( attr );
+        
+        AttributesImpl clone = (AttributesImpl)attrs.clone();
+        
+        // Both attributes should be equals
+        assertEquals( attrs, clone );
+        assertEquals( 3, clone.size() );
+        
+        Attribute attr0 = clone.get( "attr0" );
+        assertEquals( 1, attr0.size() );
+        assertEquals( "value0", attr0.get() );
+        
+        Attribute attr1 = clone.get( "attr1" );
+        assertEquals( 1, attr1.size() );
+        assertEquals( "value1", attr1.get() );
+        
+        Attribute attr2 = clone.get( "attr2" );
+        assertEquals( 2, attr2.size() );
+        assertTrue( attr2.contains( "value2" ) );
+        assertTrue( attr2.contains( "value3" ) );
+        
+        // Remove an element
+        attrs.remove( "attr1" );
+        assertNotSame( attrs, clone );
+        assertEquals( 2, attrs.size() );
+        assertEquals( 3, clone.size() );
+    }
+
+    public void testCopyBasicAttributes() throws NamingException
+    {
+        BasicAttributes attrs = new BasicAttributes();
+        attrs.put( "attr0", "value0" );
+        attrs.put( "attr1", "value1" );
+
+        Attribute attr = new AttributeImpl( "attr2" );
+        attr.add( "value2" );
+        attr.add( "value3" );
+        attrs.put( attr );
+        
+        AttributesImpl copy = new AttributesImpl( attrs );
+        
+        // Both attributes should be internally equals
+        assertNotSame( copy, attrs );
+        assertEquals( 3, copy.size() );
+        
+        Attribute attr0 = copy.get( "attr0" );
+        assertEquals( 1, attr0.size() );
+        assertEquals( "value0", attr0.get() );
+        
+        Attribute attr1 = copy.get( "attr1" );
+        assertEquals( 1, attr1.size() );
+        assertEquals( "value1", attr1.get() );
+        
+        Attribute attr2 = copy.get( "attr2" );
+        assertEquals( 2, attr2.size() );
+        assertTrue( attr2.contains( "value2" ) );
+        assertTrue( attr2.contains( "value3" ) );
+        
+        // Remove an element
+        attrs.remove( "attr1" );
+        assertNotSame( copy, attrs );
+        assertEquals( 2, attrs.size() );
+        assertEquals( 3, copy.size() );
     }
 }



Mime
View raw message