directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r742119 - in /directory/shared/trunk/ldap/src: main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/ test/java/org/apache/directory/shared/ldap/codec/controls/replication/
Date Sun, 08 Feb 2009 15:18:16 GMT
Author: kayyagari
Date: Sun Feb  8 15:18:15 2009
New Revision: 742119

URL: http://svn.apache.org/viewvc?rev=742119&view=rev
Log:
o added encoding tests
o fixed the boolean flag value for 'TRUE' in the tests
o added a missing transition in the grammar from sequence to refreshDeletes flag
o fixed a bug in the computeLength method


Modified:
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
    directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
    directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java?rev=742119&r1=742118&r2=742119&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlCodec.java
Sun Feb  8 15:18:15 2009
@@ -66,7 +66,7 @@
         }
 
         // the refreshDeletes flag length
-        syncDoneValueLength = 1 + 1 + 1;
+        syncDoneValueLength += 1 + 1 + 1;
 
         return 1 + TLV.getNbBytes( syncDoneValueLength ) + syncDoneValueLength;
     }

Modified: directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java?rev=742119&r1=742118&r2=742119&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
(original)
+++ directory/shared/trunk/ldap/src/main/java/org/apache/directory/shared/ldap/codec/controls/replication/syncDoneValue/SyncDoneValueControlGrammar.java
Sun Feb  8 15:18:15 2009
@@ -126,8 +126,38 @@
                 }
             } );
 
+        GrammarAction refreshDeletesTagAction = new GrammarAction( "set SyncDoneValueControl
refreshDeletes flag" )
+        {
+            public void action( IAsn1Container container ) throws DecoderException
+            {
+                SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer
) container;
+                Value value = syncDoneValueContainer.getCurrentTLV().getValue();
+
+                try
+                {
+                    boolean refreshDeletes = BooleanDecoder.parse( value );
+
+                    if ( IS_DEBUG )
+                    {
+                        LOG.debug( "refreshDeletes = {}", refreshDeletes );
+                    }
+
+                    syncDoneValueContainer.getSyncDoneValueControl().setRefreshDeletes( refreshDeletes
);
+
+                    // the END transition for grammar
+                    syncDoneValueContainer.grammarEndAllowed( true );
+                }
+                catch ( BooleanDecoderException be )
+                {
+                    String msg = "failed to decode the refreshDeletes flag for SyncDoneValueControl";
+                    LOG.error( msg, be );
+                    throw new DecoderException( msg );
+                }
+
+            }
+        }; 
         /**
-         * transition from cookie
+         * transition from cookie to refreshDeletes
          * {
          *    ....
          *    refreshDeletes BOOLEAN DEFAULT FALSE
@@ -135,36 +165,19 @@
          */
         super.transitions[SyncDoneValueControlStatesEnum.COOKIE_STATE][UniversalTag.BOOLEAN_TAG]
= new GrammarTransition(
             SyncDoneValueControlStatesEnum.COOKIE_STATE, SyncDoneValueControlStatesEnum.REFRESH_DELETES_STATE,
-            UniversalTag.BOOLEAN_TAG, new GrammarAction( "set SyncDoneValueControl refreshDeletes
flag" )
-            {
-                public void action( IAsn1Container container ) throws DecoderException
-                {
-                    SyncDoneValueControlContainer syncDoneValueContainer = ( SyncDoneValueControlContainer
) container;
-                    Value value = syncDoneValueContainer.getCurrentTLV().getValue();
-
-                    try
-                    {
-                        boolean refreshDeletes = BooleanDecoder.parse( value );
-
-                        if ( IS_DEBUG )
-                        {
-                            LOG.debug( "refreshDeletes = {}", refreshDeletes );
-                        }
-
-                        syncDoneValueContainer.getSyncDoneValueControl().setRefreshDeletes(
refreshDeletes );
-
-                        // the END transition for grammar
-                        syncDoneValueContainer.grammarEndAllowed( true );
-                    }
-                    catch ( BooleanDecoderException be )
-                    {
-                        String msg = "failed to decode the refreshDeletes flag for SyncDoneValueControl";
-                        LOG.error( msg, be );
-                        throw new DecoderException( msg );
-                    }
+            UniversalTag.BOOLEAN_TAG, refreshDeletesTagAction );
+        
+        /**
+         * transition from SEQUENCE to refreshDeletes
+         * {
+         *    ....
+         *    refreshDeletes BOOLEAN DEFAULT FALSE
+         * }
+         */
+        super.transitions[SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE][UniversalTag.BOOLEAN_TAG]
= new GrammarTransition(
+            SyncDoneValueControlStatesEnum.SYNC_DONE_VALUE_SEQUENCE_STATE, SyncDoneValueControlStatesEnum.REFRESH_DELETES_STATE,
+            UniversalTag.BOOLEAN_TAG, refreshDeletesTagAction );
 
-                }
-            } );
     }
 
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java?rev=742119&r1=742118&r2=742119&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
(original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/controls/replication/SyncDoneValueControlTest.java
Sun Feb  8 15:18:15 2009
@@ -20,11 +20,17 @@
 package org.apache.directory.shared.ldap.codec.controls.replication;
 
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
+import java.util.Arrays;
 
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
+import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlCodec;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlContainer;
 import org.apache.directory.shared.ldap.codec.controls.replication.syncDoneValue.SyncDoneValueControlDecoder;
@@ -49,8 +55,10 @@
         ByteBuffer bb = ByteBuffer.allocate( 11 );
 
         bb.put( new byte[]
-            { 0x30, 0x09, 0x04, 0x04, 'x', 'k', 'c', 'd', // the cookie 
-                0x01, 0x01, 0x01 // refreshDeletes flag TRUE
+            { 
+              0x30, 0x09, 
+              0x04, 0x04, 'x', 'k', 'c', 'd', // the cookie 
+              0x01, 0x01, ( byte ) 0xFF // refreshDeletes flag TRUE
             } );
 
         bb.flip();
@@ -69,6 +77,20 @@
         SyncDoneValueControlCodec control = container.getSyncDoneValueControl();
         assertEquals( "xkcd", StringTools.utf8ToString( control.getCookie() ) );
         assertTrue( control.isRefreshDeletes() );
+        
+        // test encoding
+        try
+        {
+            ByteBuffer encodedBuf = control.encode( null );
+            encodedBuf.flip();
+            bb.flip();
+            
+            assertTrue( Arrays.equals( encodedBuf.array(), bb.array() ) );
+        }
+        catch( EncoderException e )
+        {
+            fail( e.getMessage() );
+        }
     }
 
 
@@ -76,11 +98,13 @@
     public void testSyncDoneValueControlWithoutCookie()
     {
         Asn1Decoder decoder = new SyncDoneValueControlDecoder();
-        ByteBuffer bb = ByteBuffer.allocate( 7 );
+        ByteBuffer bb = ByteBuffer.allocate( 5 );
 
         bb.put( new byte[]
-            { 0x30, 0x05, 0x04, 0x00, // null cookie
-                0x01, 0x01, 0x00 // refreshDeletes flag FALSE
+            { 
+              0x30, 0x03, 
+              // null cookie
+              0x01, 0x01, 0x00 // refreshDeletes flag FALSE
             } );
 
         bb.flip();
@@ -99,6 +123,20 @@
         SyncDoneValueControlCodec control = container.getSyncDoneValueControl();
         assertNull( control.getCookie() );
         assertFalse( control.isRefreshDeletes() );
+
+        // test encoding
+        try
+        {
+            ByteBuffer encodedBuf = control.encode( null );
+            encodedBuf.flip();
+            bb.flip();
+            
+            assertTrue( Arrays.equals( encodedBuf.array(), bb.array() ) );
+        }
+        catch( EncoderException e )
+        {
+            fail( e.getMessage() );
+        }
     }
 
 }



Mime
View raw message