directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373164 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java
Date Sat, 28 Jan 2006 15:28:11 GMT
Author: elecharny
Date: Sat Jan 28 07:28:03 2006
New Revision: 373164

URL: http://svn.apache.org/viewcvs?rev=373164&view=rev
Log:
- Added a pop transition
- Added a test

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java?rev=373164&r1=373163&r2=373164&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/unbind/UnBindRequestGrammar.java
Sat Jan 28 07:28:03 2006
@@ -119,6 +119,9 @@
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
                         
+                        // We can have a Pop transition
+                        ldapMessageContainer.grammarPopAllowed( true );
+                        
                         // And we associate it to the ldapMessage Object
                         ldapMessage.setProtocolOP( unBindRequest );
                     }

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java?rev=373164&r1=373163&r2=373164&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/unbind/UnBindRequestTest.java
Sat Jan 28 07:28:03 2006
@@ -17,11 +17,13 @@
 package org.apache.ldap.common.codec.unbind;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 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.Control;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -72,6 +74,76 @@
         
         // Check the length
         assertEquals(7, 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() );
+        }
+    }
+
+    /**
+     * Test the decoding of a UnBindRequest with controls
+     */
+    public void testDecodeUnBindRequestWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x24 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x22,         // LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x01, //         messageID MessageID
+                  0x42, 0x00,       //        CHOICE { ..., unbindRequest UnbindRequest,...
+                                    // UnbindRequest ::= [APPLICATION 2] NULL
+                  (byte)0xA0, 0x1B, // A control 
+                    0x30, 0x19, 
+                      0x04, 0x17, 
+                        0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 
+                        0x2E, 0x31, 0x2E, 0x31, 0x31, 0x33, 0x37, 0x33, 
+                        0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32
+            } );
+
+        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( 1, message.getMessageId() );
+        
+        // Check the Control
+        List controls = message.getControls();
+        
+        assertEquals( 1, controls.size() );
+        
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+        // Check the length
+        assertEquals( 0x24, message.computeLength() );
 
         try
         {



Mime
View raw message