directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373032 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
Date Fri, 27 Jan 2006 23:35:28 GMT
Author: elecharny
Date: Fri Jan 27 15:35:20 2006
New Revision: 373032

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

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java?rev=373032&r1=373031&r2=373032&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/extended/ExtendedRequestGrammar.java
Fri Jan 27 15:35:20 2006
@@ -137,6 +137,9 @@
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
 
+                        // We can have an Pop transition
+                        ldapMessageContainer.grammarPopAllowed( true );
+
                         if ( log.isDebugEnabled() )
                         {
                             log.debug( "OID read : {}", extendedRequest.getRequestName()
);
@@ -186,6 +189,9 @@
 
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
+
+                        // We can have an Pop transition
+                        ldapMessageContainer.grammarPopAllowed( true );
 
                         if ( log.isDebugEnabled() )
                         {

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java?rev=373032&r1=373031&r2=373032&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/extended/ExtendedRequestTest.java
Fri Jan 27 15:35:20 2006
@@ -17,6 +17,7 @@
 package org.apache.ldap.common.codec.extended;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 import javax.naming.NamingException;
 
@@ -24,6 +25,7 @@
 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;
@@ -87,6 +89,167 @@
         
         // Check the length
         assertEquals(0x1D, message.computeLength());
+
+        // Check the encoding
+        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 full ExtendedRequest with controls
+     */
+    public void testDecodeExtendedRequestWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3A );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x38,         // LDAPMessage ::= SEQUENCE {
+                  0x02, 0x01, 0x01, //     messageID MessageID
+                                    //     CHOICE { ..., extendedReq     ExtendedRequest,
...
+                  0x77, 0x16,       // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+                                    //     requestName      [0] LDAPOID,
+                    (byte)0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
+                                    //     requestValue     [1] OCTET STRING OPTIONAL }
+                    (byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e',
+                  (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 LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+        assertEquals( "value", StringTools.utf8ToString( extendedRequest.getRequestValue()
) );
+        
+        // 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( 0x3A, message.computeLength() );
+
+        // Check the encoding
+        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 full ExtendedRequest with no value and with controls
+     */
+    public void testDecodeExtendedRequestNoValueWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x33 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x31,         // LDAPMessage ::= SEQUENCE {
+                  0x02, 0x01, 0x01, //     messageID MessageID
+                                    //     CHOICE { ..., extendedReq     ExtendedRequest,
...
+                  0x77, 0x0F,       // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+                                    //     requestName      [0] LDAPOID,
+                    (byte)0x80, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5',
'.', '2',
+                                    //     requestValue     [1] OCTET STRING OPTIONAL }
+                  (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 LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ExtendedRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+        assertEquals( "", StringTools.utf8ToString( extendedRequest.getRequestValue() ) );
+        
+        // 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( 0x33, message.computeLength() );
 
         // Check the encoding
         try



Mime
View raw message