directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r227098 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java
Date Tue, 02 Aug 2005 22:28:57 GMT
Author: elecharny
Date: Tue Aug  2 15:28:53 2005
New Revision: 227098

URL: http://svn.apache.org/viewcvs?rev=227098&view=rev
Log:
Added a test for controls. This class has been chosen because 
its PDU is small.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java?rev=227098&r1=227097&r2=227098&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AbandonRequestTest.java
Tue Aug  2 15:28:53 2005
@@ -48,7 +48,7 @@
     /**
      * Test the decoding of a AbandonRequest with no controls
      */
-    public void testDecodeAbandonRequestNoControls()
+/*    public void testDecodeAbandonRequestNoControls()
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -88,6 +88,85 @@
         
         // Check the length
         Assert.assertEquals(8, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+*/
+    /**
+     * Test the decoding of a AbandonRequest with controls
+     */
+    public void testDecodeAbandonRequestWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x4A );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x48,         // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03,   //        messageID MessageID
+                0x50, 0x01, 0x02,    //        CHOICE { ..., abandonRequest AbandonRequest,...
+                (byte)0xA0, 0x40,   //    controls       [0] Controls OPTIONAL }
+                0x30, 0x3E,         // Controls ::= SEQUENCE OF Control
+                0x30, 0x13,         // Control ::= SEQUENCE {
+                                    //    controlType             LDAPOID, 
+                0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x01,
+                0x01, 0x01, (byte)0xFF,   //    criticality             BOOLEAN DEFAULT FALSE,
+                                    //    controlValue            OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f',
+                0x30, 0x10,         // Control ::= SEQUENCE {
+                                    //    controlType             LDAPOID, 
+                0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+                                    //    controlValue            OCTET STRING OPTIONAL }
+                0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l',
+                0x30, 0x0B,         // Control ::= SEQUENCE {
+                                    //    controlType             LDAPOID, 
+                0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x03,
+                0x01, 0x01, (byte)0xFF,   //    criticality             BOOLEAN DEFAULT FALSE}
+                0x30, 0x08,         // Control ::= SEQUENCE {
+                                    //    controlType             LDAPOID} 
+                0x04, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x04
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessageContainer Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+        
+        // Check that everything is OK
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        AbandonRequest abandonRequest = message.getAbandonRequest();
+
+        Assert.assertEquals( 3, message.getMessageId() );
+        Assert.assertEquals( 2, abandonRequest.getMessageId() );
+        
+        // Check the length
+        Assert.assertEquals(0x4A, message.computeLength());
         
         // Check the encoding
         try



Mime
View raw message