directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373026 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
Date Fri, 27 Jan 2006 23:23:35 GMT
Author: elecharny
Date: Fri Jan 27 15:23:23 2006
New Revision: 373026

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

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java?rev=373026&r1=373025&r2=373026&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareResponseGrammar.java
Fri Jan 27 15:23:23 2006
@@ -108,7 +108,15 @@
         // CompareResponse ::= [APPLICATION 15] LDAPResult (Value)
         // Ok, we have a LDAPResult Tag (0x0A). So we have to switch the grammar.
         super.transitions[LdapStatesEnum.COMPARE_RESPONSE_LDAP_RESULT][UniversalTag.ENUMERATED_TAG]
= new GrammarTransition(
-                LdapStatesEnum.COMPARE_RESPONSE_LDAP_RESULT, LdapStatesEnum.LDAP_RESULT_GRAMMAR_SWITCH,
null );
+                LdapStatesEnum.COMPARE_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/compare/CompareResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java?rev=373026&r1=373025&r2=373026&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareResponseTest.java
Fri Jan 27 15:23:23 2006
@@ -17,11 +17,13 @@
 package org.apache.ldap.common.codec.compare;
 
 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;
@@ -90,6 +92,92 @@
 
         // Check the length
         assertEquals(0x0E, 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 CompareResponse with controls
+     */
+    public void testDecodeCompareResponseSuccessWithControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2B );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x29,           // LDAPMessage ::=SEQUENCE {
+                  0x02, 0x01, 0x01,   //         messageID MessageID
+                  0x6F, 0x07,         //        CHOICE { ..., compareResponse CompareResponse,
...
+                                      // CompareResponse ::= [APPLICATION 15] 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 the CompareResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Check the decoded CompareResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        CompareResponse compareResponse      = message.getCompareResponse();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( 0, compareResponse.getLdapResult().getResultCode() );
+        assertEquals( "", compareResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", compareResponse.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



Mime
View raw message