directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373063 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java
Date Sat, 28 Jan 2006 01:41:37 GMT
Author: elecharny
Date: Fri Jan 27 17:41:29 2006
New Revision: 373063

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

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java?rev=373063&r1=373062&r2=373063&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/modify/ModifyResponseGrammar.java
Fri Jan 27 17:41:29 2006
@@ -22,6 +22,7 @@
 import org.apache.asn1.ber.grammar.GrammarAction;
 import org.apache.asn1.ber.IAsn1Container;
 import org.apache.asn1.ber.tlv.UniversalTag;
+import org.apache.asn1.codec.DecoderException;
 import org.apache.ldap.common.codec.LdapConstants;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -95,7 +96,14 @@
         // ModifyResponse ::= [APPLICATION 7] LDAPResult (Value)
         // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
         super.transitions[LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG]
= new GrammarTransition(
-                LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
+                LdapStatesEnum.MODIFY_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,

+                new GrammarAction( "Pop allowed" )
+                {
+                    public void action( IAsn1Container container ) throws DecoderException
+                    {
+                        container.grammarPopAllowed( true );
+                    }
+                });
     }
 
     //~ Methods ------------------------------------------------------------------------------------

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java?rev=373063&r1=373062&r2=373063&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/modify/ModifyResponseTest.java
Fri Jan 27 17:41:29 2006
@@ -17,11 +17,13 @@
 package org.apache.ldap.common.codec.modify;
 
 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;
@@ -108,6 +110,92 @@
     }
     
     /**
+     * Test the decoding of a ModifyResponse with controls
+     */
+    public void testDecodeModifyResponseSuccessWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2B );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x29,           // LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x01,   //         messageID MessageID
+                  0x67, 0x07,         //        CHOICE { ..., modifyResponse ModifyResponse,
...
+                                      // ModifyResponse ::= [APPLICATION 7] LDAPResult
+                    0x0A, 0x01, 0x00, //   LDAPResult ::= SEQUENCE {
+                                      //      resultCode ENUMERATED {
+                                      //          success (0), ...
+                                      //      },
+                    0x04, 0x00,       //      matchedDN    LDAPDN,
+                    0x04, 0x00,       //      errorMessage LDAPString,
+                                      //      referral     [3] Referral 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 a ModifyResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded ModifyResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyResponse modifyResponse      = message.getModifyResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, modifyResponse.getLdapResult().getResultCode() );
+        assertEquals( "", modifyResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", modifyResponse.getLdapResult().getErrorMessage() );
+        
+        // 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(0x2B, 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 ModifyResponse with no LdapResult
      */
     public void testDecodeModifyResponseEmptyResult()
@@ -119,7 +207,7 @@
         stream.put(
             new byte[]
             {
-                    0x30, 0x05,         // LDAPMessage ::=SEQUENCE {
+                    0x30, 0x05,           // LDAPMessage ::=SEQUENCE {
                       0x02, 0x01, 0x01,   //         messageID MessageID
                       0x67, 0x00,         //        CHOICE { ..., modifyResponse ModifyResponse,
...
             } );



Mime
View raw message