directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r637318 [2/2] - in /directory/apacheds/branches/bigbang/core-entry/src: main/java/org/apache/directory/server/core/entry/ test/java/org/apache/directory/server/core/entry/
Date Sat, 15 Mar 2008 00:56:28 GMT
Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java?rev=637318&r1=637317&r2=637318&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerAttributeTest.java Fri Mar 14 17:56:26 2008
@@ -1,48 +1,128 @@
 /*
- *  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. 
- *  
+ * 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.server.core.entry;
 
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
 import java.util.Set;
 
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
 import javax.naming.directory.InvalidAttributeValueException;
 
+import org.apache.directory.server.schema.bootstrap.ApacheSchema;
+import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
+import org.apache.directory.server.schema.bootstrap.BootstrapSchemaLoader;
+import org.apache.directory.server.schema.bootstrap.CoreSchema;
+import org.apache.directory.server.schema.bootstrap.CosineSchema;
+import org.apache.directory.server.schema.bootstrap.InetorgpersonSchema;
+import org.apache.directory.server.schema.bootstrap.Schema;
+import org.apache.directory.server.schema.bootstrap.SystemSchema;
+import org.apache.directory.server.schema.registries.DefaultOidRegistry;
+import org.apache.directory.server.schema.registries.DefaultRegistries;
+import org.apache.directory.server.schema.registries.OidRegistry;
+import org.apache.directory.server.schema.registries.Registries;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.entry.client.ClientBinaryValue;
+import org.apache.directory.shared.ldap.entry.client.ClientStringValue;
+import org.apache.directory.shared.ldap.entry.client.DefaultClientAttribute;
 import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
 /**
- * Tests for the DefaultServerAttribute class. 
- *
+ * Tests for the DefaultServerAttribute class
+ * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class DefaultServerAttributeTest
 {
+    private static BootstrapSchemaLoader loader;
+    private static Registries registries;
+    private static OidRegistry oidRegistry;
+    
+    private static AttributeType atCN;
+    private static AttributeType atSN;
+    
+    // A SINGLE-VALUE attribute
+    private static AttributeType atC;   
+    
+    // A Binary attribute
+    private static AttributeType atPwd;
+
+    private static final Value<String> NULL_STRING_VALUE = new ClientStringValue( null );
+    private static final Value<byte[]> NULL_BINARY_VALUE = new ClientBinaryValue( null );
+    private static final byte[] BYTES1 = new byte[]{ 'a', 'b' };
+    private static final byte[] BYTES2 = new byte[]{ 'b' };
+    private static final byte[] BYTES3 = new byte[]{ 'c' };
+    private static final byte[] BYTES4 = new byte[]{ 'd' };
+    
+    private static final ClientStringValue STR_VALUE1 = new ClientStringValue( "a" );
+    private static final ClientStringValue STR_VALUE2 = new ClientStringValue( "b" );
+    private static final ClientStringValue STR_VALUE3 = new ClientStringValue( "c" );
+    private static final ClientStringValue STR_VALUE4 = new ClientStringValue( "d" );
+
+    private static final ClientBinaryValue BIN_VALUE1 = new ClientBinaryValue( BYTES1 );
+    private static final ClientBinaryValue BIN_VALUE2 = new ClientBinaryValue( BYTES2 );
+    private static final ClientBinaryValue BIN_VALUE3 = new ClientBinaryValue( BYTES3 );
+    private static final ClientBinaryValue BIN_VALUE4 = new ClientBinaryValue( BYTES4 );
+
+    /**
+     * Initialize the registries once for the whole test suite
+     */
+    @BeforeClass
+    public static void setup() throws NamingException
+    {
+        loader = new BootstrapSchemaLoader();
+        oidRegistry = new DefaultOidRegistry();
+        registries = new DefaultRegistries( "bootstrap", loader, oidRegistry );
+        
+        // load essential bootstrap schemas 
+        Set<Schema> bootstrapSchemas = new HashSet<Schema>();
+        bootstrapSchemas.add( new ApachemetaSchema() );
+        bootstrapSchemas.add( new ApacheSchema() );
+        bootstrapSchemas.add( new CoreSchema() );
+        bootstrapSchemas.add( new SystemSchema() );
+        bootstrapSchemas.add( new InetorgpersonSchema() );
+        bootstrapSchemas.add( new CosineSchema() );
+        loader.loadWithDependencies( bootstrapSchemas, registries );
+        
+        atCN = registries.getAttributeTypeRegistry().lookup( "cn" );
+        atC = registries.getAttributeTypeRegistry().lookup( "c" );
+        atSN = registries.getAttributeTypeRegistry().lookup( "sn" );
+        atPwd = registries.getAttributeTypeRegistry().lookup( "userpassword" );
+    }
+
     @Test public void testAddOneValue() throws NamingException
     {
         AttributeType at = TestServerEntryUtils.getIA5StringAttributeType();
@@ -54,7 +134,7 @@
         
         assertEquals( 1, attr.size() );
         
-        assertTrue( attr.getType().getSyntax().isHumanReadable() );
+        assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() );
         
         Value<?> value = attr.get();
         
@@ -62,15 +142,7 @@
         assertEquals( "test", ((ServerStringValue)value).get() );
         
         // Add a binary value
-        try
-        {
-            attr.add( new byte[]{0x01} );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        assertEquals( 0, attr.add( new byte[]{0x01} ) );
         
         // Add a Value
         Value<?> ssv = new ServerStringValue( at, "test2" );
@@ -111,7 +183,7 @@
         
         assertEquals( 2, attr.size() );
         
-        assertTrue( attr.getType().getSyntax().isHumanReadable() );
+        assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() );
         
         Set<String> expected = new HashSet<String>();
         expected.add( "test" );
@@ -144,7 +216,7 @@
         
         assertEquals( 1, attr.size() );
         
-        assertTrue( attr.getType().getSyntax().isHumanReadable() );
+        assertTrue( attr.getAttributeType().getSyntax().isHumanReadable() );
         
         Value<?> value = attr.get();
         
@@ -188,5 +260,1656 @@
         assertTrue( attr.contains( "test 1" ) );
         assertTrue( attr.contains( "Test 2" ) );
         assertTrue( attr.contains( "TEST     3" ) );
+    }
+
+
+    /**
+     * Test method getBytes()
+     */
+    @Test
+    public void testGetBytes() throws InvalidAttributeValueException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd );
+        
+        attr1.add( (byte[])null );
+        assertNull( attr1.getBytes() );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        
+        attr2.add( BYTES1, BYTES2 );
+        assertTrue( Arrays.equals( BYTES1, attr2.getBytes() ) );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atCN );
+        
+        attr3.add( "a", "b" );
+        
+        try
+        {
+            attr3.getBytes();
+            fail();
+        }
+        catch ( InvalidAttributeValueException ivae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test method getId()
+     */
+    @Test
+    public void testGetId()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+
+        assertEquals( "cn", attr.getId() );
+        
+        attr.setId(  "  CN  " );
+        assertEquals( "cn", attr.getId() );
+
+        attr.setId(  "  CommonName  " );
+        assertEquals( "commonname", attr.getId() );
+
+        attr.setId(  "  2.5.4.3  " );
+        assertEquals( "2.5.4.3", attr.getId() );
+    }
+
+
+    /**
+     * Test method getString()
+     */
+    @Test
+    public void testGetString() throws InvalidAttributeValueException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        attr1.add( (String)null );
+        assertNull( attr1.getString() );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN );
+        
+        attr2.add( "a", "b" );
+        assertEquals( "a", attr2.getString() );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atPwd );
+        
+        attr3.add( BYTES1, BYTES2 );
+        
+        try
+        {
+            attr3.getString();
+            fail();
+        }
+        catch ( InvalidAttributeValueException ivae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test method getUpId
+     */
+    @Test
+    public void testGetUpId()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+
+        assertNotNull( attr.getUpId() );
+        assertEquals( "cn", attr.getUpId() );
+        
+        attr.setUpId( "CN" );
+        assertEquals( "CN", attr.getUpId() );
+        
+        attr.setUpId(  "  Cn  " );
+        assertEquals( "Cn", attr.getUpId() );
+
+        attr.setUpId(  "  2.5.4.3  " );
+        assertEquals( "2.5.4.3", attr.getUpId() );
+    }
+
+
+    /**
+     * Test method hashCode()
+     */
+    @Test
+    public void testHashCode()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        ServerAttribute attr2 = new DefaultServerAttribute( atSN );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+        
+        attr2.setAttributeType( atCN );
+        assertEquals( attr1.hashCode(), attr2.hashCode() );
+        
+        attr1.put( (String)null );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+
+        attr1.clear();
+        assertEquals( attr1.hashCode(), attr2.hashCode() );
+        
+        attr1.put( "a", "b" );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+
+        attr2.put( "a", "b" );
+        assertEquals( attr1.hashCode(), attr2.hashCode() );
+        
+        // Order matters
+        attr2.put( "b", "a" );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atPwd );
+        ServerAttribute attr4 = new DefaultServerAttribute( atPwd );
+        assertNotSame( attr3.hashCode(), attr4.hashCode() );
+        
+        attr3.put( (byte[])null );
+        assertNotSame( attr3.hashCode(), attr4.hashCode() );
+
+        attr3.clear();
+        assertEquals( attr3.hashCode(), attr4.hashCode() );
+        
+        attr3.put( new byte[]{0x01, 0x02}, new byte[]{0x03, 0x04} );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+
+        attr4.put( new byte[]{0x01, 0x02}, new byte[]{0x03, 0x04} );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+
+        // Order matters
+        attr4.put( new byte[]{0x03, 0x04}, new byte[]{0x01, 0x02} );
+        assertNotSame( attr1.hashCode(), attr2.hashCode() );
+    }
+    
+    
+    /**
+     * Test method SetId(String)
+     */
+    @Test
+    public void testSetId()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+
+        attr.setId( "Cn" );
+        assertEquals( "cn", attr.getId() );
+        
+        attr.setId( " CN " );
+        assertEquals( "cn", attr.getId() );
+        
+        attr.setId( " 2.5.4.3 " );
+        assertEquals( "2.5.4.3", attr.getId() );
+        
+        attr.setId( " commonName " );
+        assertEquals( "commonname", attr.getId() );
+
+        try
+        {
+            attr.setId( null );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        try
+        {
+            attr.setId( "" );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        try
+        {
+            attr.setId( "  " );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        try
+        {
+            attr.setId( " SN " );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test method isValid()
+     */
+    @Test
+    public void testIsValid() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        // No value, this should be valid
+        assertTrue( attr.isValid() );
+        
+        attr.add( "test", "test2", "A123\\;" );
+        assertTrue( attr.isValid() );
+
+        // If we try to add a wrong value, it will not be added. The
+        // attribute remains valid.
+        assertEquals(0, attr.add( new byte[]{0x01} ) );
+        assertTrue( attr.isValid() );
+
+        // test a SINGLE-VALUE attribute. CountryName is SINGLE-VALUE
+        attr.setAttributeType( atC );
+        attr.put( "FR" );
+        assertTrue( attr.isValid() );
+        attr.add( "US" );
+        assertFalse( attr.isValid() );
+    }
+
+
+    /**
+     * Test method add( Value... )
+     */
+    @Test
+    public void testAddValueArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        int nbAdded = attr1.add( new ServerStringValue( atCN, null ) );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr1.isHR() );
+        assertEquals( NULL_STRING_VALUE, attr1.get() );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr2.add( new ServerBinaryValue( atPwd, null ) );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr2.isHR() );
+        assertEquals( NULL_BINARY_VALUE, attr2.get() );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr3.add( new ServerStringValue( atCN, "a" ), new ServerStringValue( atCN, "b" ) );
+        assertEquals( 2, nbAdded );
+        assertTrue( attr3.isHR() );
+        assertTrue( attr3.contains( "a" ) );
+        assertTrue( attr3.contains( "b" ) );
+        
+        ServerAttribute attr4 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr4.add( new ServerBinaryValue( atPwd, BYTES1 ), new ServerBinaryValue( atPwd, BYTES2 ) );
+        assertEquals( 0, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertFalse( attr4.contains( BYTES1 ) );
+        assertFalse( attr4.contains( BYTES2 ) );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr5.add( new ServerStringValue( atCN, "c" ), new ServerBinaryValue( atPwd, BYTES1 ) );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr5.isHR() );
+        assertFalse( attr5.contains( "ab" ) );
+        assertTrue( attr5.contains( "c" ) );
+
+        ServerAttribute attr6 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr6.add( new ServerBinaryValue( atPwd, BYTES1 ), new ServerStringValue( atCN, "c" ) );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr6.isHR() );
+        assertTrue( attr6.contains( BYTES1 ) );
+        assertFalse( attr6.contains( BYTES3 ) );
+
+        ServerAttribute attr7 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr7.add( new ServerBinaryValue( atPwd, null ), new ServerStringValue( atCN, "c" ) );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr7.isHR() );
+        assertTrue( attr7.contains( NULL_BINARY_VALUE ) );
+        assertFalse( attr7.contains( BYTES3 ) );
+
+        ServerAttribute attr8 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr8.add( new ServerStringValue( atCN, null ), new ServerBinaryValue( atPwd, BYTES1 ) );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr8.isHR() );
+        assertTrue( attr8.contains( NULL_STRING_VALUE ) );
+        assertFalse( attr8.contains( "ab" ) );
+
+    
+        ServerAttribute attr9 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr9.add( new ClientStringValue( null ), new ClientStringValue( "ab" ) );
+        assertEquals( 2, nbAdded );
+        assertTrue( attr9.isHR() );
+        assertTrue( attr9.contains( NULL_STRING_VALUE ) );
+        assertTrue( attr9.contains( "ab" ) );
+
+        ServerAttribute attr10 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr10.add( new ClientBinaryValue( null ), new ClientBinaryValue( BYTES1 ) );
+        assertEquals( 2, nbAdded );
+        assertFalse( attr10.isHR() );
+        assertTrue( attr10.contains( NULL_BINARY_VALUE ) );
+        assertTrue( attr10.contains( BYTES1 ) );
+    }
+
+
+    /**
+     * Test method add( String... )
+     */
+    @Test
+    public void testAddStringArray() throws InvalidAttributeValueException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        int nbAdded = attr1.add( (String)null );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr1.isHR() );
+        assertEquals( NULL_STRING_VALUE, attr1.get() );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr2.add( "" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr2.isHR() );
+        assertEquals( "", attr2.getString() );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr3.add( "t" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr3.isHR() );
+        assertEquals( "t", attr3.getString() );
+        
+        ServerAttribute attr4 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr4.add( "a", "b", "c", "d" );
+        assertEquals( 4, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertEquals( "a", attr4.getString() );
+        assertTrue( attr4.contains( "a" ) );
+        assertTrue( attr4.contains( "b" ) );
+        assertTrue( attr4.contains( "c" ) );
+        assertTrue( attr4.contains( "d" ) );
+        
+        nbAdded = attr4.add( "e" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertEquals( "a", attr4.getString() );
+        assertTrue( attr4.contains( "a" ) );
+        assertTrue( attr4.contains( "b" ) );
+        assertTrue( attr4.contains( "c" ) );
+        assertTrue( attr4.contains( "d" ) );
+        assertTrue( attr4.contains( "e" ) );
+        
+        nbAdded = attr4.add( BYTES1 );
+        assertEquals( 0, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertEquals( "a", attr4.getString() );
+        assertTrue( attr4.contains( "a" ) );
+        assertTrue( attr4.contains( "b" ) );
+        assertTrue( attr4.contains( "c" ) );
+        assertTrue( attr4.contains( "d" ) );
+        assertTrue( attr4.contains( "e" ) );
+        assertFalse( attr4.contains( "ab" ) );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr5.add( "a", "b", (String)null, "d" );
+        assertEquals( 4, nbAdded );
+        assertTrue( attr5.isHR() );
+        assertTrue( attr5.contains( "a" ) );
+        assertTrue( attr5.contains( "b" ) );
+        assertTrue( attr5.contains( NULL_STRING_VALUE ) );
+        assertTrue( attr5.contains( "d" ) );
+
+        ServerAttribute attr6 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr6.add( "a", (String)null );
+        assertEquals( 0, nbAdded );
+        assertFalse( attr6.isHR() );
+    }
+
+
+    /**
+     * Test method add( byte[]... )
+     */
+    @Test
+    public void testAddByteArray() throws InvalidAttributeValueException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd );
+        
+        int nbAdded = attr1.add( (byte[])null );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr1.isHR() );
+        assertTrue( Arrays.equals( NULL_BINARY_VALUE.get(), attr1.getBytes() ) );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr2.add( StringTools.EMPTY_BYTES );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr2.isHR() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, attr2.getBytes() ) );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr3.add( BYTES1 );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr3.isHR() );
+        assertTrue( Arrays.equals( BYTES1, attr3.getBytes() ) );
+        
+        ServerAttribute attr4 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr4.add( BYTES1, BYTES2, BYTES3, BYTES4 );
+        assertEquals( 4, nbAdded );
+        assertFalse( attr4.isHR() );
+        assertTrue( attr4.contains( BYTES1 ) );
+        assertTrue( attr4.contains( BYTES2 ) );
+        assertTrue( attr4.contains( BYTES3 ) );
+        assertTrue( attr4.contains( BYTES4 ) );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr5.add( BYTES1, BYTES2, (byte[])null, BYTES3 );
+        assertEquals( 4, nbAdded );
+        assertFalse( attr5.isHR() );
+        assertTrue( attr5.contains( BYTES1 ) );
+        assertTrue( attr5.contains( BYTES2 ) );
+        assertTrue( attr5.contains( (byte[])null ) );
+        assertTrue( attr5.contains( BYTES3 ) );
+
+        ServerAttribute attr6 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr6.add( "ab", (String)null );
+        assertEquals( 0, nbAdded );
+        assertFalse( attr6.isHR() );
+    }
+
+
+    /**
+     * Test method clear()
+     */
+    @Test
+    public void testClear()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( "cn", atCN );
+        
+        assertEquals( 0, attr.size() );
+        
+        attr.add( (String)null, "a", "b" );
+        assertEquals( 3, attr.size() );
+        
+        attr.clear();
+        assertTrue( attr.isHR() );
+        assertEquals( 0, attr.size() );
+        assertEquals( atCN, attr.getAttributeType() );
+    }
+
+
+    /**
+     * Test method contains( Value... )
+     */
+    @Test
+    public void testContainsValueArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        assertEquals( 0, attr1.size() );
+        assertFalse( attr1.contains( STR_VALUE1 ) );
+        assertFalse( attr1.contains( NULL_STRING_VALUE ) );
+        
+        attr1.add( (String)null );
+        assertEquals( 1, attr1.size() );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        
+        attr1.remove( (String)null );
+        assertFalse( attr1.contains( NULL_STRING_VALUE ) );
+        assertEquals( 0, attr1.size() );
+        
+        attr1.add(  "a", "b", "c" );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( STR_VALUE2 ) );
+        assertTrue( attr1.contains( STR_VALUE3 ) );
+        assertTrue( attr1.contains( STR_VALUE1, STR_VALUE3 ) );
+        assertFalse( attr1.contains( STR_VALUE4 ) );
+        assertFalse( attr1.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        assertEquals( 0, attr2.size() );
+        assertFalse( attr2.contains( BYTES1 ) );
+        assertFalse( attr2.contains( NULL_BINARY_VALUE ) );
+        
+        attr2.add( (byte[])null );
+        assertEquals( 1, attr2.size() );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+        
+        attr2.remove( (byte[])null );
+        assertFalse( attr2.contains( NULL_BINARY_VALUE ) );
+        assertEquals( 0, attr2.size() );
+        
+        attr2.add( BYTES1, BYTES2, BYTES3 );
+        assertEquals( 3, attr2.size() );
+        assertTrue( attr2.contains( BIN_VALUE1 ) );
+        assertTrue( attr2.contains( BIN_VALUE2 ) );
+        assertTrue( attr2.contains( BIN_VALUE3 ) );
+        assertFalse( attr2.contains( NULL_BINARY_VALUE ) );
+    }
+
+
+    /**
+     * Test method contains( String... )
+     */
+    @Test
+    public void testContainsStringArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        assertEquals( 0, attr1.size() );
+        assertFalse( attr1.contains( "a" ) );
+        assertFalse( attr1.contains( (String)null ) );
+        
+        attr1.add( (String)null );
+        assertEquals( 1, attr1.size() );
+        assertTrue( attr1.contains( (String)null ) );
+        
+        attr1.remove( (String)null );
+        assertFalse( attr1.contains( (String)null ) );
+        assertEquals( 0, attr1.size() );
+        
+        attr1.add(  "a", "b", "c" );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( "a" ) );
+        assertTrue( attr1.contains( "b" ) );
+        assertTrue( attr1.contains( "c" ) );
+        assertFalse( attr1.contains( "e" ) );
+        assertFalse( attr1.contains( (String)null ) );
+    }
+
+
+    /**
+     * Test method contains( byte[]... )
+     */
+    @Test
+    public void testContainsByteArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd );
+        
+        assertEquals( 0, attr1.size() );
+        assertFalse( attr1.contains( BYTES1 ) );
+        assertFalse( attr1.contains( (byte[])null ) );
+        
+        attr1.add( (byte[])null );
+        assertEquals( 1, attr1.size() );
+        assertTrue( attr1.contains( (byte[])null ) );
+        
+        attr1.remove( (byte[])null );
+        assertFalse( attr1.contains( (byte[])null ) );
+        assertEquals( 0, attr1.size() );
+        
+        attr1.add(  BYTES1, BYTES2, BYTES3 );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( BYTES1 ) );
+        assertTrue( attr1.contains( BYTES2 ) );
+        assertTrue( attr1.contains( BYTES3 ) );
+        assertFalse( attr1.contains( BYTES4 ) );
+        assertFalse( attr1.contains( (byte[])null ) );
+    }
+
+
+    /**
+     * Test method testEquals()
+     */
+    @Test
+    public void testEquals()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        assertFalse( attr1.equals( null ) );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN );
+        
+        assertTrue( attr1.equals( attr2 ) );
+        
+        attr2.setId( "CN" );
+        assertTrue( attr1.equals( attr2 ) );
+
+        attr1.setId( "CommonName" );
+        assertTrue( attr1.equals( attr2 ) );
+        
+        attr1.setUpId( "CN" );
+        assertTrue( attr1.equals( attr2 ) );
+        
+        attr1.add( "a", "b", "c" );
+        attr2.add( "c", "b", "a" );
+        assertTrue( attr1.equals( attr2 ) );
+        
+        attr1.setHR( true );
+        attr2.setHR( false );
+        assertTrue( attr1.equals( attr2 ) );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atPwd );
+        ServerAttribute attr4 = new DefaultServerAttribute( atPwd );
+        
+        attr3.put( NULL_BINARY_VALUE );
+        attr4.put( NULL_BINARY_VALUE );
+        assertTrue( attr3.equals( attr4 ) );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atPwd );
+        ServerAttribute attr6 = new DefaultServerAttribute( atCN );
+        assertFalse( attr5.equals( attr6 ) );
+        
+        attr5.put( NULL_BINARY_VALUE );
+        attr6.put( NULL_STRING_VALUE );
+        assertFalse( attr5.equals( attr6 ) );
+
+        ServerAttribute attr7 = new DefaultServerAttribute( atCN );
+        ServerAttribute attr8 = new DefaultServerAttribute( atPwd );
+        
+        attr7.put( "a" );
+        attr8.put( BYTES2 );
+        assertFalse( attr7.equals( attr8 ) );
+
+        ServerAttribute attr9 = new DefaultServerAttribute( atCN );
+        ServerAttribute attr10 = new DefaultServerAttribute( atPwd );
+        
+        attr7.put( "a" );
+        attr7.add( BYTES2 );
+        attr8.put( "a", "b" );
+        assertFalse( attr9.equals( attr10 ) );
+    }
+
+
+    /**
+     * Test method get()
+     */
+    @Test
+    public void testGet()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( "cn", atCN );
+        
+        attr1.add( (String)null );
+        assertEquals( NULL_STRING_VALUE,attr1.get() );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( "cn", atCN );
+        
+        attr2.add( "a", "b", "c" );
+        assertEquals( "a", attr2.get().get() );
+        
+        attr2.remove( "a" );
+        assertEquals( "b", attr2.get().get() );
+
+        attr2.remove( "b" );
+        assertEquals( "c", attr2.get().get() );
+
+        attr2.remove( "c" );
+        assertNull( attr2.get() );
+
+        ServerAttribute attr3 = new DefaultServerAttribute( "userPassword", atPwd );
+        
+        attr3.add( BYTES1, BYTES2, BYTES3 );
+        assertTrue( Arrays.equals( BYTES1, (byte[])attr3.get().get() ) );
+        
+        attr3.remove( BYTES1 );
+        assertTrue( Arrays.equals( BYTES2, (byte[])attr3.get().get() ) );
+
+        attr3.remove( BYTES2 );
+        assertTrue( Arrays.equals( BYTES3, (byte[])attr3.get().get() ) );
+
+        attr3.remove( BYTES3 );
+        assertNull( attr2.get() );
+    }
+
+
+    /**
+     * Test method getAll()
+     */
+    @Test
+    public void testGetAll()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        Iterator<Value<?>> iterator = attr.getAll(); 
+        assertFalse( iterator.hasNext() );
+        
+        attr.add( NULL_STRING_VALUE );
+        iterator = attr.getAll(); 
+        assertTrue( iterator.hasNext() );
+        
+        Value<?> value = iterator.next();
+        assertEquals( NULL_STRING_VALUE, value );
+        
+        attr.clear();
+        iterator = attr.getAll(); 
+        assertFalse( iterator.hasNext() );
+        
+        attr.add(  "a", "b", "c" );
+        iterator = attr.getAll(); 
+        assertTrue( iterator.hasNext() );
+        assertEquals( "a", iterator.next().get() );
+        assertEquals( "b", iterator.next().get() );
+        assertEquals( "c", iterator.next().get() );
+        assertFalse( iterator.hasNext() );
+    }
+
+
+    /**
+     * Test method size()
+     */
+    @Test
+    public void testSize() throws NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+
+        assertEquals( 0, attr1.size() );
+        
+        attr1.add( (String)null );
+        assertEquals( 1, attr1.size() );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN );
+        
+        attr2.add( "a", "b" );
+        assertEquals( 2, attr2.size() );
+        
+        attr2.clear();
+        assertEquals( 0, attr2.size() );
+
+        ServerAttribute attr3 = new DefaultServerAttribute( atC );
+        
+        attr3.add( "US" );
+        assertEquals( 1, attr3.size() );
+        
+        // TODO : forbid addition of more than 1 value for SINGLE-VALUE attributes
+        attr3.add( "FR" );
+        assertEquals( 2, attr3.size() );
+    }
+
+
+    /**
+     * Test method put( byte[]... )
+     */
+    @Test
+    public void testPutByteArray() throws InvalidAttributeValueException, NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd );
+        
+        int nbAdded = attr1.put( (byte[])null );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr1.isHR() );
+        assertTrue( Arrays.equals( NULL_BINARY_VALUE.get(), attr1.getBytes() ) );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr2.put( StringTools.EMPTY_BYTES );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr2.isHR() );
+        assertTrue( Arrays.equals( StringTools.EMPTY_BYTES, attr2.getBytes() ) );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr3.put( BYTES1 );
+        assertEquals( 1, nbAdded );
+        assertFalse( attr3.isHR() );
+        assertTrue( Arrays.equals( BYTES1, attr3.getBytes() ) );
+        
+        ServerAttribute attr4 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr4.put( BYTES1, BYTES2 );
+        assertEquals( 2, nbAdded );
+        assertFalse( attr4.isHR() );
+        assertTrue( attr4.contains( BYTES1 ) );
+        assertTrue( attr4.contains( BYTES2 ) );
+        
+        nbAdded = attr4.put( BYTES3, BYTES4 );
+        assertEquals( 2, nbAdded );
+        assertFalse( attr4.isHR() );
+        assertTrue( attr4.contains( BYTES3 ) );
+        assertTrue( attr4.contains( BYTES4 ) );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr5.put( BYTES1, BYTES2, (byte[])null, BYTES3 );
+        assertEquals( 4, nbAdded );
+        assertFalse( attr5.isHR() );
+        assertTrue( attr5.contains( BYTES1 ) );
+        assertTrue( attr5.contains( BYTES2 ) );
+        assertTrue( attr5.contains( (byte[])null ) );
+        assertTrue( attr5.contains( BYTES3 ) );
+
+        ServerAttribute attr6 = new DefaultServerAttribute( atPwd );
+        
+        attr6.setHR( true );
+        assertFalse( attr6.isHR() );
+        nbAdded = attr6.put( BYTES1, (byte[])null );
+        assertEquals( 2, nbAdded );
+        assertTrue( attr6.contains( BYTES1 ) );
+        assertTrue( attr6.contains( (byte[])null ) );
+    }
+
+
+    /**
+     * Test method put( String... )
+     */
+    @Test
+    public void testPutStringArray() throws InvalidAttributeValueException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        int nbAdded = attr1.put( (String)null );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr1.isHR() );
+        assertEquals( NULL_STRING_VALUE, attr1.get() );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr2.put( "" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr2.isHR() );
+        assertEquals( "", attr2.getString() );
+        
+        ServerAttribute attr3 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr3.put( "t" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr3.isHR() );
+        assertEquals( "t", attr3.getString() );
+        
+        ServerAttribute attr4 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr4.put( "a", "b", "c", "d" );
+        assertEquals( 4, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertEquals( "a", attr4.getString() );
+        assertTrue( attr4.contains( "a" ) );
+        assertTrue( attr4.contains( "b" ) );
+        assertTrue( attr4.contains( "c" ) );
+        assertTrue( attr4.contains( "d" ) );
+        
+        nbAdded = attr4.put( "e" );
+        assertEquals( 1, nbAdded );
+        assertTrue( attr4.isHR() );
+        assertEquals( "e", attr4.getString() );
+        assertFalse( attr4.contains( "a" ) );
+        assertFalse( attr4.contains( "b" ) );
+        assertFalse( attr4.contains( "c" ) );
+        assertFalse( attr4.contains( "d" ) );
+        assertTrue( attr4.contains( "e" ) );
+        
+        nbAdded = attr4.put( BYTES1 );
+        assertEquals( 0, nbAdded );
+        assertTrue( attr4.isHR() );
+        
+        ServerAttribute attr5 = new DefaultServerAttribute( atCN );
+        
+        nbAdded = attr5.put( "a", "b", (String)null, "d" );
+        assertEquals( 4, nbAdded );
+        assertTrue( attr5.isHR() );
+        assertTrue( attr5.contains( "a" ) );
+        assertTrue( attr5.contains( "b" ) );
+        assertTrue( attr5.contains( NULL_STRING_VALUE ) );
+        assertTrue( attr5.contains( "d" ) );
+
+        ServerAttribute attr6 = new DefaultServerAttribute( atPwd );
+        
+        nbAdded = attr6.put( "a", (String)null );
+        assertEquals( 0, nbAdded );
+        assertFalse( attr6.isHR() );
+    }
+
+
+    /**
+     * Test method put( Value... )
+     */
+    @Test
+    public void testPutValueArray() throws InvalidAttributeValueException, NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        assertEquals( 0, attr1.size() );
+        
+        attr1.put( NULL_STRING_VALUE );
+        assertEquals( 1, attr1.size() );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        
+        attr1.put( STR_VALUE1, STR_VALUE2, STR_VALUE3 );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( STR_VALUE2 ) );
+        assertTrue( attr1.contains( STR_VALUE3 ) );
+
+        attr1.put( STR_VALUE1, NULL_STRING_VALUE, STR_VALUE3 );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        assertTrue( attr1.contains( STR_VALUE3 ) );
+        
+        attr1.put( STR_VALUE1, NULL_STRING_VALUE, BIN_VALUE3 );
+        assertEquals( 2, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        assertFalse( attr1.contains( STR_VALUE3 ) );
+        
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        assertEquals( 0, attr2.size() );
+        
+        attr2.put( NULL_BINARY_VALUE );
+        assertEquals( 1, attr2.size() );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+        
+        attr2.put( BIN_VALUE1, BIN_VALUE2, BIN_VALUE3 );
+        assertEquals( 3, attr2.size() );
+        assertTrue( attr2.contains( BIN_VALUE1 ) );
+        assertTrue( attr2.contains( BIN_VALUE2 ) );
+        assertTrue( attr2.contains( BIN_VALUE3 ) );
+        
+        attr2.put( BIN_VALUE1, NULL_BINARY_VALUE, STR_VALUE3 );
+        assertEquals( 2, attr2.size() );
+        assertTrue( attr2.contains( BIN_VALUE1 ) );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+        assertFalse( attr2.contains( BIN_VALUE3 ) );
+    }
+
+
+    /**
+     * Test method put( List&lt;Value&gt; )
+     */
+    @Test
+    public void testPutListOfValues()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        
+        assertEquals( 0, attr1.size() );
+        
+        List<Value<?>> list = new ArrayList<Value<?>>();
+        list.add( NULL_STRING_VALUE );
+        
+        attr1.put( list );
+        assertEquals( 1, attr1.size() );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        
+        list.clear();
+        list.add( STR_VALUE1 );
+        list.add( STR_VALUE2 );
+        list.add( STR_VALUE3 );
+        attr1.put( list );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( STR_VALUE2 ) );
+        assertTrue( attr1.contains( STR_VALUE3 ) );
+
+        list.clear();
+        list.add( STR_VALUE1 );
+        list.add( NULL_STRING_VALUE );
+        list.add( STR_VALUE3 );
+        attr1.put( list );
+        assertEquals( 3, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        assertTrue( attr1.contains( STR_VALUE3 ) );
+        
+        list.clear();
+        list.add( STR_VALUE1 );
+        list.add( NULL_STRING_VALUE );
+        list.add( BIN_VALUE3 );
+        attr1.put( list );
+        assertEquals( 2, attr1.size() );
+        assertTrue( attr1.contains( STR_VALUE1 ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+        assertFalse( attr1.contains( STR_VALUE3 ) );
+        
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+        assertEquals( 0, attr2.size() );
+        
+        list.clear();
+        list.add( NULL_BINARY_VALUE );
+        attr2.put( list );
+        assertEquals( 1, attr2.size() );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+        
+        list.clear();
+        list.add( BIN_VALUE1 );
+        list.add( BIN_VALUE2 );
+        list.add( BIN_VALUE3 );
+        attr2.put( list );
+        assertEquals( 3, attr2.size() );
+        assertTrue( attr2.contains( BIN_VALUE1 ) );
+        assertTrue( attr2.contains( BIN_VALUE2 ) );
+        assertTrue( attr2.contains( BIN_VALUE3 ) );
+        
+        list.clear();
+        list.add( BIN_VALUE1 );
+        list.add( NULL_BINARY_VALUE );
+        list.add( STR_VALUE3 );
+        attr2.put( list );
+        assertEquals( 2, attr2.size() );
+        assertTrue( attr2.contains( BIN_VALUE1 ) );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+        assertFalse( attr2.contains( BIN_VALUE3 ) );
+    }
+
+
+    /**
+     * Test method remove( Value... )
+     */
+    @Test
+    public void testRemoveValueArray() throws InvalidAttributeValueException, NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+
+        assertFalse( attr1.remove( STR_VALUE1 ) );
+
+        attr1.setHR( true );
+        assertFalse( attr1.remove( STR_VALUE1 ) );
+        
+        attr1.put( "a", "b", "c" );
+        assertTrue( attr1.remove( STR_VALUE1 ) );
+        assertEquals( 2, attr1.size() );
+        
+        assertTrue( attr1.remove( STR_VALUE2, STR_VALUE3 ) );
+        assertEquals( 0, attr1.size() );
+        
+        assertFalse( attr1.remove( STR_VALUE4 ) );
+        
+        attr1.put( "a", "b", "c" );
+        assertFalse( attr1.remove( STR_VALUE2, STR_VALUE4 ) );
+        assertEquals( 2, attr1.size() );
+        
+        attr1.clear();
+        attr1.put( "a", (String)null, "b" );
+        assertTrue( attr1.remove( NULL_STRING_VALUE, STR_VALUE1 ) );
+        assertEquals( 1, attr1.size() );
+        
+        attr1.clear();
+        attr1.put( "a", (String)null, "b" );
+        attr1.add( BYTES3 );
+        assertFalse( attr1.remove( NULL_STRING_VALUE, STR_VALUE1, BIN_VALUE3 ) );
+        assertEquals( 1, attr1.size() );
+        
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd );
+
+        assertFalse( attr2.remove( BIN_VALUE1 ) );
+
+        attr2.setHR( true );
+        assertFalse( attr2.remove( BIN_VALUE1 ) );
+        
+        attr2.put( BYTES1, BYTES2, BYTES3 );
+        assertTrue( attr2.remove( BIN_VALUE1 ) );
+        assertEquals( 2, attr2.size() );
+        
+        assertTrue( attr2.remove( BIN_VALUE2, BIN_VALUE3 ) );
+        assertEquals( 0, attr2.size() );
+        
+        assertFalse( attr2.remove( BIN_VALUE4 ) );
+        
+        attr2.put( BYTES1, BYTES2, BYTES3 );
+        assertFalse( attr2.remove( BIN_VALUE2, STR_VALUE4 ) );
+        assertEquals( 2, attr2.size() );
+        
+        attr2.clear();
+        attr2.put( BYTES1, (byte[])null, BYTES3 );
+        assertFalse( attr2.remove( NULL_STRING_VALUE, BIN_VALUE1 ) );
+        assertEquals( 2, attr2.size() );
+        
+        attr2.clear();
+        attr2.put( BYTES1, (byte[])null, BYTES2 );
+        attr2.add( "c" );
+        assertFalse( attr2.remove( NULL_STRING_VALUE, BIN_VALUE1, STR_VALUE3 ) );
+        assertEquals( 2, attr2.size() );
+    }
+
+
+    /**
+     * Test method remove( byte... )
+     */
+    @Test
+    public void testRemoveByteArray() throws InvalidAttributeValueException, NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd );
+
+        assertFalse( attr1.remove( BYTES1 ) );
+
+        attr1.put( BYTES1, BYTES2, BYTES3 );
+        assertTrue( attr1.remove( BYTES1 ) );
+        assertEquals( 2, attr1.size() );
+        
+        assertTrue( attr1.remove( BYTES2, BYTES3 ) );
+        assertEquals( 0, attr1.size() );
+        
+        assertFalse( attr1.remove( BYTES4 ) );
+        
+        attr1.put( BYTES1, BYTES2, BYTES3 );
+        assertFalse( attr1.remove( BYTES3, BYTES4 ) );
+        assertEquals( 2, attr1.size() );
+        
+        attr1.clear();
+        attr1.put( BYTES1, (byte[])null, BYTES2 ) ;
+        assertTrue( attr1.remove( (byte[])null, BYTES1 ) );
+        assertEquals( 1, attr1.size() );
+    }
+
+
+    /**
+     * Test method remove( String... )
+     */
+    @Test
+    public void testRemoveStringArray() throws InvalidAttributeValueException, NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+
+        assertFalse( attr1.remove( "a" ) );
+
+        attr1.setHR( true );
+        assertFalse( attr1.remove( "a" ) );
+        
+        attr1.put( "a", "b", "c" );
+        assertTrue( attr1.remove( "a" ) );
+        assertEquals( 2, attr1.size() );
+        
+        assertTrue( attr1.remove( "b", "c" ) );
+        assertEquals( 0, attr1.size() );
+        
+        assertFalse( attr1.remove( "d" ) );
+        
+        attr1.put( "a", "b", "c" );
+        assertFalse( attr1.remove( "b", "e" ) );
+        assertEquals( 2, attr1.size() );
+        
+        attr1.clear();
+        attr1.put( "a", (String)null, "b" );
+        assertTrue( attr1.remove( (String )null, "a" ) );
+        assertEquals( 1, attr1.size() );
+        
+        EntryAttribute attr2 = new DefaultClientAttribute( "test" );
+        
+        attr2.put( BYTES1, BYTES2, BYTES3 );
+        
+        assertFalse( attr2.remove( (String)null ) );
+        assertTrue( attr2.remove( "ab", "c" ) );
+        assertFalse( attr2.remove( "d" ) );
+    }
+
+
+    /**
+     * Test method iterator()
+     */
+    @Test
+    public void testIterator()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN );
+        attr1.add(  "a", "b", "c" );
+        
+        Iterator<Value<?>> iter = attr1.iterator();
+        
+        assertTrue( iter.hasNext() );
+        
+        String[] values = new String[]{ "a", "b", "c" };
+        int pos = 0;
+        
+        for ( Value<?> val:attr1 )
+        {
+            assertTrue( val instanceof ServerStringValue );
+            assertEquals( values[pos++], val.get() );
+        }
+    }
+
+
+    /**
+     * Test method toString
+     */
+    @Test
+    public void testToString()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        assertEquals( "    cn: (null)\n", attr.toString() );
+        
+        attr.setUpId( "CommonName" );
+        assertEquals( "    CommonName: (null)\n", attr.toString() );
+        
+        attr.add( (String)null );
+        assertEquals( "    CommonName: 'null'\n", attr.toString() );
+
+        attr.put( "a", "b" );
+        assertEquals( "    CommonName: 'a'\n    CommonName: 'b'\n", attr.toString() );
+    }
+
+
+    /**
+     * Test method instanceOf()
+     */
+    @Test
+    public void testInstanceOf() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        assertTrue( attr.instanceOf( "CommonName" ) );
+        assertTrue( attr.instanceOf( "2.5.4.3" ) );
+        assertTrue( attr.instanceOf( "  Cn  " ) );
+        assertFalse( attr.instanceOf( "  " ) );
+        assertFalse( attr.instanceOf( "sn" ) );
+        assertFalse( attr.instanceOf( "name" ) );
+    }
+
+
+    /**
+     * Test method setUpId( String, AttributeType )
+     */
+    @Test
+    public void testSetUpIdStringAttributeType() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atSN );
+        
+        attr.setUpId( null, atCN );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  ", atCN );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  CN  ", atCN );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "CN", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  CommonName  ", atCN );
+        assertEquals( "commonname", attr.getId() );
+        assertEquals( "CommonName", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  2.5.4.3  ", atCN );
+        assertEquals( "2.5.4.3", attr.getId() );
+        assertEquals( "2.5.4.3", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        // Check with wrong IDs
+        try
+        {
+            attr.setUpId( "sn", atCN );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+
+        try
+        {
+            attr.setUpId( "  2.5.4.4  ", atCN );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+    }
+
+
+    /**
+     * Test method setUpId( String ) inherited from ClientAttribute
+     */
+    @Test
+    public void testSetUpIdString() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        attr.setUpId( "cn" );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  CN  " );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "CN", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  CommonName  ");
+        assertEquals( "commonname", attr.getId() );
+        assertEquals( "CommonName", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  2.5.4.3  " );
+        assertEquals( "2.5.4.3", attr.getId() );
+        assertEquals( "2.5.4.3", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+        
+        // Now check wrong IDs
+        attr = new DefaultServerAttribute( atCN );
+        attr.setUpId( "sn" );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  SN  " );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  surname  " );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+
+        attr.setUpId( "  2.5.4.4  " );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+    }
+
+
+    /**
+     * Test method setAttributeType( AttributeType )
+     */
+    @Test
+    public void testSetAttributeType() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        try
+        {
+            attr.setAttributeType( null );
+            fail();
+        }
+        catch ( IllegalArgumentException iae )
+        {
+            assertTrue( true );
+        }
+        
+        attr.setAttributeType( atSN );
+        
+        assertTrue( attr.instanceOf( "Surname" ) );
+        assertEquals( "sn", attr.getId() );
+    }
+
+
+    /**
+     * Test method getAttributeType()
+     */
+    @Test
+    public void testGetAttributeType() throws NamingException
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atSN );
+        
+        assertEquals( atSN, attr.getAttributeType() );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( AttributeType )
+     */
+    @Test
+    public void testDefaultServerAttributeAttributeType()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        assertTrue( attr.isHR() );
+        assertEquals( 0, attr.size() );
+        assertEquals( "cn", attr.getId() );
+        assertEquals( "cn", attr.getUpId() );
+        assertEquals( atCN, attr.getAttributeType() );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( String, AttributeType )
+     */
+    @Test
+    public void testDefaultServerAttributeStringAttributeType()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( "cn", atCN );
+        
+        assertTrue( attr1.isHR() );
+        assertEquals( 0, attr1.size() );
+        assertEquals( "cn", attr1.getId() );
+        assertEquals( "cn", attr1.getUpId() );
+        assertEquals( atCN, attr1.getAttributeType() );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( "  CommonName  ", atCN );
+        
+        assertTrue( attr2.isHR() );
+        assertEquals( 0, attr2.size() );
+        assertEquals( "commonname", attr2.getId() );
+        assertEquals( "CommonName", attr2.getUpId() );
+        assertEquals( atCN, attr2.getAttributeType() );
+
+        ServerAttribute attr3 = new DefaultServerAttribute( "  ", atCN );
+        
+        assertTrue( attr3.isHR() );
+        assertEquals( 0, attr3.size() );
+        assertEquals( "cn", attr3.getId() );
+        assertEquals( "cn", attr3.getUpId() );
+        assertEquals( atCN, attr3.getAttributeType() );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( AttributeType, Value... )
+     */
+    @Test
+    public void testDefaultServerAttributeAttributeTypeValueArray() throws NamingException
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "cn", attr1.getId() );
+        assertEquals( "cn", attr1.getUpId() );
+        assertEquals( atCN, attr1.getAttributeType() );
+        assertTrue( attr1.contains( "a", "b" ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr2.isHR() );
+        assertEquals( 2, attr2.size() );
+        assertEquals( "cn", attr2.getId() );
+        assertEquals( "cn", attr2.getUpId() );
+        assertEquals( atCN, attr2.getAttributeType() );
+        assertTrue( attr2.contains( "a" ) );
+        assertTrue( attr2.contains( NULL_STRING_VALUE ) );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( String, AttributeType, Value... )
+     */
+    @Test
+    public void testDefaultServerAttributeStringAttributeTypeValueArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( "cn", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "cn", attr1.getId() );
+        assertEquals( "cn", attr1.getUpId() );
+        assertEquals( atCN, attr1.getAttributeType() );
+        assertTrue( attr1.contains( "a", "b" ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr2.isHR() );
+        assertEquals( 2, attr2.size() );
+        assertEquals( "cn", attr2.getId() );
+        assertEquals( "cn", attr2.getUpId() );
+        assertEquals( atCN, attr2.getAttributeType() );
+        assertTrue( attr2.contains( "a" ) );
+        assertTrue( attr2.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr3 = new DefaultServerAttribute( "CommonName", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr3.isHR() );
+        assertEquals( 3, attr3.size() );
+        assertEquals( "commonname", attr3.getId() );
+        assertEquals( "CommonName", attr3.getUpId() );
+        assertEquals( atCN, attr3.getAttributeType() );
+        assertTrue( attr3.contains( "a", "b" ) );
+        assertTrue( attr3.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr4 = new DefaultServerAttribute( " 2.5.4.3 ", atCN, STR_VALUE1, STR_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr4.isHR() );
+        assertEquals( 3, attr4.size() );
+        assertEquals( "2.5.4.3", attr4.getId() );
+        assertEquals( "2.5.4.3", attr4.getUpId() );
+        assertEquals( atCN, attr4.getAttributeType() );
+        assertTrue( attr4.contains( "a", "b" ) );
+        assertTrue( attr4.contains( NULL_STRING_VALUE ) );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( AttributeType, String... ) 
+     */
+    @Test
+    public void testDefaultServerAttributeAttributeTypeStringArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atCN, "a", "b", (String)null );
+        
+        assertTrue( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "cn", attr1.getId() );
+        assertEquals( "cn", attr1.getUpId() );
+        assertEquals( atCN, attr1.getAttributeType() );
+        assertTrue( attr1.contains( "a", "b" ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atCN, STR_VALUE1, BIN_VALUE2, NULL_STRING_VALUE );
+        
+        assertTrue( attr2.isHR() );
+        assertEquals( 2, attr2.size() );
+        assertEquals( "cn", attr2.getId() );
+        assertEquals( "cn", attr2.getUpId() );
+        assertEquals( atCN, attr2.getAttributeType() );
+        assertTrue( attr2.contains( "a" ) );
+        assertTrue( attr2.contains( NULL_STRING_VALUE ) );
+    }
+
+
+    /**
+     * Test constructor DefaultServerAttribute( String, AttributeType, String... )
+     */
+    @Test
+    public void testDefaultServerAttributeStringAttributeTypeStringArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( "cn", atCN, "a", "b", (String)null );
+        
+        assertTrue( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "cn", attr1.getId() );
+        assertEquals( "cn", attr1.getUpId() );
+        assertEquals( atCN, attr1.getAttributeType() );
+        assertTrue( attr1.contains( "a", "b" ) );
+        assertTrue( attr1.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( "CommonName", atCN, "a", "b", (String)null );
+        
+        assertTrue( attr2.isHR() );
+        assertEquals( 3, attr2.size() );
+        assertEquals( "commonname", attr2.getId() );
+        assertEquals( "CommonName", attr2.getUpId() );
+        assertEquals( atCN, attr2.getAttributeType() );
+        assertTrue( attr2.contains( "a", "b" ) );
+        assertTrue( attr2.contains( NULL_STRING_VALUE ) );
+
+        ServerAttribute attr3 = new DefaultServerAttribute( " 2.5.4.3 ", atCN, "a", "b", (String)null );
+        
+        assertTrue( attr3.isHR() );
+        assertEquals( 3, attr3.size() );
+        assertEquals( "2.5.4.3", attr3.getId() );
+        assertEquals( "2.5.4.3", attr3.getUpId() );
+        assertEquals( atCN, attr3.getAttributeType() );
+        assertTrue( attr3.contains( "a", "b" ) );
+        assertTrue( attr3.contains( NULL_STRING_VALUE ) );
+    }
+
+
+    /**
+     * Test method DefaultServerAttribute( AttributeType, byte[]... ) 
+     */
+    @Test
+    public void testDefaultServerAttributeAttributeTypeByteArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( atPwd, BYTES1, BYTES2, (byte[])null );
+        
+        assertFalse( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "userpassword", attr1.getId() );
+        assertEquals( "userPassword", attr1.getUpId() );
+        assertEquals( atPwd, attr1.getAttributeType() );
+        assertTrue( attr1.contains( BYTES1, BYTES2 ) );
+        assertTrue( attr1.contains( NULL_BINARY_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( atPwd, STR_VALUE1, BIN_VALUE2, NULL_BINARY_VALUE );
+        
+        assertFalse( attr2.isHR() );
+        assertEquals( 2, attr2.size() );
+        assertEquals( "userpassword", attr2.getId() );
+        assertEquals( "userPassword", attr2.getUpId() );
+        assertEquals( atPwd, attr2.getAttributeType() );
+        assertTrue( attr2.contains( BYTES2 ) );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+    }
+
+
+    /**
+     * Test method DefaultServerAttribute( String, AttributeType, byte[]... )
+     */
+    @Test
+    public void testDefaultServerAttributeStringAttributeTypeByteArray()
+    {
+        ServerAttribute attr1 = new DefaultServerAttribute( "userPassword", atPwd, BYTES1, BYTES2, (byte[])null );
+        
+        assertFalse( attr1.isHR() );
+        assertEquals( 3, attr1.size() );
+        assertEquals( "userpassword", attr1.getId() );
+        assertEquals( "userPassword", attr1.getUpId() );
+        assertEquals( atPwd, attr1.getAttributeType() );
+        assertTrue( attr1.contains( BYTES1, BYTES2 ) );
+        assertTrue( attr1.contains( NULL_BINARY_VALUE ) );
+
+        ServerAttribute attr2 = new DefaultServerAttribute( "2.5.4.35", atPwd, STR_VALUE1, BIN_VALUE2, NULL_BINARY_VALUE );
+        
+        assertFalse( attr2.isHR() );
+        assertEquals( 2, attr2.size() );
+        assertEquals( "2.5.4.35", attr2.getId() );
+        assertEquals( "2.5.4.35", attr2.getUpId() );
+        assertEquals( atPwd, attr2.getAttributeType() );
+        assertTrue( attr2.contains( BYTES2 ) );
+        assertTrue( attr2.contains( NULL_BINARY_VALUE ) );
+    }
+
+
+    /**
+     * Test method testClone()
+     */
+    @Test
+    public void testClone()
+    {
+        ServerAttribute attr = new DefaultServerAttribute( atCN );
+        
+        EntryAttribute clone = attr.clone();
+        
+        assertEquals( attr, clone );
+        attr.setUpId( "CommonName" );
+        assertEquals( "cn", clone.getId() );
+        
+        attr.add( "a", (String)null, "b" );
+        clone = attr.clone();
+        assertEquals( attr, clone );
+        
+        attr.remove( "a" );
+        assertNotSame( attr, clone );
+        
+        clone = attr.clone();
+        assertEquals( attr, clone );
     }
 }

Modified: directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java?rev=637318&r1=637317&r2=637318&view=diff
==============================================================================
--- directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java (original)
+++ directory/apacheds/branches/bigbang/core-entry/src/test/java/org/apache/directory/server/core/entry/DefaultServerEntryTest.java Fri Mar 14 17:56:26 2008
@@ -29,7 +29,6 @@
 import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 import javax.naming.directory.BasicAttributes;
-import javax.naming.directory.InvalidAttributeValueException;
 
 import org.apache.directory.server.schema.bootstrap.ApacheSchema;
 import org.apache.directory.server.schema.bootstrap.ApachemetaSchema;
@@ -90,7 +89,6 @@
         bootstrapSchemas.add( new InetorgpersonSchema() );
         bootstrapSchemas.add( new CosineSchema() );
         loader.loadWithDependencies( bootstrapSchemas, registries );
-        
     }
 
 
@@ -196,8 +194,8 @@
         assertEquals( 0, result.size() );
         ServerAttribute sa = entry.get( "sn" );
         assertNotNull( sa );
-        assertEquals( atSN, sa.getType() );
-        assertEquals( "sn", sa.getType().getName() );
+        assertEquals( atSN, sa.getAttributeType() );
+        assertEquals( "sn", sa.getAttributeType().getName() );
         
         // Add two AT now
         AttributeType atL = registries.getAttributeTypeRegistry().lookup( "localityName" );
@@ -211,23 +209,23 @@
         assertEquals( 0, result.size() );
         sa = entry.get( "l" );
         assertNotNull( sa );
-        assertEquals( atL, sa.getType() );
-        assertEquals( "l", sa.getType().getName() );
+        assertEquals( atL, sa.getAttributeType() );
+        assertEquals( "l", sa.getAttributeType().getName() );
 
         sa = entry.get( "c" );
         assertNotNull( sa );
-        assertEquals( atC, sa.getType() );
-        assertEquals( "c", sa.getType().getName() );
+        assertEquals( atC, sa.getAttributeType() );
+        assertEquals( "c", sa.getAttributeType().getName() );
 
         sa = entry.get( "2.5.4.9" );
         assertNotNull( sa );
-        assertEquals( atStreet, sa.getType() );
-        assertEquals( "street", sa.getType().getName() );
+        assertEquals( atStreet, sa.getAttributeType() );
+        assertEquals( "street", sa.getAttributeType().getName() );
 
         sa = entry.get( "givenName" );
         assertNotNull( sa );
-        assertEquals( atGN, sa.getType() );
-        assertEquals( "givenName", sa.getType().getName() );
+        assertEquals( atGN, sa.getAttributeType() );
+        assertEquals( "givenName", sa.getAttributeType().getName() );
         
         // Now try to add existing ATs
         // First, set some value to the modified AT
@@ -253,7 +251,7 @@
 
         ServerAttribute oc = entry.get( "objectClass" );
         
-        assertEquals( OBJECT_CLASS_AT, oc.getType() );
+        assertEquals( OBJECT_CLASS_AT, oc.getAttributeType() );
         assertNull( oc.get() );
     }
 
@@ -304,7 +302,7 @@
 
         ServerAttribute sa = entry.get( "sn" );
         assertNotNull( sa );
-        assertEquals( "sn", sa.getType().getName() );
+        assertEquals( "sn", sa.getAttributeType().getName() );
         
         // Add different upIds now
         AttributeType atL = registries.getAttributeTypeRegistry().lookup( "localityName" );
@@ -320,26 +318,26 @@
 
         sa = entry.get( "l" );
         assertNotNull( sa );
-        assertEquals( atL, sa.getType() );
-        assertEquals( "l", sa.getType().getName() );
+        assertEquals( atL, sa.getAttributeType() );
+        assertEquals( "l", sa.getAttributeType().getName() );
         assertEquals( "L", sa.getUpId() );
 
         sa = entry.get( "c" );
         assertNotNull( sa );
-        assertEquals( atC, sa.getType() );
-        assertEquals( "c", sa.getType().getName() );
+        assertEquals( atC, sa.getAttributeType() );
+        assertEquals( "c", sa.getAttributeType().getName() );
         assertEquals( "CountryName", sa.getUpId() );
 
         sa = entry.get( "2.5.4.9" );
         assertNotNull( sa );
-        assertEquals( atStreet, sa.getType() );
-        assertEquals( "street", sa.getType().getName() );
+        assertEquals( atStreet, sa.getAttributeType() );
+        assertEquals( "street", sa.getAttributeType().getName() );
         assertEquals( "2.5.4.9", sa.getUpId() );
 
         sa = entry.get( "givenName" );
         assertNotNull( sa );
-        assertEquals( atGN, sa.getType() );
-        assertEquals( "givenName", sa.getType().getName() );
+        assertEquals( atGN, sa.getAttributeType() );
+        assertEquals( "givenName", sa.getAttributeType().getName() );
         assertEquals( "gn", sa.getUpId() );
         
         // Now try to add existing ATs
@@ -433,7 +431,7 @@
         ServerAttribute newOc = entry.get( "objectClass" );
         
         assertNotNull( newOc );
-        assertEquals( OBJECT_CLASS_AT, newOc.getType() );
+        assertEquals( OBJECT_CLASS_AT, newOc.getAttributeType() );
         assertEquals( 2, newOc.size() );
         assertEquals( "OBJECTCLASS", newOc.getUpId() );
         assertTrue( newOc.contains( "person", "inetOrgPerson" ) );
@@ -778,34 +776,27 @@
         entry.put( "commonName", atCN, (String)null );
         assertEquals( 1, entry.size() );
         assertEquals( "commonName", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
         // Check that we can use a null AttributeType
         entry.put( "commonName", (AttributeType)null, (String)null );
         assertEquals( 1, entry.size() );
         assertEquals( "commonName", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
         // Test that we can use a null upId
         entry.put( null, atCN, (String)null );
         assertEquals( 1, entry.size() );
         assertEquals( "cn", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
-        // Test that we can't use an upId which is not compatible
-        // with the AT
-        try
-        {
-            entry.put( "sn", atCN, (String)null );
-            fail();
-        }
-        catch( IllegalArgumentException iae )
-        {
-            assertTrue( true );
-        }
+        // Test that if we use an upId which is not compatible
+        // with the AT, it is changed to the AT default name
+        entry.put( "sn", atCN, (String)null );
+        assertEquals( "cn", entry.get( atCN ).getId() );
         
         // Test that we can add some new attributes with values
         ServerAttribute result = entry.put( "CN", atCN, "test1", "test2", "test3" );
@@ -845,7 +836,7 @@
         entry.put( "userPassword", atPassword, (byte[])null );
         assertEquals( 1, entry.size() );
         assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
-        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertEquals( "userPassword", entry.get( atPassword ).getAttributeType().getName() );
         assertNull( entry.get( atPassword ).get().get() );
         
         // Check that we can use a null AttributeType
@@ -861,27 +852,20 @@
         
         assertEquals( 1, entry.size() );
         assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
-        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertEquals( "userPassword", entry.get( atPassword ).getAttributeType().getName() );
         assertNull( entry.get( atPassword ).get().get() );
         
         // Test that we can use a null upId
         entry.put( null, atPassword, (byte[])null );
         assertEquals( 1, entry.size() );
         assertEquals( "userPassword", entry.get( atPassword ).getUpId() );
-        assertEquals( "userPassword", entry.get( atPassword ).getType().getName() );
+        assertEquals( "userPassword", entry.get( atPassword ).getAttributeType().getName() );
         assertNull( entry.get( atPassword ).get().get() );
         
-        // Test that we can't use an upId which is not compatible
-        // with the AT
-        try
-        {
-            entry.put( "sn", atPassword, (byte[])null );
-            fail();
-        }
-        catch( IllegalArgumentException iae )
-        {
-            assertTrue( true );
-        }
+        // Test that if we use an upId which is not compatible
+        // with the AT, it is changed to the AT default name
+        entry.put( "sn", atPassword, (byte[])null );
+        assertEquals( "userpassword", entry.get( atPassword ).getId() );
         
         // Test that we can add some new attributes with values
         byte[] test1 = StringTools.getBytesUtf8( "test1" );
@@ -926,21 +910,21 @@
         entry.put( "commonName", atCN, (Value<?>)null );
         assertEquals( 1, entry.size() );
         assertEquals( "commonName", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
         // Check that we can use a null AttributeType
         entry.put( "commonName", (AttributeType)null, (Value<?>)null );
         assertEquals( 1, entry.size() );
         assertEquals( "commonName", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
         // Test that we can use a null upId
         entry.put( null, atCN, (Value<?>)null );
         assertEquals( 1, entry.size() );
         assertEquals( "cn", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
         
         // Test that we can't use an upId which is not compatible
@@ -997,7 +981,7 @@
         entry.put( "commonName", (Value<?>)null );
         assertEquals( 1, entry.size() );
         assertEquals( "commonName", entry.get( atCN ).getUpId() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertNull( entry.get( atCN ).get().get() );
 
         // Test that we can add some new attributes with values
@@ -1067,15 +1051,8 @@
         // Test the addition of a binary value
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
         
-        try
-        {
-            entry.add( atCN, test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( atCN, test4 );
+        assertFalse( entry.get( atCN ).contains( test4 ) );
     }
 
 
@@ -1131,8 +1108,8 @@
 
         entry.add( atPassword, "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, test4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, test4 ) );
     }
 
 
@@ -1195,15 +1172,8 @@
         // Test the addition of a String value. It should be converted to a byte array
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
 
-        try
-        {
-            entry.add( atCN, test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( atCN, test4 );
+        assertFalse( entry.contains( atCN, test4 ) );
 
         // Now, work with a binary attribute
         // Test a simple addition
@@ -1244,8 +1214,8 @@
 
         entry.add( atPassword, "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, b4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, b4 ) );
     }
 
 
@@ -1262,8 +1232,8 @@
         // Test a simple addition
         entry.add( "CN", "test1" );
         assertNotNull( entry.get( atCN ) );
-        assertEquals( atCN, entry.get( atCN ).getType() );
-        assertEquals( "cn", entry.get( atCN ).getType().getName() );
+        assertEquals( atCN, entry.get( atCN ).getAttributeType() );
+        assertEquals( "cn", entry.get( atCN ).getAttributeType().getName() );
         assertEquals( "CN", entry.get( atCN ).getUpId() );
         assertEquals( 1, entry.get( atCN ).size() );
         assertEquals( "test1", entry.get( atCN ).get().get() );
@@ -1298,15 +1268,8 @@
         // Test the addition of a binary value
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
         
-        try
-        {
-            entry.add( "CN", test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( "CN", test4 );
+        assertFalse( entry.contains(  "CN", test4 ) );
     }
 
 
@@ -1362,8 +1325,8 @@
 
         entry.add( "userPassword", "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, test4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, test4 ) );
     }
 
 
@@ -1395,7 +1358,7 @@
         assertNotNull( entry.get( atCN ) );
         assertEquals( 1, entry.get( atCN ).size() );
         assertEquals( "test1", entry.get( atCN ).get().get() );
-        assertEquals( atCN, entry.get( atCN ).getType() );
+        assertEquals( atCN, entry.get( atCN ).getAttributeType() );
         assertEquals( "cN", entry.get( atCN ).getUpId() );
         
         // Test some more addition
@@ -1405,7 +1368,7 @@
         assertTrue( entry.contains( atCN, "test1" ) );
         assertTrue( entry.contains( atCN, "test2" ) );
         assertTrue( entry.contains( atCN, "test3" ) );
-        assertEquals( atCN, entry.get( atCN ).getType() );
+        assertEquals( atCN, entry.get( atCN ).getAttributeType() );
         assertEquals( "cN", entry.get( atCN ).getUpId() );
         
         // Test some addition of existing values
@@ -1430,15 +1393,8 @@
         // Test the addition of a String value. It should be converted to a byte array
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
 
-        try
-        {
-            entry.add( "cN", test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( "cN", test4 );
+        assertFalse( entry.contains( "cN", test4 ) );
 
         // Now, work with a binary attribute
         // Test a simple addition
@@ -1446,7 +1402,7 @@
         assertNotNull( entry.get( atPassword ) );
         assertEquals( 1, entry.get( atPassword ).size() );
         assertTrue( Arrays.equals( b1, (byte[])entry.get( atPassword ).get().get() ) );
-        assertEquals( atPassword, entry.get( atPassword ).getType() );
+        assertEquals( atPassword, entry.get( atPassword ).getAttributeType() );
         assertEquals( "userPASSWORD", entry.get( atPassword ).getUpId() );
         
         // Test some more addition
@@ -1481,8 +1437,8 @@
 
         entry.add( "userPASSWORD", "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, b4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, b4 ) );
     }
 
 
@@ -1532,15 +1488,8 @@
         // Test the addition of a binary value
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
         
-        try
-        {
-            entry.add( "cn", atCN, test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( "cn", atCN, test4 );
+        assertFalse( entry.contains( "cn", test4 ) );
     }
 
 
@@ -1596,8 +1545,8 @@
 
         entry.add( "userPassword", atPassword, "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, test4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, test4 ) );
     }
 
 
@@ -1629,7 +1578,7 @@
         assertNotNull( entry.get( atCN ) );
         assertEquals( 1, entry.get( atCN ).size() );
         assertEquals( "test1", entry.get( atCN ).get().get() );
-        assertEquals( atCN, entry.get( atCN ).getType() );
+        assertEquals( atCN, entry.get( atCN ).getAttributeType() );
         assertEquals( "cN", entry.get( atCN ).getUpId() );
         
         // Test some more addition
@@ -1639,7 +1588,7 @@
         assertTrue( entry.contains( atCN, "test1" ) );
         assertTrue( entry.contains( atCN, "test2" ) );
         assertTrue( entry.contains( atCN, "test3" ) );
-        assertEquals( atCN, entry.get( atCN ).getType() );
+        assertEquals( atCN, entry.get( atCN ).getAttributeType() );
         assertEquals( "cN", entry.get( atCN ).getUpId() );
         
         // Test some addition of existing values
@@ -1664,15 +1613,8 @@
         // Test the addition of a String value. It should be converted to a byte array
         byte[] test4 = StringTools.getBytesUtf8( "test4" );
 
-        try
-        {
-            entry.add( "cN", atCN, test4 );
-            fail();
-        }
-        catch ( InvalidAttributeValueException iave )
-        {
-            assertTrue( true );
-        }
+        entry.add( "cN", atCN, test4 );
+        assertFalse( entry.contains( "cN", test4 ) );
 
         // Now, work with a binary attribute
         // Test a simple addition
@@ -1680,7 +1622,7 @@
         assertNotNull( entry.get( atPassword ) );
         assertEquals( 1, entry.get( atPassword ).size() );
         assertTrue( Arrays.equals( b1, (byte[])entry.get( atPassword ).get().get() ) );
-        assertEquals( atPassword, entry.get( atPassword ).getType() );
+        assertEquals( atPassword, entry.get( atPassword ).getAttributeType() );
         assertEquals( "userPASSWORD", entry.get( atPassword ).getUpId() );
         
         // Test some more addition
@@ -1715,8 +1657,8 @@
 
         entry.add( "userPASSWORD", atPassword, "test4" );
         assertNotNull( entry.get( atPassword ) );
-        assertEquals( 1, entry.get( atPassword ).size() );
-        assertTrue( entry.contains( atPassword, b4 ) );
+        assertEquals( 0, entry.get( atPassword ).size() );
+        assertFalse( entry.contains( atPassword, b4 ) );
     }
 
     //-------------------------------------------------------------------------



Mime
View raw message