directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r226665 - in /directory/sandbox/trunk/asn1-new-codec/src: java/org/apache/asn1/ldap/codec/ java/org/apache/asn1/ldap/codec/grammars/ java/org/apache/asn1/ldap/pojo/ test/org/apache/asn1/ldap/codec/
Date Sun, 31 Jul 2005 17:28:09 GMT
Author: elecharny
Date: Sun Jul 31 10:28:00 2005
New Revision: 226665

URL: http://svn.apache.org/viewcvs?rev=226665&view=rev
Log:
- added the encoding of SearchResultReference and ModifyDNRequest
messages
- fixed a bug in ModifyDNRequest : the tag for newSuperior was 0x04 
(OCTET_STRING) when it should have been 0x80.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultReferenceGrammar.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
    directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/LdapConstants.java
Sun Jul 31 10:28:00 2005
@@ -59,11 +59,16 @@
     public static final byte MODIFY_RESPONSE_TAG = 0x67;
     public static final byte ADD_RESPONSE_TAG = 0x69;
     public static final byte DEL_RESPONSE_TAG = 0x6B;
+    public static final byte MODIFY_DN_REQUEST_TAG = 0x6C;
     public static final byte MODIFY_DN_RESPONSE_TAG = 0x6D;
     public static final byte COMPARE_RESPONSE_TAG = 0x6F;
+    public static final byte SEARCH_RESULT_REFERENCE_TAG = 0x73;
     public static final byte EXTENDED_REQUEST_TAG = 0x77;
     public static final byte EXTENDED_RESPONSE_TAG = 0x78;
+    // The following tags are ints, because bytes above 127 are negative
+    // numbers, and we can't use them as array indexes.
     public static final int EXTENDED_REQUEST_NAME_TAG = 0x80;
+    public static final int MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG = 0x80;
     public static final int EXTENDED_REQUEST_VALUE_TAG = 0x81;
     public static final int LDAP_RESULT_REFERRAL_SEQUENCE_TAG = 0x83;
     public static final int SERVER_SASL_CREDENTIAL_TAG = 0x87;

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/ModifyDNRequestGrammar.java
Sun Jul 31 10:28:00 2005
@@ -24,6 +24,7 @@
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
 import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.RelativeLdapDN;
@@ -72,13 +73,13 @@
         //============================================================================================
         // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_TAG][0x6c] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_TAG][LdapConstants.MODIFY_DN_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_TAG, LdapStatesEnum.MODIFY_DN_REQUEST_VALUE,
                 null );
 
         // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { (Value)
         // Initialise the modify DN request pojo
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_VALUE][0x6c] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_VALUE][LdapConstants.MODIFY_DN_REQUEST_TAG]
= new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_VALUE, LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG,
                 new GrammarAction( "Init Modify DN Request" )
                 {
@@ -101,7 +102,7 @@
         //    entry           LDAPDN, (Tag)
         //    ...
         // The tag is 0x04. Nothing to do
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_TAG,
                 LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE, null );
@@ -110,7 +111,7 @@
         //    entry           LDAPDN, (Value)
         //    ...
         // We store the entry. It must not be null.
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_ENTRY_VALUE,
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG,
@@ -149,7 +150,7 @@
         //    ...
         // The tag is 0x04. A RelativeLDAPDN is a component of a
         // LDAPDN. Nothing to do
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_TAG,
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE, null );
@@ -160,7 +161,7 @@
         //    ...
         // A RelativeLDAPDN is a component of a LDAPDN. We have to check that it is
         // valid.
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE][LdapConstants.OCTET_STRING_TAG]
=
             new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_NEW_RDN_VALUE,
                 LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG,
                 new GrammarAction( "Store new RDN" )
@@ -196,7 +197,7 @@
         //    deleteoldrdn    BOOLEAN, (Tag)
         //    ...
         // Nothing to do.
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG][0x01] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG][LdapConstants.BOOLEAN_TAG]
=
             new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_TAG,
                 LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE, null );
 
@@ -205,7 +206,7 @@
         //    deleteoldrdn    BOOLEAN, (Value)
         //    ...
         // Store the flag
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE][0x01] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE][LdapConstants.BOOLEAN_TAG]
=
             new GrammarTransition( LdapStatesEnum.MODIFY_DN_REQUEST_DELETE_OLD_RDN_VALUE,
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
                 new GrammarAction( "Store matching dnAttributes Value" )
@@ -246,7 +247,7 @@
         //    ...
         //    newSuperior     [0] LDAPDN OPTIONAL } (Tag)
         // This is an optionnal element. Nothing to do
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG][LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE, null );
@@ -258,7 +259,7 @@
         // we will consider that it's just a change of the entry, except
         // if the deleteOldRDN flag is set to true, in which case this is
         // an error.
-        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE][0x04] =
+        super.transitions[LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE][LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG]
=
             new GrammarTransition(
                 LdapStatesEnum.MODIFY_DN_REQUEST_NEW_SUPERIOR_VALUE, LdapStatesEnum.GRAMMAR_END,
                 new GrammarAction( "Store new superior" )

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultReferenceGrammar.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultReferenceGrammar.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultReferenceGrammar.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/codec/grammars/SearchResultReferenceGrammar.java
Sun Jul 31 10:28:00 2005
@@ -23,6 +23,7 @@
 import org.apache.asn1.ber.grammar.GrammarTransition;
 import org.apache.asn1.ber.grammar.IGrammar;
 import org.apache.asn1.ber.tlv.TLV;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.LdapMessageContainer;
 import org.apache.asn1.ldap.codec.primitives.LdapURL;
 import org.apache.asn1.ldap.pojo.LdapMessage;
@@ -70,12 +71,12 @@
         //============================================================================================
         // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL (Tag)
         // Nothing to do
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_TAG][0x73] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_TAG][LdapConstants.SEARCH_RESULT_REFERENCE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_TAG, LdapStatesEnum.SEARCH_RESULT_REFERENCE_VALUE,
null );
 
         // SearchResultReference ::= [APPLICATION 19] SEQUENCE OF LDAPURL (Value)
         // We won't have a value. The next Tag will be the LDAPUrl Tag (0x04)
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_VALUE][0x73] = new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_VALUE][LdapConstants.SEARCH_RESULT_REFERENCE_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_VALUE, LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_TAG,
                 new GrammarAction( "Init SearchResultReference" )
                 {
@@ -99,17 +100,17 @@
                 }  );
 
         // LDAPURL (Tag)
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_TAG][0x04] = new
GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_TAG, LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_VALUE,
                 null );
 
         // LDAPURL loop (Tag)
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LOOP_OR_END_TAG][0x04] =
new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LOOP_OR_END_TAG][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_LOOP_OR_END_TAG, LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_VALUE,
                 null );
 
         // LDAPURL (Value)
-        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_VALUE][0x04] =
new GrammarTransition(
+        super.transitions[LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_VALUE][LdapConstants.OCTET_STRING_TAG]
= new GrammarTransition(
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_LDAP_URL_VALUE,
                 LdapStatesEnum.SEARCH_RESULT_REFERENCE_LOOP_OR_END_TAG, 
                 new GrammarAction( "Store ldapUrl value" )

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/ModifyDNRequest.java
Sun Jul 31 10:28:00 2005
@@ -16,8 +16,14 @@
  */
 package org.apache.asn1.ldap.pojo;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
+
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ber.tlv.Value;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapDN;
 import org.apache.asn1.ldap.codec.primitives.RelativeLdapDN;
 
@@ -47,6 +53,9 @@
 
     /** The optional superior, which will be concatened to the newRdn */
     private LdapDN newSuperior;
+    
+    /** The modify DN request length */
+    private transient int modifyDNRequestLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -161,7 +170,7 @@
     public int computeLength()
     {
 
-        int modifyDNRequestLength =
+        modifyDNRequestLength =
             1 + Length.getNbBytes( entry.getLength() ) + entry.getLength() +
             1 + Length.getNbBytes( newRDN.getLength() ) + newRDN.getLength() +
             1 + 1 + 1; // deleteOldRDN
@@ -173,6 +182,63 @@
         }
 
         return 1 + Length.getNbBytes( modifyDNRequestLength ) + modifyDNRequestLength;
+    }
+
+    /**
+     * Encode the ModifyDNRequest message to a PDU.
+     * 
+     * ModifyDNRequest :
+     * 
+     * 0x6C LL
+     *   0x04 LL entry
+     *   0x04 LL newRDN
+     *   0x01 0x01 deleteOldRDN
+     *   [0x80 LL newSuperior]
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The SearchResultReference Tag
+            buffer.put( LdapConstants.MODIFY_DN_REQUEST_TAG );
+            buffer.put( Length.getBytes( modifyDNRequestLength ) ) ;
+
+            // The entry
+            Value.encode( buffer, entry );
+            
+            // The newRDN
+            Value.encode( buffer, newRDN );
+            
+            // The flag deleteOldRdn
+            Value.encode( buffer, deleteOldRDN );
+            
+            // The new superior, if any
+            if ( newSuperior != null )
+            {
+                // Encode the reference
+                buffer.put( (byte)LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG );
+                buffer.put( Length.getBytes( newSuperior.getLength() ) );
+                
+                if ( newSuperior.getLength() != 0 )
+                {
+                    buffer.put( newSuperior.getData() );
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/java/org/apache/asn1/ldap/pojo/SearchResultReference.java
Sun Jul 31 10:28:00 2005
@@ -17,9 +17,13 @@
 package org.apache.asn1.ldap.pojo;
 
 import org.apache.asn1.Asn1Object;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.tlv.Length;
+import org.apache.asn1.ldap.codec.LdapConstants;
 import org.apache.asn1.ldap.codec.primitives.LdapURL;
 
+import java.nio.BufferOverflowException;
+import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Iterator;
 
@@ -36,6 +40,9 @@
 
     /** The set of LdapURLs */
     private ArrayList searchResultReferences;
+    
+    /** The search result reference length */
+    private transient int searchResultReferenceLength;
 
     //~ Constructors -------------------------------------------------------------------------------
 
@@ -88,7 +95,7 @@
      */
     public int computeLength()
     {
-        int searchResultReferenceLength = 0;
+        searchResultReferenceLength = 0;
         
         Iterator referencesIterator = searchResultReferences.iterator();
         
@@ -100,6 +107,53 @@
         }
         
         return 1 + Length.getNbBytes( searchResultReferenceLength ) + searchResultReferenceLength;
+    }
+
+    /**
+     * Encode the SearchResultReference message to a PDU.
+     * 
+     * SearchResultReference :
+     * 
+     * 0x73 LL
+     *   0x04 LL reference
+     *   [0x04 LL reference]*
+     * 
+     * @param buffer The buffer where to put the PDU
+     * @return The PDU.
+     */
+    public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException
+    {
+        if ( buffer == null )
+        {
+            throw new EncoderException( "Cannot put a PDU in a null buffer !" );
+        }
+
+        try 
+        {
+            // The SearchResultReference Tag
+            buffer.put( LdapConstants.SEARCH_RESULT_REFERENCE_TAG );
+            buffer.put( Length.getBytes( searchResultReferenceLength ) ) ;
+
+            // The references. We must at least have one reference
+            Iterator referencesIterator = searchResultReferences.iterator();
+            
+            // We may have more than one reference.
+            while (referencesIterator.hasNext())
+            {
+                LdapURL reference = ((LdapURL)referencesIterator.next());
+                
+                // Encode the reference
+                buffer.put( LdapConstants.OCTET_STRING_TAG );
+                buffer.put( Length.getBytes( reference.getLength() ) );
+                buffer.put( reference.getData() );
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException("The PDU buffer size is too small !"); 
+        }
+
+        return buffer;
     }
 
     /**

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
Sun Jul 31 10:28:00 2005
@@ -21,10 +21,12 @@
 import javax.naming.NamingException;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.ModifyDNRequest;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -69,9 +71,10 @@
                 0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i',
'f', 'y',
                 0x01, 0x01, 0x00,   //     deleteoldrdn    BOOLEAN,
                                     // newSuperior     [0] LDAPDN OPTIONAL }
-                0x04, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
+                (byte)0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a ModifyRequest Container
@@ -98,6 +101,21 @@
 
         // Check the length
         Assert.assertEquals(0x4A, 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() );
+        }
     }
 
     /**
@@ -126,6 +144,7 @@
                                     // newSuperior     [0] LDAPDN OPTIONAL }
             } );
 
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a ModifyRequest Container
@@ -151,5 +170,20 @@
         
         // Check the length
         Assert.assertEquals(0x3F, 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() );
+        }
     }
 }

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java?rev=226665&r1=226664&r2=226665&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultReferenceTest.java
Sun Jul 31 10:28:00 2005
@@ -23,11 +23,13 @@
 import javax.naming.NamingException;
 
 import org.apache.asn1.DecoderException;
+import org.apache.asn1.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.containers.IAsn1Container;
 import org.apache.asn1.ldap.codec.primitives.LdapURL;
 import org.apache.asn1.ldap.pojo.LdapMessage;
 import org.apache.asn1.ldap.pojo.SearchResultReference;
+import org.apache.asn1.util.StringUtils;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
 
@@ -107,6 +109,7 @@
             }
         }
         
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a BindRequest Container
@@ -159,5 +162,20 @@
         
         // Check the length
         Assert.assertEquals(0x3D8, 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() );
+        }
     }
 }



Mime
View raw message