directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373499 - /directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java
Date Mon, 30 Jan 2006 12:30:57 GMT
Author: elecharny
Date: Mon Jan 30 04:30:53 2006
New Revision: 373499

URL: http://svn.apache.org/viewcvs?rev=373499&view=rev
Log:
Added a test to check that high message id are correctly encoded
and decoded

Modified:
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java?rev=373499&r1=373498&r2=373499&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/LdapMessageTest.java
Mon Jan 30 04:30:53 2006
@@ -19,10 +19,12 @@
 import junit.framework.TestCase;
 
 import org.apache.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.IAsn1Container;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessageContainer;
+import org.apache.ldap.common.util.StringTools;
 
 import java.nio.ByteBuffer;
 
@@ -259,4 +261,61 @@
 
         assertTrue( true );
     }
+    
+    /**
+     * Test the decoding of a LdapMessage with a large MessageId
+     */
+    public void testDecodeUnBindRequestNoControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x08 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x06,                     // LDAPMessage ::=SEQUENCE {
+                0x02, 0x02, 0x01, (byte)0xF4,   //         messageID MessageID (500)
+                0x42, 0x00,                     //        CHOICE { ..., unbindRequest UnbindRequest,...
+                                                // UnbindRequest ::= [APPLICATION 2] NULL
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+
+        assertEquals( 500, message.getMessageId() );
+        
+        // Check the length
+        assertEquals(8, message.computeLength());
+
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    
 }



Mime
View raw message