You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2006/07/28 01:37:07 UTC

svn commit: r426325 - /directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java

Author: elecharny
Date: Thu Jul 27 16:37:07 2006
New Revision: 426325

URL: http://svn.apache.org/viewvc?rev=426325&view=rev
Log:
Added a test for bug DIR_SERVER 664

Modified:
    directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java

Modified: directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java
URL: http://svn.apache.org/viewvc/directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java?rev=426325&r1=426324&r2=426325&view=diff
==============================================================================
--- directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java (original)
+++ directory/branches/apacheds/optimization/server-unit/src/test/java/org/apache/directory/server/ModifyAddTest.java Thu Jul 27 16:37:07 2006
@@ -69,7 +69,7 @@
     /**
      * Create context and a person entry.
      */
-    public void setUp() throws Exception
+    protected void setUp() throws Exception
     {
         super.setUp();
 
@@ -94,7 +94,7 @@
     /**
      * Remove person entry and close context.
      */
-    public void tearDown() throws Exception
+    protected void tearDown() throws Exception
     {
         ctx.unbind( RDN );
         ctx.close();
@@ -110,7 +110,6 @@
      */
     public void testAddNewAttributeValue() throws NamingException
     {
-
         // Add telephoneNumber attribute
         String newValue = "1234567890";
         Attributes attrs = new BasicAttributes( "telephoneNumber", newValue );
@@ -132,7 +131,6 @@
      */
     public void testAddNewAttributeValues() throws NamingException
     {
-
         // Add telephoneNumber attribute
         String[] newValues =
             { "1234567890", "999999999" };
@@ -160,7 +158,6 @@
      */
     public void testAddAdditionalAttributeValue() throws NamingException
     {
-
         // A new description attribute value
         String newValue = "A new description for this person";
         assertFalse( newValue.equals( PERSON_DESCRIPTION ) );
@@ -190,9 +187,9 @@
      */
     public void testAddExistingAttributeValue() throws NamingException
     {
-
         // Change description attribute
         Attributes attrs = new BasicAttributes( "description", PERSON_DESCRIPTION );
+        
         try
         {
             ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, attrs );
@@ -211,6 +208,58 @@
         assertEquals( 1, attr.size() );
     }
 
+    /**
+     * Try to add an already existing attribute value.
+     * 
+     * Expected behaviour: Modify operation fails with an
+     * AttributeInUseException. Original LDAP Error code: 20 (Indicates that the
+     * attribute value specified in a modify or add operation already exists as
+     * a value for that attribute).
+     * 
+     * Check for bug DIR_SERVER664
+     * 
+     * @throws NamingException
+     */
+    public void testAddExistingNthAttributesDirServer664() throws NamingException
+    {
+        // Change description attribute
+        Attributes attrs = new BasicAttributes( true );
+        attrs.put( new BasicAttribute( "attr1", "attr 1" ) );
+        attrs.put( new BasicAttribute( "attr2", "attr 2" ) );
+        attrs.put( new BasicAttribute( "attr3", "attr 3" ) );
+        attrs.put( new BasicAttribute( "attr4", "attr 4" ) );
+        attrs.put( new BasicAttribute( "attr5", "attr 5" ) );
+        attrs.put( new BasicAttribute( "attr6", "attr 6" ) );
+        attrs.put( new BasicAttribute( "attr7", "attr 7" ) );
+        attrs.put( new BasicAttribute( "attr8", "attr 8" ) );
+        attrs.put( new BasicAttribute( "attr9", "attr 9" ) );
+        attrs.put( new BasicAttribute( "attr10", "attr 10" ) );
+        attrs.put( new BasicAttribute( "attr11", "attr 11" ) );
+        attrs.put( new BasicAttribute( "attr12", "attr 12" ) );
+        attrs.put( new BasicAttribute( "attr13", "attr 13" ) );
+        attrs.put( new BasicAttribute( "attr14", "attr 14" ) );
+        
+        Attribute attr = new BasicAttribute( "description", PERSON_DESCRIPTION );
+
+        attrs.put( attr );
+        
+        try
+        {
+            ctx.modifyAttributes( RDN, DirContext.ADD_ATTRIBUTE, attrs );
+            fail( "Adding an already existing atribute value should fail." );
+        }
+        catch ( AttributeInUseException e )
+        {
+            // expected behaviour
+        }
+
+        // Verify, that attribute is still there, and is the only one
+        attrs = ctx.getAttributes( RDN );
+        attr = attrs.get( "description" );
+        assertNotNull( attr );
+        assertTrue( attr.contains( PERSON_DESCRIPTION ) );
+        assertEquals( 1, attr.size() );
+    }
 
     /**
      * Try to add a duplicate attribute value to an entry, where this attribute