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 2010/07/30 20:39:34 UTC

svn commit: r980915 - in /directory: apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/

Author: elecharny
Date: Fri Jul 30 18:39:34 2010
New Revision: 980915

URL: http://svn.apache.org/viewvc?rev=980915&view=rev
Log:
Added a ModifyRequest.replace( String ) method

Modified:
    directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/ModifyRequest.java

Modified: directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java?rev=980915&r1=980914&r2=980915&view=diff
==============================================================================
--- directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java (original)
+++ directory/apacheds/trunk/ldap-client-test/src/test/java/org/apache/directory/shared/client/api/operations/ClientModifyRequestTest.java Fri Jul 30 18:39:34 2010
@@ -6,22 +6,23 @@
  *  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. 
- *  
+ *  under the License.
+ *
  */
 package org.apache.directory.shared.client.api.operations;
 
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -44,6 +45,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.csn.CsnFactory;
 import org.apache.directory.shared.ldap.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.entry.Entry;
+import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
@@ -60,18 +62,18 @@ import org.junit.runner.RunWith;
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 @RunWith(FrameworkRunner.class)
-@CreateLdapServer ( 
-    transports = 
+@CreateLdapServer (
+    transports =
     {
-        @CreateTransport( protocol = "LDAP" ), 
-        @CreateTransport( protocol = "LDAPS" ) 
+        @CreateTransport( protocol = "LDAP" ),
+        @CreateTransport( protocol = "LDAPS" )
     })
 public class ClientModifyRequestTest extends AbstractLdapTestUnit
 {
     private LdapAsyncConnection connection;
-    
+
     private CoreSession session;
-    
+
     @Before
     public void setup() throws Exception
     {
@@ -80,11 +82,11 @@ public class ClientModifyRequestTest ext
 
         DN bindDn = new DN( "uid=admin,ou=system" );
         connection.bind( bindDn.getName(), "secret" );
-        
+
         session = ldapServer.getDirectoryService().getAdminSession();
     }
 
-    
+
     /**
      * Close the LdapConnection
      */
@@ -104,7 +106,7 @@ public class ClientModifyRequestTest ext
         }
     }
 
-    
+
     @Test
     public void testModify() throws Exception
     {
@@ -128,28 +130,55 @@ public class ClientModifyRequestTest ext
     public void testModifyWithEntry() throws Exception
     {
         DN dn = new DN( "uid=admin,ou=system" );
-        
+
         Entry entry = new DefaultEntry( dn );
-        
+
         String expectedSn = String.valueOf( System.currentTimeMillis() );
         String expectedCn = String.valueOf( System.currentTimeMillis() );
-        
+
         entry.add( SchemaConstants.SN_AT, expectedSn );
-        
+
         entry.add( SchemaConstants.CN_AT, expectedCn );
-        
+
         connection.modify( entry, ModificationOperation.REPLACE_ATTRIBUTE );
-        
+
         Entry lookupEntry = session.lookup( dn );
 
         String actualSn = lookupEntry.get( SchemaConstants.SN_AT ).getString();
         assertEquals( expectedSn, actualSn );
-        
+
         String actualCn = lookupEntry.get( SchemaConstants.CN_AT ).getString();
         assertEquals( expectedCn, actualCn );
     }
-    
-    
+
+
+    @Test
+    public void testModifyReplaceRemove() throws Exception
+    {
+        DN dn = new DN( "uid=admin,ou=system" );
+
+        Entry entry = new DefaultEntry( dn );
+
+        entry.add( "givenName", "test" );
+
+        connection.modify( entry, ModificationOperation.REPLACE_ATTRIBUTE );
+
+        Entry lookupEntry = session.lookup( dn );
+
+        String gn = lookupEntry.get( "givenName" ).getString();
+        assertEquals( "test", gn );
+
+        // Now, replace the givenName
+        ModifyRequest modifyRequest = new ModifyRequest( dn );
+        modifyRequest.replace( "givenName" );
+        connection.modify( modifyRequest );
+
+        lookupEntry = session.lookup( dn );
+        EntryAttribute giveName = lookupEntry.get( "givenName" );
+        assertNull( giveName );
+    }
+
+
     @Test
     public void modifyAsync() throws Exception
     {
@@ -158,15 +187,15 @@ public class ClientModifyRequestTest ext
         String expected = String.valueOf( System.currentTimeMillis() );
         ModifyRequest modRequest = new ModifyRequest( dn );
         modRequest.replace( SchemaConstants.SN_AT, expected );
-        
+
         assertTrue( session.exists( dn ) );
-        
+
         ModifyFuture modifyFuture = connection.modifyAsync( modRequest );
-        
+
         try
         {
             ModifyResponse response = modifyFuture.get( 1000, TimeUnit.MILLISECONDS );
-            
+
             assertNotNull( response );
 
             Entry entry = session.lookup( dn );
@@ -183,8 +212,8 @@ public class ClientModifyRequestTest ext
             fail();
         }
     }
-    
-    
+
+
     /**
      * ApacheDS doesn't allow modifying entryUUID and entryCSN AT
      */
@@ -192,21 +221,21 @@ public class ClientModifyRequestTest ext
     public void testModifyEntryUUIDAndEntryCSN() throws Exception
     {
         DN dn = new DN( "uid=admin,ou=system" );
-        
+
         ModifyRequest modReq = new ModifyRequest( dn );
         modReq.replace( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() );
-        
+
         ModifyResponse modResp = connection.modify( modReq );
         assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, modResp.getLdapResult().getResultCode() );
-        
+
         modReq = new ModifyRequest( dn );
         modReq.replace( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString() );
-        
+
         modResp = connection.modify( modReq );
         assertEquals( ResultCodeEnum.INSUFFICIENT_ACCESS_RIGHTS, modResp.getLdapResult().getResultCode() );
     }
-    
-    
+
+
     /**
      * ApacheDS allows modifying the modifiersName and modifyTimestamp operational AT
      */
@@ -214,19 +243,19 @@ public class ClientModifyRequestTest ext
     public void testModifyModifierNameAndModifyTimestamp() throws Exception
     {
         DN dn = new DN( "uid=admin,ou=system" );
-        
+
         String modifierName = "uid=x,ou=system";
         String modifiedTime = DateUtils.getGeneralizedTime();
 
         ModifyRequest modReq = new ModifyRequest( dn );
         modReq.replace( SchemaConstants.MODIFIERS_NAME_AT, modifierName );
         modReq.replace( SchemaConstants.MODIFY_TIMESTAMP_AT, modifiedTime );
-        
+
         ModifyResponse modResp = connection.modify( modReq );
         assertEquals( ResultCodeEnum.SUCCESS, modResp.getLdapResult().getResultCode() );
-        
+
         Entry loadedEntry = ( ( SearchResultEntry ) connection.lookup( dn.getName(), "+" ) ).getEntry();
-        
+
         assertEquals( modifierName, loadedEntry.get( SchemaConstants.MODIFIERS_NAME_AT ).getString() );
         assertEquals( modifiedTime, loadedEntry.get( SchemaConstants.MODIFY_TIMESTAMP_AT ).getString() );
     }

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/ModifyRequest.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/ModifyRequest.java?rev=980915&r1=980914&r2=980915&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/ModifyRequest.java (original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/message/ModifyRequest.java Fri Jul 30 18:39:34 2010
@@ -25,12 +25,13 @@ import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
-import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.DefaultEntryAttribute;
+import org.apache.directory.shared.ldap.entry.DefaultModification;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.util.StringTools;
 
 
 /**
@@ -48,10 +49,10 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
+     *
      * Creates a new instance of ModifyRequest.
      *
-     * @param dn DN of the Entry to be modified 
+     * @param dn DN of the Entry to be modified
      */
     public ModifyRequest( DN dn )
     {
@@ -61,8 +62,8 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
-     * marks a given attribute for addition in the target entry with the 
+     *
+     * marks a given attribute for addition in the target entry with the
      * given values.
      *
      * @param attributeName name of the attribute to be added
@@ -84,7 +85,7 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
+     *
      * marks a given attribute for addition in the target entry.
      *
      * @param attr the attribute to be added
@@ -96,9 +97,18 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
-     * marks a given attribute for replacement with the given 
-     * values in the target entry. 
+     * @see #replace(String, String...)
+     */
+    public void replace( String attributeName )
+    {
+        addModification( ModificationOperation.REPLACE_ATTRIBUTE, attributeName, StringTools.EMPTY_STRINGS );
+    }
+
+
+    /**
+     *
+     * marks a given attribute for replacement with the given
+     * values in the target entry.
      *
      * @param attributeName name of the attribute to be added
      * @param attributeValue values of the attribute
@@ -110,7 +120,7 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * @see #remove(String, String...)
+     * @see #replace(String, String...)
      */
     public void replace( String attributeName, byte[]... attributeValue )
     {
@@ -119,7 +129,7 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
+     *
      * marks a given attribute for replacement in the target entry.
      *
      * @param attr the attribute to be added
@@ -131,9 +141,9 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
-     * marks a given attribute for removal with the given 
-     * values from the target entry. 
+     *
+     * marks a given attribute for removal with the given
+     * values from the target entry.
      *
      * @param attributeName name of the attribute to be added
      * @param attributeValue values of the attribute
@@ -154,7 +164,7 @@ public class ModifyRequest extends Abstr
 
 
     /**
-     * 
+     *
      * marks a given attribute for removal from the target entry.
      *
      * @param attr the attribute to be added
@@ -189,8 +199,8 @@ public class ModifyRequest extends Abstr
     {
         mods.addAll( Arrays.asList( modifications ) );
     }
-    
-    
+
+
     /**
      * @return the target entry's DN
      */