directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r679468 - in /directory/shared/branches/bigbang/ldap/src: main/java/org/apache/directory/shared/ldap/codec/search/controls/ test/java/org/apache/directory/shared/ldap/codec/search/controls/
Date Thu, 24 Jul 2008 17:29:00 GMT
Author: elecharny
Date: Thu Jul 24 10:29:00 2008
New Revision: 679468

URL: http://svn.apache.org/viewvc?rev=679468&view=rev
Log:
o Modified the ChangeControl control to accept longs
o Added some tests for the long values

Modified:
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlCodec.java
    directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java
    directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlTest.java

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlCodec.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlCodec.java?rev=679468&r1=679467&r2=679468&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlCodec.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlCodec.java
Thu Jul 24 10:29:00 2008
@@ -33,8 +33,8 @@
 
 /**
  * A response control that may be returned by Persistent Search entry responses.
- * It contains addition change information to descrive the exact change that
- * occured to an entry. The exact details of this control are covered in section
+ * It contains addition change information to describe the exact change that
+ * occurred to an entry. The exact details of this control are covered in section
  * 5 of this (yes) expired draft: <a
  * href="http://www3.ietf.org/proceedings/01aug/I-D/draft-ietf-ldapext-psearch-03.txt">
  * Persistent Search Draft v03</a> which is printed out below for convenience:
@@ -105,6 +105,7 @@
         super();
     }
 
+    
     /**
      * Compute the EntryChangeControl length 
      * 
@@ -112,7 +113,7 @@
      *   | 
      *   +--> 0x0A 0x0(1-4) [1|2|4|8] (changeType) 
      *  [+--> 0x04 L2 previousDN] 
-     *  [+--> 0x02 0x0(1-4) [0..2^31-1] (changeNumber)]
+     *  [+--> 0x02 0x0(1-4) [0..2^63-1] (changeNumber)]
      */
     public int computeLength()
     {
@@ -129,9 +130,7 @@
 
         if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
         {
-            // TODO Emmanuel can you please check how we can use long here instead
-            // TODO get rid of cast to int 
-            changeNumberLength = 1 + 1 + Value.getNbBytes( ( int ) changeNumber );
+            changeNumberLength = 1 + 1 + Value.getNbBytes( changeNumber );
         }
 
         eccSeqLength = changeTypesLength + previousDnLength + changeNumberLength;
@@ -162,12 +161,12 @@
         {
             Value.encode( bb, previousDnBytes );
         }
+        
         if ( changeNumber != UNDEFINED_CHANGE_NUMBER )
         {
-            // TODO Emmanuel can you please check how we can use long here instead
-            // TODO get rid of cast to int 
-            Value.encode( bb, ( int ) changeNumber );
+            Value.encode( bb, changeNumber );
         }
+        
         return bb;
     }
 

Modified: directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java?rev=679468&r1=679467&r2=679468&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/main/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlGrammar.java
Thu Jul 24 10:29:00 2008
@@ -32,6 +32,8 @@
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.util.IntegerDecoder;
 import org.apache.directory.shared.asn1.util.IntegerDecoderException;
+import org.apache.directory.shared.asn1.util.LongDecoder;
+import org.apache.directory.shared.asn1.util.LongDecoderException;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.slf4j.Logger;
@@ -211,7 +213,7 @@
 
                 try
                 {
-                    int changeNumber = IntegerDecoder.parse( value );
+                    long changeNumber = LongDecoder.parse( value );
 
                     if ( IS_DEBUG )
                     {
@@ -223,7 +225,7 @@
                     // We can have an END transition
                     entryChangeContainer.grammarEndAllowed( true );
                 }
-                catch ( IntegerDecoderException e )
+                catch ( LongDecoderException e )
                 {
                     String msg = "failed to decode the changeNumber for EntryChangeControl";
                     log.error( msg, e );

Modified: directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlTest.java?rev=679468&r1=679467&r2=679468&view=diff
==============================================================================
--- directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlTest.java
(original)
+++ directory/shared/branches/bigbang/ldap/src/test/java/org/apache/directory/shared/ldap/codec/search/controls/EntryChangeControlTest.java
Thu Jul 24 10:29:00 2008
@@ -30,6 +30,7 @@
 import org.apache.directory.shared.ldap.codec.search.controls.EntryChangeControlDecoder;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Test;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -45,6 +46,7 @@
     /**
      * Test the decoding of a EntryChangeControl
      */
+    @Test
     public void testDecodeEntryChangeControlSuccess()
     {
         Asn1Decoder decoder = new EntryChangeControlDecoder();
@@ -79,8 +81,47 @@
 
 
     /**
+     * Test the decoding of a EntryChangeControl
+     */
+    @Test
+    public void testDecodeEntryChangeControlSuccessLongChangeNumber()
+    {
+        Asn1Decoder decoder = new EntryChangeControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0x13 );
+        bb.put( new byte[]
+            { 
+            0x30, 0x11,                     // EntryChangeNotification ::= SEQUENCE {
+              0x0A, 0x01, 0x08,             //     changeType ENUMERATED {
+                                            //         modDN (8)
+                                            //     }
+              0x04, 0x03, 'a', '=', 'b',    //     previousDN LDAPDN OPTIONAL, -- modifyDN
ops. only
+              0x02, 0x07,                   //     changeNumber INTEGER OPTIONAL } -- if
supported
+                0x12, 0x34, 0x56, 0x78, (byte)0x9A, (byte)0xBC, (byte)0xDE
+            } );
+        bb.flip();
+
+        EntryChangeControlContainer container = new EntryChangeControlContainer();
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        EntryChangeControlCodec entryChange = container.getEntryChangeControl();
+        assertEquals( ChangeType.MODDN, entryChange.getChangeType() );
+        assertEquals( "a=b", entryChange.getPreviousDn().toString() );
+        assertEquals( 5124095576030430L, entryChange.getChangeNumber() );
+    }
+
+
+    /**
      * Test the decoding of a EntryChangeControl with a add and a change number
      */
+    @Test
     public void testDecodeEntryChangeControlWithADDAndChangeNumber()
     {
         Asn1Decoder decoder = new EntryChangeControlDecoder();
@@ -118,6 +159,7 @@
      * Test the decoding of a EntryChangeControl with a add so we should not
      * have a PreviousDN
      */
+    @Test
     public void testDecodeEntryChangeControlWithADDAndPreviousDNBad()
     {
         Asn1Decoder decoder = new EntryChangeControlDecoder();
@@ -155,6 +197,7 @@
     /**
      * Test the decoding of a EntryChangeControl with a add and nothing else
      */
+    @Test
     public void testDecodeEntryChangeControlWithADD()
     {
         Asn1Decoder decoder = new EntryChangeControlDecoder();
@@ -189,9 +232,10 @@
 
 
     /**
-     * Test the decoding of a EntryChangeControl with a worng changeType and
+     * Test the decoding of a EntryChangeControl with a wrong changeType and
      * nothing else
      */
+    @Test
     public void testDecodeEntryChangeControlWithWrongChangeType()
     {
         Asn1Decoder decoder = new EntryChangeControlDecoder();
@@ -224,8 +268,47 @@
 
 
     /**
+     * Test the decoding of a EntryChangeControl with a wrong changeNumber
+     */
+    @Test
+    public void testDecodeEntryChangeControlWithWrongChangeNumber()
+    {
+        Asn1Decoder decoder = new EntryChangeControlDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0x1C );
+        bb.put( new byte[]
+            { 
+            0x30, 0x1A,                     // EntryChangeNotification ::= SEQUENCE {
+              0x0A, 0x01, 0x08,             //     changeType ENUMERATED {
+                                            //         modDN (8)
+                                            //     }
+              0x04, 0x03, 'a', '=', 'b',    //     previousDN LDAPDN OPTIONAL, -- modifyDN
ops. only
+              0x02, 0x10,                   //     changeNumber INTEGER OPTIONAL -- if supported
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+                0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+            } );
+        bb.flip();
+
+        EntryChangeControlContainer container = new EntryChangeControlContainer();
+
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException de )
+        {
+            // We should fail because the ChangeType is not known
+            assertTrue( true );
+            return;
+        }
+
+        Assert.fail( "The changeNumber is incorrect" );
+    }
+
+
+    /**
      * Test encoding of a EntryChangeControl.
      */
+    @Test
     public void testEncodeEntryChangeControl() throws Exception
     {
         ByteBuffer bb = ByteBuffer.allocate( 0x0D );
@@ -250,4 +333,35 @@
         String decoded = StringTools.dumpBytes( bb.array() );
         assertEquals( expected, decoded );
     }
+
+
+    /**
+     * Test encoding of a EntryChangeControl with a long changeNumber.
+     */
+    @Test
+    public void testEncodeEntryChangeControlLong() throws Exception
+    {
+        ByteBuffer bb = ByteBuffer.allocate( 0x13 );
+        bb.put( new byte[]
+            { 
+            0x30, 0x11,                     // EntryChangeNotification ::= SEQUENCE {
+              0x0A, 0x01, 0x08,             //     changeType ENUMERATED {
+                                            //         modDN (8)
+                                            //     }
+              0x04, 0x03, 'a', '=', 'b',    //     previousDN LDAPDN OPTIONAL, -- modifyDN
ops. only
+              0x02, 0x07,                   //     changeNumber INTEGER OPTIONAL -- if supported
+                0x12, 0x34, 0x56, 0x78, (byte)0x9a, (byte)0xbc, (byte)0xde
+            } );
+
+        String expected = StringTools.dumpBytes( bb.array() );
+        bb.flip();
+
+        EntryChangeControlCodec entry = new EntryChangeControlCodec();
+        entry.setChangeType( ChangeType.MODDN );
+        entry.setChangeNumber( 5124095576030430L );
+        entry.setPreviousDn( new LdapDN( "a=b" ) );
+        bb = entry.encode( null );
+        String decoded = StringTools.dumpBytes( bb.array() );
+        assertEquals( expected, decoded );
+    }
 }



Mime
View raw message