directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373475 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
Date Mon, 30 Jan 2006 09:00:26 GMT
Author: elecharny
Date: Mon Jan 30 01:00:18 2006
New Revision: 373475

URL: http://svn.apache.org/viewcvs?rev=373475&view=rev
Log:
- Fixed a bug in length computation
- Added a test for this bug

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java?rev=373475&r1=373474&r2=373475&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnect.java
Mon Jan 30 01:00:18 2006
@@ -134,13 +134,9 @@
                 int ldapUrlLength = ((LdapURL)replicatedContextIterator.next()).getNbBytes();
                 replicatedContextsLength += 1 + Length.getNbBytes( ldapUrlLength ) + ldapUrlLength;
             }
+
+            gracefulDisconnectSequenceLength += 1 + Length.getNbBytes( replicatedContextsLength
) + replicatedContextsLength; 
         }
-        else
-        {
-            replicatedContextsLength = 1 + 1;
-        }
-        
-        gracefulDisconnectSequenceLength += 1 + Length.getNbBytes( replicatedContextsLength
) + replicatedContextsLength; 
 
         return 1 + Length.getNbBytes( gracefulDisconnectSequenceLength ) + gracefulDisconnectSequenceLength;
     }

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java?rev=373475&r1=373474&r2=373475&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/operations/GracefulDisconnectTest.java
Mon Jan 30 01:00:18 2006
@@ -171,6 +171,59 @@
     }
 
     /**
+     * Test the decoding of a GracefulDisconnect with a timeOffline and a delay
+     */
+    public void testDecodeGracefulDisconnectTimeOfflineDelay() throws NamingException
+    {
+        Asn1Decoder decoder = new GracefulDisconnectDecoder();
+        ByteBuffer bb = ByteBuffer.allocate( 0x08 );
+        bb.put( new byte[]
+            {
+                0x30, 0x06,                 // GracefulDisconnect ::= SEQUENCE {
+                  0x02, 0x01, 0x01,          //     timeOffline INTEGER (0..720) DEFAULT
0,
+                  (byte)0x80, 0x01, 0x01,          //     timeOffline INTEGER (0..720) DEFAULT
0,
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( bb.array() );
+        bb.flip();
+
+        GracefulDisconnectContainer container = new GracefulDisconnectContainer();
+        
+        try
+        {
+            decoder.decode( bb, container );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+        
+        GracefulDisconnect gracefulDisconnect = container.getGracefulDisconnect();
+        assertEquals( 1, gracefulDisconnect.getTimeOffline() );
+        assertEquals( 1, gracefulDisconnect.getDelay() );
+        assertEquals( 0, gracefulDisconnect.getReplicatedContexts().size() );
+
+        // Check the length
+        assertEquals(0x08, gracefulDisconnect.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb2 = gracefulDisconnect.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb2.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    /**
      * Test the decoding of a GracefulDisconnect with replicatedContexts only
      */
     public void testDecodeGracefulDisconnectReplicatedContextsOnly() throws NamingException



Mime
View raw message