You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/05/03 23:42:55 UTC

svn commit: r940636 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/ test/java/org/apache/directory/shared/ldap/codec/controls/replication/

Author: kayyagari
Date: Mon May  3 21:42:55 2010
New Revision: 940636

URL: http://svn.apache.org/viewvc?rev=940636&view=rev
Log:
o added transitions for RENAME and MOVEANDRENAME choices
o added tests for the newly added transitions

Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java?rev=940636&r1=940635&r2=940636&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java (original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncmodifydn/SyncModifyDnControlGrammar.java Mon May  3 21:42:55 2010
@@ -173,45 +173,153 @@ public class SyncModifyDnControlGrammar 
         /**
          * read the newSuperiorDn
          * move-name       [0] LDAPDN
-         *
-        super.transitions[SyncModifyDnControlStatesEnum.MOVE_DN_STATE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
-            SyncModifyDnControlStatesEnum.MOVE_DN_STATE, SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE,
-            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl newSuperiorDn" )
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.ENTRY_DN_STATE][SyncModifyDnControlTags.RENAME_TAG.getValue()] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.ENTRY_DN_STATE, SyncModifyDnControlStatesEnum.RENAME_STATE,
+            SyncModifyDnControlTags.RENAME_TAG.getValue(), new GrammarAction( "enter SyncModifyDnControl rename choice" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer ) container;
+                    syncModifyDnControlContainer.getSyncModifyDnControl().setModDnType( SyncModifyDnType.RENAME );
+
+                    syncModifyDnControlContainer.grammarEndAllowed( false );
+                }
+            } );
+
+        /** 
+         * Transition from rename's RENAME state to newRdn
+         * 
+         * Rename SEQUENCE {
+         *     new-rdn RDN,
+         * }
+         *            
+         * Stores the newRdn value
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.RENAME_STATE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.RENAME_STATE, SyncModifyDnControlStatesEnum.RENAME_NEW_RDN_STATE,
+            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl newRdn value" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
                     SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer ) container;
                     Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
 
-                    String newSuperiorDn = StringTools.utf8ToString( value.getData() );
+                    String newRdn = StringTools.utf8ToString( value.getData() );
 
                     if ( IS_DEBUG )
                     {
-                        LOG.debug( "newSuperiorDn = {}", newSuperiorDn );
+                        LOG.debug( "newRdn = {}", newRdn );
                     }
 
-                    syncModifyDnControlContainer.getSyncModifyDnControl().setNewSuperiorDn( newSuperiorDn );
+                    syncModifyDnControlContainer.getSyncModifyDnControl().setNewRdn( newRdn );
 
-                    // We can have an END transition
-                    syncModifyDnControlContainer.grammarEndAllowed( true );
+                    // terminal state
+                    syncModifyDnControlContainer.grammarEndAllowed( false );
                 }
             } );
-
-        // elecharny, the below transitions are wrong, but if the above code for reading the 'move' CHOICE's superiorDN is solved
-        // will take the cue from there and try fixing the below for 'rename' and 'moveAndRename' CHOICE
+       
+        
         /** 
-         * Transition from entryDN to newRdn
+         * Transition from rename's RENAME newRdn to deleteOldRdn
          * 
          * Rename SEQUENCE {
-         *     new-rdn RDN,
-         *     delete-old-rdn BOOLEAN
+         *   ....
+         *   deleteOldRdn 
          * }
          *            
+         * Stores the deleteOldRdn value
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.RENAME_NEW_RDN_STATE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.RENAME_NEW_RDN_STATE, SyncModifyDnControlStatesEnum.RENAME_DEL_OLD_RDN_STATE,
+            UniversalTag.BOOLEAN_TAG, new GrammarAction( "Set SyncModifyDnControl deleteOldRdn value" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer ) container;
+                    Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+                    byte deleteOldRdn = value.getData()[0];
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "deleteOldRdn = {}", deleteOldRdn );
+                    }
+
+                    if( deleteOldRdn != 0 )
+                    {
+                        syncModifyDnControlContainer.getSyncModifyDnControl().setDeleteOldRdn( true );
+                    }
+
+                    // terminal state
+                    syncModifyDnControlContainer.grammarEndAllowed( true );
+                }
+            } );
+        
+
+        /** 
+         * Transition from entryDN to moveAndRename SEQUENCE
+         *  MoveAndRename SEQUENCE {
+         *     
+         * Stores the deleteOldRdn flag
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.ENTRY_DN_STATE][SyncModifyDnControlTags.MOVEANDRENAME_TAG.getValue()] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.ENTRY_DN_STATE, SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_STATE,
+            SyncModifyDnControlTags.MOVEANDRENAME_TAG.getValue(), new GrammarAction( "enter SyncModifyDnControl moveAndRename choice" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer ) container;
+                    syncModifyDnControlContainer.getSyncModifyDnControl().setModDnType( SyncModifyDnType.MOVEANDRENAME );
+
+                    syncModifyDnControlContainer.grammarEndAllowed( false );
+                }
+            } );
+
+        /** 
+         * Transition from MOVE_AND_RENAME_STATE to newSuperiorDn
+         * 
+         * MoveAndRename SEQUENCE {
+         *      superior-name   LDAPDN
+         *      ....
+         *            
          * Stores the newRdn value
-         *
-        super.transitions[SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE][SyncModifyDnControlTags.RENAME_TAG.getValue()] = new GrammarTransition(
-            SyncModifyDnControlStatesEnum.NEW_SUPERIOR_DN_STATE, SyncModifyDnControlStatesEnum.NEW_RDN_STATE,
-            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl newRdn value" )
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_STATE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_STATE, SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_SUPERIOR_DN_STATE,
+            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl moveAndRename state's newSuperirorDN value" )
+            {
+                public void action( IAsn1Container container ) throws DecoderException
+                {
+                    SyncModifyDnControlContainer syncModifyDnControlContainer = ( SyncModifyDnControlContainer ) container;
+                    Value value = syncModifyDnControlContainer.getCurrentTLV().getValue();
+
+                    String newSuperirorDn = StringTools.utf8ToString( value.getData() );
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "newSuperirorDn = {}", newSuperirorDn );
+                    }
+
+                    syncModifyDnControlContainer.getSyncModifyDnControl().setNewSuperiorDn( newSuperirorDn );
+
+                    // terminal state
+                    syncModifyDnControlContainer.grammarEndAllowed( false );
+                }
+            } );
+
+        /** 
+         * Transition from moveAndRename's newSuperiorDn to newRdn
+         * 
+         * MoveAndRename SEQUENCE {
+         *      superior-name   LDAPDN
+         *      ....
+         *            
+         * Stores the newRdn value
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_SUPERIOR_DN_STATE][UniversalTag.OCTET_STRING_TAG] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_SUPERIOR_DN_STATE, SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_RDN_STATE,
+            UniversalTag.OCTET_STRING_TAG, new GrammarAction( "Set SyncModifyDnControl moveAndRename state's newRdn value" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
                 {
@@ -228,22 +336,21 @@ public class SyncModifyDnControlGrammar 
                     syncModifyDnControlContainer.getSyncModifyDnControl().setNewRdn( newRdn );
 
                     // terminal state
-                    syncModifyDnControlContainer.grammarEndAllowed( true );
+                    syncModifyDnControlContainer.grammarEndAllowed( false );
                 }
             } );
         
+
         /** 
-         * Transition from entryDN to deleteOldRdn
+         * Transition from moveAndRename's newRdn to deleteOldRdn
          *  MoveAndRename SEQUENCE {
-         *      superior-name   LDAPDN
-         *      new-rd RDN,
+         *      ....
          *      delete-old-rdn BOOLEAN
-         *  }
          *     
          * Stores the deleteOldRdn flag
-         *
-        super.transitions[SyncModifyDnControlStatesEnum.NEW_RDN_STATE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
-            SyncModifyDnControlStatesEnum.NEW_RDN_STATE, SyncModifyDnControlStatesEnum.DEL_OLD_RDN_STATE,
+         */
+        super.transitions[SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_RDN_STATE][UniversalTag.BOOLEAN_TAG] = new GrammarTransition(
+            SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_NEW_RDN_STATE, SyncModifyDnControlStatesEnum.MOVE_AND_RENAME_DEL_OLD_RDN_STATE,
             UniversalTag.BOOLEAN_TAG, new GrammarAction( "Set SyncModifyDnControl deleteOldRdn value" )
             {
                 public void action( IAsn1Container container ) throws DecoderException
@@ -258,7 +365,7 @@ public class SyncModifyDnControlGrammar 
                         LOG.debug( "deleteOldRdn = {}", deleteOldRdn );
                     }
 
-                    if( deleteOldRdn == 1 )
+                    if( deleteOldRdn != 0 )
                     {
                         syncModifyDnControlContainer.getSyncModifyDnControl().setDeleteOldRdn( true );
                     }
@@ -266,7 +373,8 @@ public class SyncModifyDnControlGrammar 
                     // terminal state
                     syncModifyDnControlContainer.grammarEndAllowed( true );
                 }
-            } );*/
+            } );
+
     }
 
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java?rev=940636&r1=940635&r2=940636&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncModifyDnControlTest.java Mon May  3 21:42:55 2010
@@ -22,15 +22,18 @@ package org.apache.directory.shared.ldap
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControl;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControlContainer;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncmodifydn.SyncModifyDnControlDecoder;
+import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 
 /**
@@ -74,25 +77,23 @@ public class SyncModifyDnControlTest
         assertEquals( "ou=dc", syncmodDnControl.getNewSuperiorDn() );
         assertFalse( syncmodDnControl.isDeleteOldRdn() );
 
-        /*
         // Check the encoding
         try
         {
 
-            ByteBuffer buffer = ByteBuffer.allocate( 56 );
+            ByteBuffer buffer = ByteBuffer.allocate( 48 );
             buffer.put( new byte[]
                 { 
-                  0x30, 0x36,                            // Control
+                  0x30, 0x2E,                            // Control
                     0x04, 0x18,                          // OID (SuncStateValue)
                       '1', '.', '3', '.', '6', '.', '1', '.', 
                       '4', '.', '1', '.', '4', '2', '0', '3', 
                       '.', '1', '.', '9', '.', '1', '.', '5',
-                    0x04, 0x1A,
-                     0x30, 0x18, 
+                     0x30, 0x12, 
                       0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn entryDn
-                      0x04, 0x05, 'u','i','d','=','j',         //     newSuperiorDn newSuperiorDn OPTIONAL,
-                      0x04, 0x03, 'x', '=', 'y',               //     newRdn newRdn OPTIONAL,
-                      0x01, 0x01, 0x00                         //     deleteOldRdn deleteOldRdn OPTIONAL
+                      ( byte )0x80, 0x07,                     //     move
+                    0x04, 0x05,
+                      'o','u','=','d','c'         //     newSuperiorDn LDAPDN
                 } );
             buffer.flip();
 
@@ -103,6 +104,154 @@ public class SyncModifyDnControlTest
         {
             fail( ee.getMessage() );
         }
-        */
+    }
+
+    
+    @Test
+    public void testDecodeSyncModifyDnControlWithRenameOperation()
+    {
+        Asn1Decoder decoder = new SyncModifyDnControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0x17 );
+        bb.put( new byte[]
+            { 
+              0x30, 0x15,                                // SyncModifyDnControl ::= SEQUENCE {
+                0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn LDAPDN
+                ( byte )0x00A1, 0x0A,                    //     rename
+                  0x04, 0x05, 'u','i','d','=','j',       //     newRdn
+                  0x01, 0x01, ( byte ) 0xFF                       //     deleteOldRdn
+            } );
+        bb.flip();
+
+        SyncModifyDnControlContainer container = new SyncModifyDnControlContainer();
+        container.setSyncModifyDnControl( new SyncModifyDnControl() );
+
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        SyncModifyDnControl syncmodDnControl = container.getSyncModifyDnControl();
+        assertEquals( "uid=jim", syncmodDnControl.getEntryDn() );
+        assertEquals( "uid=j", syncmodDnControl.getNewRdn() );
+        assertTrue( syncmodDnControl.isDeleteOldRdn() );
+
+        // Check the encoding
+        try
+        {
+
+            ByteBuffer buffer = ByteBuffer.allocate( 51 );
+            buffer.put( new byte[]
+                { 
+                  0x30, 0x31,                            // Control
+                    0x04, 0x18,                          // OID (SuncStateValue)
+                      '1', '.', '3', '.', '6', '.', '1', '.', 
+                      '4', '.', '1', '.', '4', '2', '0', '3', 
+                      '.', '1', '.', '9', '.', '1', '.', '5',
+                      0x30, 0x15,                                // SyncModifyDnControl ::= SEQUENCE {
+                      0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn LDAPDN
+                      ( byte )0x00A1, 0x0A,                    //     rename
+                        0x04, 0x05, 'u','i','d','=','j',       //     newRdn
+                        0x01, 0x01, ( byte ) 0xFF                       //     deleteOldRdn
+                } );
+            buffer.flip();
+
+            ByteBuffer encoded = syncmodDnControl.encode( ByteBuffer.allocate( syncmodDnControl.computeLength() ) );
+            assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+                }
+        catch ( EncoderException ee )
+        {
+            fail( ee.getMessage() );
+        }
+    }
+
+    
+    @Test
+    public void testDecodeSyncModifyDnControlWithRenameAndMoveOperation()
+    {
+        Asn1Decoder decoder = new SyncModifyDnControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0x1E );
+        bb.put( new byte[]
+            { 
+              0x30, 0x1C,                                // SyncModifyDnControl ::= SEQUENCE {
+                0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn LDAPDN
+                ( byte )0x00A2, 0x11,                    //     rename
+                  0x04, 0x05, 'o','u','=','d','c',       //     newSuperiorDn
+                  0x04, 0x05, 'u','i','d','=','j',       //     newRdn
+                  0x01, 0x01, ( byte ) 0xFF                       //     deleteOldRdn
+            } );
+        bb.flip();
+
+        SyncModifyDnControlContainer container = new SyncModifyDnControlContainer();
+        container.setSyncModifyDnControl( new SyncModifyDnControl() );
+
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+
+        SyncModifyDnControl syncmodDnControl = container.getSyncModifyDnControl();
+        assertEquals( "uid=jim", syncmodDnControl.getEntryDn() );
+        assertEquals( "ou=dc", syncmodDnControl.getNewSuperiorDn() );
+        assertEquals( "uid=j", syncmodDnControl.getNewRdn() );
+        assertTrue( syncmodDnControl.isDeleteOldRdn() );
+
+        // Check the encoding
+        try
+        {
+
+            ByteBuffer buffer = ByteBuffer.allocate( 58 );
+            buffer.put( new byte[]
+                { 
+                  0x30, 0x38,                            // Control
+                    0x04, 0x18,                          // OID (SuncStateValue)
+                      '1', '.', '3', '.', '6', '.', '1', '.', 
+                      '4', '.', '1', '.', '4', '2', '0', '3', 
+                      '.', '1', '.', '9', '.', '1', '.', '5',
+                      0x30, 0x1C,                                // SyncModifyDnControl ::= SEQUENCE {
+                      0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn LDAPDN
+                      ( byte )0x00A2, 0x11,                    //     rename
+                        0x04, 0x05, 'o','u','=','d','c',       //     newSuperiorDn
+                        0x04, 0x05, 'u','i','d','=','j',       //     newRdn
+                        0x01, 0x01, ( byte ) 0xFF                       //     deleteOldRdn
+                } );
+            buffer.flip();
+
+            ByteBuffer encoded = syncmodDnControl.encode( ByteBuffer.allocate( syncmodDnControl.computeLength() ) );
+            assertEquals( StringTools.dumpBytes( buffer.array() ), StringTools.dumpBytes( encoded.array() ) );
+                }
+        catch ( EncoderException ee )
+        {
+            fail( ee.getMessage() );
+        }
+    }
+
+    
+    @Test( expected=DecoderException.class)
+    public void testDecodeSyncModifyDnControlWithIncorrectRenameOperationData() throws DecoderException
+    {
+        Asn1Decoder decoder = new SyncModifyDnControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0xE );
+        bb.put( new byte[]
+            { 
+              0x30, 0xC,                                // SyncModifyDnControl ::= SEQUENCE {
+                0x04, 0x07, 'u','i','d','=','j','i','m', //     entryDn LDAPDN
+                0x01, 0x01, ( byte ) 0xFF             //     deleteOldRdn
+            } );
+        bb.flip();
+
+        SyncModifyDnControlContainer container = new SyncModifyDnControlContainer();
+        container.setSyncModifyDnControl( new SyncModifyDnControl() );
+
+        decoder.decode( bb, container );
     }
 }