directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r987606 [16/25] - in /directory/shared/trunk: ./ all/ asn1-codec/ asn1-codec/src/main/java/org/apache/directory/shared/asn1/codec/ asn1/ asn1/src/main/java/org/apache/directory/shared/asn1/ber/grammar/ asn1/src/main/java/org/apache/director...
Date Fri, 20 Aug 2010 19:23:37 GMT
Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapControlTest.java Fri Aug 20 19:23:27 2010
@@ -19,13 +19,14 @@
  */
 package org.apache.directory.shared.ldap.codec;
 
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -33,7 +34,9 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
-import org.apache.directory.shared.ldap.codec.abandon.AbandonRequestCodec;
+import org.apache.directory.shared.ldap.message.AbandonRequest;
+import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
@@ -44,6 +47,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class LdapControlTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a Request with controls
      */
@@ -54,39 +61,29 @@ public class LdapControlTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x64 );
         stream.put( new byte[]
-            { 
-            0x30, 0x62,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x03,         // messageID MessageID
-              0x50, 0x01, 0x02,         // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-              ( byte ) 0xA0, 0x5A,      // controls [0] Controls OPTIONAL }
-                0x30, 0x1A,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x0D, 
-                    '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
-                                        // criticality BOOLEAN DEFAULT FALSE,
-                  0x01, 0x01, ( byte ) 0xFF, 
-                                        // controlValue OCTET STRING OPTIONAL }
-                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 
-                0x30, 0x17,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x0D, 
-                    '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
-                                        // controlValue OCTET STRING OPTIONAL }
-                  0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 
-                0x30, 0x12,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x0D, 
-                    '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
-                                        // criticality BOOLEAN DEFAULT FALSE}
-                  0x01, 0x01, ( byte ) 0xFF, 
-                0x30, 0x0F,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID}
-                0x04, 0x0D, 
-                  '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' 
-            } );
+            { 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03, // messageID MessageID
+                0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+                // AbandonRequest,...
+                ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
+                0x30, 0x1A, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+                // criticality BOOLEAN DEFAULT FALSE,
+                0x01, 0x01, ( byte ) 0xFF,
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, 0x17, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, 0x12, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
+                // criticality BOOLEAN DEFAULT FALSE}
+                0x01, 0x01, ( byte ) 0xFF, 0x30, 0x0F, // Control ::= SEQUENCE {
+                // controlType LDAPOID}
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' } );
 
-        String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessageContainer Container
@@ -104,47 +101,68 @@ public class LdapControlTest
         }
 
         // Check that everything is OK
-        AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+        AbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+
+        // Copy the message
+        AbandonRequest internalAbandonRequest = new AbandonRequestImpl( abandonRequest.getMessageId() );
+        internalAbandonRequest.setAbandoned( abandonRequest.getAbandoned() );
 
         assertEquals( 3, abandonRequest.getMessageId() );
-        assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+        assertEquals( 2, abandonRequest.getAbandoned() );
 
         // Check the Controls
-        List<Control> controls = abandonRequest.getControls();
+        Map<String, Control> controls = abandonRequest.getControls();
 
         assertEquals( 4, controls.size() );
 
-        Control control = abandonRequest.getControls( 0 );
+        Control control = controls.get( "1.3.6.1.5.5.1" );
         assertEquals( "1.3.6.1.5.5.1", control.getOid() );
         assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertTrue( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 1 );
+        control = controls.get( "1.3.6.1.5.5.2" );
         assertEquals( "1.3.6.1.5.5.2", control.getOid() );
         assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertFalse( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 2 );
+        control = controls.get( "1.3.6.1.5.5.3" );
         assertEquals( "1.3.6.1.5.5.3", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertTrue( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 3 );
+        control = controls.get( "1.3.6.1.5.5.4" );
         assertEquals( "1.3.6.1.5.5.4", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertFalse( control.isCritical() );
-
-        // Check the length
-        assertEquals( 0x64, abandonRequest.computeLength() );
+        internalAbandonRequest.addControl( control );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = abandonRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( internalAbandonRequest );
 
-            String encodedPdu = StringTools.dumpBytes( bb.array() );
+            // Check the length
+            assertEquals( 0x64, bb.limit() );
 
-            assertEquals( encodedPdu, decodedPdu );
+            // Don't check the PDU, as control are in a Map, and can be in a different order
+            // So we decode the generated PDU, and we compare it with the initial message
+            try
+            {
+                ldapDecoder.decode( bb, ldapMessageContainer );
+            }
+            catch ( DecoderException de )
+            {
+                de.printStackTrace();
+                fail( de.getMessage() );
+            }
+
+            AbandonRequest abandonRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer )
+                .getAbandonRequest();
+
+            assertEquals( abandonRequest, abandonRequest2 );
         }
         catch ( EncoderException ee )
         {
@@ -153,6 +171,7 @@ public class LdapControlTest
         }
     }
 
+
     /**
      * Test the decoding of a Request with null OID controls
      */
@@ -163,20 +182,18 @@ public class LdapControlTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x19 );
         stream.put( new byte[]
-            { 
-            0x30, 0x17,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x03,         // messageID MessageID
-              0x50, 0x01, 0x02,         // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-              ( byte ) 0xA0, 0x0F,      // controls [0] Controls OPTIONAL }
-                0x30, 0x0D,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x00, 
-                                        // criticality BOOLEAN DEFAULT FALSE,
-                  0x01, 0x01, ( byte ) 0xFF, 
-                                        // controlValue OCTET STRING OPTIONAL }
-                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 
-            } );
+            { 0x30, 0x17, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03, // messageID MessageID
+                0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+                // AbandonRequest,...
+                ( byte ) 0xA0, 0x0F, // controls [0] Controls OPTIONAL }
+                0x30, 0x0D, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x00,
+                // criticality BOOLEAN DEFAULT FALSE,
+                0x01, 0x01, ( byte ) 0xFF,
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
 
         stream.flip();
 
@@ -197,6 +214,7 @@ public class LdapControlTest
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a Request with bad OID controls
      */
@@ -207,20 +225,18 @@ public class LdapControlTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x20 );
         stream.put( new byte[]
-            { 
-            0x30, 0x1E,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x03,         // messageID MessageID
-              0x50, 0x01, 0x02,         // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-              ( byte ) 0xA0, 0x16,      // controls [0] Controls OPTIONAL }
-                0x30, 0x14,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x07, 'b', 'a', 'd', ' ', 'o', 'i', 'd',
-                                        // criticality BOOLEAN DEFAULT FALSE,
-                  0x01, 0x01, ( byte ) 0xFF, 
-                                        // controlValue OCTET STRING OPTIONAL }
-                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 
-            } );
+            { 0x30, 0x1E, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03, // messageID MessageID
+                0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+                // AbandonRequest,...
+                ( byte ) 0xA0, 0x16, // controls [0] Controls OPTIONAL }
+                0x30, 0x14, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x07, 'b', 'a', 'd', ' ', 'o', 'i', 'd',
+                // criticality BOOLEAN DEFAULT FALSE,
+                0x01, 0x01, ( byte ) 0xFF,
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
 
         stream.flip();
 
@@ -241,6 +257,7 @@ public class LdapControlTest
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a Request with bad criticality
      */
@@ -251,21 +268,18 @@ public class LdapControlTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x25 );
         stream.put( new byte[]
-            { 
-            0x30, 0x23,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x03,         // messageID MessageID
-              0x50, 0x01, 0x02,         // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-              ( byte ) 0xA0, 0x1B,      // controls [0] Controls OPTIONAL }
-                0x30, 0x19,             // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                  0x04, 0x0D, 
-                    '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
-                                        // criticality BOOLEAN DEFAULT FALSE,
-                  0x01, 0x00, 
-                                        // controlValue OCTET STRING OPTIONAL }
-                  0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 
-            } );
+            { 0x30, 0x23, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03, // messageID MessageID
+                0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+                // AbandonRequest,...
+                ( byte ) 0xA0, 0x1B, // controls [0] Controls OPTIONAL }
+                0x30, 0x19, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+                // criticality BOOLEAN DEFAULT FALSE,
+                0x01, 0x00,
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', } );
 
         stream.flip();
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapDecoderTest.java Fri Aug 20 19:23:27 2010
@@ -21,6 +21,7 @@ package org.apache.directory.shared.ldap
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
@@ -31,8 +32,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.ber.tlv.TLVStateEnum;
 import org.apache.directory.shared.asn1.codec.DecoderException;
-import org.apache.directory.shared.ldap.codec.bind.BindRequestCodec;
-import org.apache.directory.shared.ldap.codec.bind.SimpleAuthentication;
+import org.apache.directory.shared.ldap.message.BindRequest;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -61,15 +61,20 @@ public class LdapDecoderTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
-            { 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+            { 0x30,
+                0x33, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x2E, // CHOICE { ..., bindRequest BindRequest, ...
                 // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03, // version INTEGER (1..127),
-                0x04, 0x1F, // name LDAPDN,
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04,
+                0x1F, // name LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
                 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication
-                                                                                            // AuthenticationChoice
+                // AuthenticationChoice
                 // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
                 // ...
                 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
@@ -91,14 +96,13 @@ public class LdapDecoderTest
         }
 
         // Check the decoded PDU
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) );
-        assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() )
-            .getSimple() ) );
+        assertTrue( bindRequest.isSimple() );
+        assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) );
     }
 
 
@@ -140,12 +144,12 @@ public class LdapDecoderTest
         assertEquals( TLVStateEnum.VALUE_STATE_PENDING, ldapMessageContainer.getState() );
 
         // Check the decoded PDU
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( null, bindRequest.getName() );
-        assertEquals( false, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) );
+        assertTrue( bindRequest.isSimple() );
     }
 
 
@@ -191,7 +195,7 @@ public class LdapDecoderTest
         stream.put( new byte[]
             { 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',',
                 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication
-                                                                    // AuthenticationChoice
+                // AuthenticationChoice
                 // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
                 // ...
                 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
@@ -212,14 +216,13 @@ public class LdapDecoderTest
         assertEquals( ldapMessageContainer.getState(), TLVStateEnum.PDU_DECODED );
 
         // Check the decoded PDU
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "uid=akarasulu,dc=example,dc=com", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) );
-        assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() )
-            .getSimple() ) );
+        assertTrue( bindRequest.isSimple() );
+        assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) );
     }
 
 
@@ -236,16 +239,21 @@ public class LdapDecoderTest
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
             {
-            // Length should be 0x33...
-                0x30, 0x32, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x60, 0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+                // Length should be 0x33...
+                0x30,
+                0x32, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x2E, // CHOICE { ..., bindRequest BindRequest, ...
                 // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03, // version INTEGER (1..127),
-                0x04, 0x1F, // name LDAPDN,
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04,
+                0x1F, // name LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
                 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication
-                                                                                            // AuthenticationChoice
+                // AuthenticationChoice
                 // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
                 // ...
                 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
@@ -282,20 +290,23 @@ public class LdapDecoderTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
-            { 
-            0x30, 0x33,                 // LDAPMessage ::=SEQUENCE {
-                                        // Length should be 0x01...
-              0x02, 0x02, 0x01,         // messageID MessageID
-              0x60, 0x2E,               // CHOICE { ..., bindRequest BindRequest, ...
-                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x1F,             // name LDAPDN,
-                  'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
-                  'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', 
-                ( byte ) 0x80, 0x08,    // authentication AuthenticationChoice
-                                        // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
-                                        // ...
-                  'p', 'a', 's', 's', 'w', 'o', 'r' } );
+            { 0x30,
+                0x33, // LDAPMessage ::=SEQUENCE {
+                // Length should be 0x01...
+                0x02, 0x02,
+                0x01, // messageID MessageID
+                0x60,
+                0x2E, // CHOICE { ..., bindRequest BindRequest, ...
+                // BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04,
+                0x1F, // name LDAPDN,
+                'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
+                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+                // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+                // ...
+                'p', 'a', 's', 's', 'w', 'o', 'r' } );
 
         stream.flip();
 
@@ -329,16 +340,21 @@ public class LdapDecoderTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
-            { 0x30, 0x33, // LDAPMessage ::=SEQUENCE {
+            { 0x30,
+                0x33, // LDAPMessage ::=SEQUENCE {
                 // Length should be 0x01...
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x2D, 0x2D, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x2D,
+                0x2D, // CHOICE { ..., bindRequest BindRequest, ...
                 // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03, // version INTEGER (1..127),
-                0x04, 0x1F, // name LDAPDN,
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04,
+                0x1F, // name LDAPDN,
                 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a',
                 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0x80, 0x08, // authentication
-                                                                                            // AuthenticationChoice
+                // AuthenticationChoice
                 // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
                 // ...
                 'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
@@ -362,6 +378,7 @@ public class LdapDecoderTest
         fail( "Should never reach this point." );
     }
 
+
     /**
      * Test the decoding of a splitted Length.
      * 
@@ -376,8 +393,7 @@ public class LdapDecoderTest
 
         ByteBuffer stream = ByteBuffer.allocate( 3 );
         stream.put( new byte[]
-            { 
-            0x30, (byte)0x82, 0x01,// LDAPMessage ::=SEQUENCE {
+            { 0x30, ( byte ) 0x82, 0x01,// LDAPMessage ::=SEQUENCE {
             } );
 
         stream.flip();
@@ -401,8 +417,7 @@ public class LdapDecoderTest
         // Second block of data
         stream = ByteBuffer.allocate( 1 );
         stream.put( new byte[]
-            { 
-                (byte)0x80 // End of the length
+            { ( byte ) 0x80 // End of the length
             } );
 
         stream.flip();

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapMessageTest.java Fri Aug 20 19:23:27 2010
@@ -32,6 +32,10 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.UnbindRequest;
+import org.apache.directory.shared.ldap.message.UnbindRequestImpl;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -46,6 +50,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class LdapMessageTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     // ~ Methods
     // ------------------------------------------------------------------------------------
 
@@ -60,8 +68,7 @@ public class LdapMessageTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x02 );
         stream.put( new byte[]
-            { 
-            0x30, 0x00,                 // LDAPMessage ::=SEQUENCE {
+            { 0x30, 0x00, // LDAPMessage ::=SEQUENCE {
             } );
 
         stream.flip();
@@ -95,9 +102,8 @@ public class LdapMessageTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x04 );
         stream.put( new byte[]
-            { 
-            0x30, 0x02,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x00                // messageID MessageID
+            { 0x30, 0x02, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x00 // messageID MessageID
             } );
 
         stream.flip();
@@ -131,9 +137,8 @@ public class LdapMessageTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x05 );
         stream.put( new byte[]
-            { 
-            0x30, 0x03,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, ( byte ) 0xff // messageID MessageID = -1
+            { 0x30, 0x03, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, ( byte ) 0xff // messageID MessageID = -1
             } );
 
         stream.flip();
@@ -167,11 +172,9 @@ public class LdapMessageTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x08 );
         stream.put( new byte[]
-            { 
-            0x30, 0x06,                 // LDAPMessage ::=SEQUENCE {
-                                        // messageID MessageID = -1
-              0x02, 0x04, ( byte ) 0x7f, ( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff
-            } );
+            { 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
+                // messageID MessageID = -1
+                0x02, 0x04, ( byte ) 0x7f, ( byte ) 0xff, ( byte ) 0xff, ( byte ) 0xff } );
 
         stream.flip();
 
@@ -201,10 +204,9 @@ public class LdapMessageTest
     {
 
         byte[] buffer = new byte[]
-            { 
-            0x30, 0x05,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID = 1
-              0x42, 0x00                // ProtocolOp
+            { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID = 1
+                0x42, 0x00 // ProtocolOp
             };
 
         Asn1Decoder ldapDecoder = new Asn1Decoder();
@@ -287,11 +289,10 @@ public class LdapMessageTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x08 );
         stream.put( new byte[]
-            { 
-            0x30, 0x06,                         // LDAPMessage ::=SEQUENCE {
-              0x02, 0x02, 0x01, ( byte ) 0xF4,  // messageID MessageID (500)
-              0x42, 0x00,                       // CHOICE { ..., unbindRequest UnbindRequest,...
-                                                // UnbindRequest ::= [APPLICATION 2] NULL
+            { 0x30, 0x06, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x02, 0x01, ( byte ) 0xF4, // messageID MessageID (500)
+                0x42, 0x00, // CHOICE { ..., unbindRequest UnbindRequest,...
+            // UnbindRequest ::= [APPLICATION 2] NULL
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -310,16 +311,19 @@ public class LdapMessageTest
             fail( de.getMessage() );
         }
 
-        LdapMessageCodec message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        Message message = ( ( LdapMessageContainer ) ldapMessageContainer ).getMessage();
 
         assertEquals( 500, message.getMessageId() );
 
         // Check the length
-        assertEquals( 8, message.computeLength() );
+        UnbindRequest internalUnbindRequest = new UnbindRequestImpl( message.getMessageId() );
 
         try
         {
-            ByteBuffer bb = message.encode();
+            ByteBuffer bb = encoder.encodeMessage( internalUnbindRequest );
+
+            // Check the length
+            assertEquals( 0x08, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapResultTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapResultTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapResultTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/LdapResultTest.java Fri Aug 20 19:23:27 2010
@@ -21,10 +21,12 @@ package org.apache.directory.shared.ldap
 
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
+import java.util.Collection;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -32,9 +34,10 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
-import org.apache.directory.shared.ldap.codec.add.AddResponseCodec;
+import org.apache.directory.shared.ldap.message.AddResponse;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Referral;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
-import org.apache.directory.shared.ldap.util.LdapURL;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -50,6 +53,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class LdapResultTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     // ~ Methods
     // ------------------------------------------------------------------------------------
 
@@ -284,19 +291,19 @@ public class LdapResultTest
         }
 
         // Check the decoded AddResponse
-        AddResponseCodec addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
+        AddResponse addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
 
         assertEquals( 1, addResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, addResponse.getLdapResult().getResultCode() );
-        assertEquals( "", addResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x0E, addResponse.computeLength() );
-
         try
         {
-            ByteBuffer bb = addResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( addResponse );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -347,25 +354,27 @@ public class LdapResultTest
         }
 
         // Check the decoded AddResponse
-        AddResponseCodec addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
+        AddResponse addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
 
         assertEquals( 1, addResponse.getMessageId() );
         assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
-        assertEquals( "", addResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
 
-        assertEquals( 1, addResponse.getLdapResult().getReferrals().size() );
-
-        LdapURL referral = addResponse.getLdapResult().getReferrals().get( 0 );
+        Referral referral = addResponse.getLdapResult().getReferral();
 
-        assertEquals( "ldap:///", referral.toString() );
+        assertNotNull( referral );
+        assertEquals( 1, referral.getLdapUrls().size() );
+        Collection<String> ldapUrls = referral.getLdapUrls();
 
-        // Check the length
-        assertEquals( 0x1A, addResponse.computeLength() );
+        assertTrue( ldapUrls.contains( "ldap:///" ) );
 
         try
         {
-            ByteBuffer bb = addResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( addResponse );
+
+            // Check the length
+            assertEquals( 0x1A, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -390,12 +399,18 @@ public class LdapResultTest
         ByteBuffer stream = ByteBuffer.allocate( 0x24 );
 
         stream.put( new byte[]
-            { 0x30, 0x22, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x69, 0x1D, // CHOICE { ..., addResponse AddResponse, ...
-                0x0A, 0x01, 0x0A, // resultCode success (Referral)
-                0x04, 0x00, // Empty matched DN
-                0x04, 0x00, // Empty errorMessage
+            { 0x30,
+                0x22, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x69,
+                0x1D, // CHOICE { ..., addResponse AddResponse, ...
+                0x0A, 0x01,
+                0x0A, // resultCode success (Referral)
+                0x04,
+                0x00, // Empty matched DN
+                0x04,
+                0x00, // Empty errorMessage
                 ( byte ) 0xA3, 0x14, 0x04, 0x08, 'l', 'd', 'a', 'p', ':', '/', '/', '/', 0x04, 0x08, 'l', 'd', 'a',
                 'p', ':', '/', '/', '/' } );
 
@@ -417,29 +432,32 @@ public class LdapResultTest
         }
 
         // Check the decoded AddResponse
-        AddResponseCodec addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
+        AddResponse addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
 
         assertEquals( 1, addResponse.getMessageId() );
         assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
-        assertEquals( "", addResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
 
-        assertEquals( 2, addResponse.getLdapResult().getReferrals().size() );
-
-        LdapURL referral = addResponse.getLdapResult().getReferrals().get( 0 );
+        Referral referral = addResponse.getLdapResult().getReferral();
 
-        assertEquals( "ldap:///", referral.toString() );
+        assertNotNull( referral );
 
-        referral = addResponse.getLdapResult().getReferrals().get( 1 );
+        assertEquals( 2, referral.getLdapUrls().size() );
 
-        assertEquals( "ldap:///", referral.toString() );
+        Collection<String> ldapUrls = referral.getLdapUrls();
 
-        // Check the length
-        assertEquals( 0x24, addResponse.computeLength() );
+        for ( String ldapUrl : ldapUrls )
+        {
+            assertEquals( "ldap:///", ldapUrl );
+        }
 
         try
         {
-            ByteBuffer bb = addResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( addResponse );
+
+            // Check the length
+            assertEquals( 0x24, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -491,29 +509,37 @@ public class LdapResultTest
         }
 
         // Check the decoded AddResponse
-        AddResponseCodec addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
+        AddResponse addResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddResponse();
 
         assertEquals( 1, addResponse.getMessageId() );
         assertEquals( ResultCodeEnum.REFERRAL, addResponse.getLdapResult().getResultCode() );
-        assertEquals( "", addResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", addResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", addResponse.getLdapResult().getErrorMessage() );
 
-        assertEquals( 2, addResponse.getLdapResult().getReferrals().size() );
+        Referral referral = addResponse.getLdapResult().getReferral();
 
-        LdapURL referral = addResponse.getLdapResult().getReferrals().get( 0 );
+        assertNotNull( referral );
 
-        assertEquals( "ldap:///", referral.toString() );
+        assertEquals( 2, referral.getLdapUrls().size() );
 
-        referral = addResponse.getLdapResult().getReferrals().get( 1 );
+        Collection<String> ldapUrls = referral.getLdapUrls();
 
-        assertEquals( "ldap:///", referral.toString() );
+        String[] expected = new String[]
+            { "ldap:///", "" };
+        int i = 0;
 
-        // Check the length
-        assertEquals( 0x1C, addResponse.computeLength() );
+        for ( String ldapUrl : ldapUrls )
+        {
+            assertEquals( expected[i], ldapUrl );
+            i++;
+        }
 
         try
         {
-            ByteBuffer bb = addResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( addResponse );
+
+            // Check the length
+            assertEquals( 0x1C, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/abandon/AbandonRequestTest.java Fri Aug 20 19:23:27 2010
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -35,6 +35,9 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.DecoderException;
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
+import org.apache.directory.shared.ldap.message.AbandonRequest;
+import org.apache.directory.shared.ldap.message.AbandonRequestImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
@@ -50,6 +53,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class AbandonRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a AbandonRequest with controls
      */
@@ -60,40 +67,29 @@ public class AbandonRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x64 );
         stream.put( new byte[]
-            { 
-            0x30, 0x62,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x03,         // messageID MessageID
-              0x50, 0x01, 0x02,         // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-                ( byte ) 0xA0, 0x5A,    // controls [0] Controls OPTIONAL }
-                  0x30, 0x1A,           // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                    0x04, 0x0D, 
-                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
-                                        // criticality BOOLEAN DEFAULT FALSE,
-                    0x01, 0x01, ( byte ) 0xFF, 
-                                        // controlValue OCTET STRING OPTIONAL }
-                    0x04, 0x06, 
-                      'a', 'b', 'c', 'd', 'e', 'f', 
-                  0x30, 0x17,         // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                    0x04, 0x0D, 
-                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
-                                        // controlValue OCTET STRING OPTIONAL }
-                    0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 
-                  0x30, 0x12,           // Control ::= SEQUENCE {
-                                        // controlType LDAPOID,
-                    0x04, 0x0D, 
-                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
-                                        // criticality BOOLEAN DEFAULT FALSE }
-                    0x01, 0x01, ( byte ) 0xFF, 
-                  0x30, 0x0F,           // Control ::= SEQUENCE {
-                                        // controlType LDAPOID}
-                    0x04, 0x0D, 
-                      '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' 
-            } );
+            { 0x30, 0x62, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x03, // messageID MessageID
+                0x50, 0x01, 0x02, // CHOICE { ..., abandonRequest
+                // AbandonRequest,...
+                ( byte ) 0xA0, 0x5A, // controls [0] Controls OPTIONAL }
+                0x30, 0x1A, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '1',
+                // criticality BOOLEAN DEFAULT FALSE,
+                0x01, 0x01, ( byte ) 0xFF,
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f', 0x30, 0x17, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '2',
+                // controlValue OCTET STRING OPTIONAL }
+                0x04, 0x06, 'g', 'h', 'i', 'j', 'k', 'l', 0x30, 0x12, // Control ::= SEQUENCE {
+                // controlType LDAPOID,
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '3',
+                // criticality BOOLEAN DEFAULT FALSE }
+                0x01, 0x01, ( byte ) 0xFF, 0x30, 0x0F, // Control ::= SEQUENCE {
+                // controlType LDAPOID}
+                0x04, 0x0D, '1', '.', '3', '.', '6', '.', '1', '.', '5', '.', '5', '.', '4' } );
 
-        String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessageContainer Container
@@ -111,47 +107,68 @@ public class AbandonRequestTest
         }
 
         // Check that everything is OK
-        AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+        AbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+
+        // Copy the message
+        AbandonRequest internalAbandonRequest = new AbandonRequestImpl( abandonRequest.getMessageId() );
+        internalAbandonRequest.setAbandoned( abandonRequest.getAbandoned() );
 
         assertEquals( 3, abandonRequest.getMessageId() );
-        assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+        assertEquals( 2, abandonRequest.getAbandoned() );
 
         // Check the Controls
-        List<Control> controls = abandonRequest.getControls();
+        Map<String, Control> controls = abandonRequest.getControls();
 
         assertEquals( 4, controls.size() );
 
-        Control control = abandonRequest.getControls( 0 );
+        Control control = controls.get( "1.3.6.1.5.5.1" );
         assertEquals( "1.3.6.1.5.5.1", control.getOid() );
         assertEquals( "0x61 0x62 0x63 0x64 0x65 0x66 ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertTrue( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 1 );
+        control = controls.get( "1.3.6.1.5.5.2" );
         assertEquals( "1.3.6.1.5.5.2", control.getOid() );
         assertEquals( "0x67 0x68 0x69 0x6A 0x6B 0x6C ", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertFalse( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 2 );
+        control = controls.get( "1.3.6.1.5.5.3" );
         assertEquals( "1.3.6.1.5.5.3", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertTrue( control.isCritical() );
+        internalAbandonRequest.addControl( control );
 
-        control = abandonRequest.getControls( 3 );
+        control = controls.get( "1.3.6.1.5.5.4" );
         assertEquals( "1.3.6.1.5.5.4", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
         assertFalse( control.isCritical() );
-
-        // Check the length
-        assertEquals( 0x64, abandonRequest.computeLength() );
+        internalAbandonRequest.addControl( control );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = abandonRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( internalAbandonRequest );
 
-            String encodedPdu = StringTools.dumpBytes( bb.array() );
+            // Check the length
+            assertEquals( 0x64, bb.limit() );
+
+            // Don't check the PDU, as control are in a Map, and can be in a different order
+            // So we decode the generated PDU, and we compare it with the initial message
+            try
+            {
+                ldapDecoder.decode( bb, ldapMessageContainer );
+            }
+            catch ( DecoderException de )
+            {
+                de.printStackTrace();
+                fail( de.getMessage() );
+            }
 
-            assertEquals( decodedPdu, encodedPdu );
+            AbandonRequest abandonRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer )
+                .getAbandonRequest();
+
+            assertEquals( abandonRequest, abandonRequest2 );
         }
         catch ( EncoderException ee )
         {
@@ -171,13 +188,11 @@ public class AbandonRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
-            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
-                                        // messageID MessageID
-              0x02, 0x03, 0x00, ( byte ) 0x80, 0x13, 
-              0x50, 0x01, 0x02          // CHOICE { ..., abandonRequest
-                                        // AbandonRequest,...
-                                        // AbandonRequest ::= [APPLICATION 16] MessageID
+            { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+                // messageID MessageID
+                0x02, 0x03, 0x00, ( byte ) 0x80, 0x13, 0x50, 0x01, 0x02 // CHOICE { ..., abandonRequest
+            // AbandonRequest,...
+            // AbandonRequest ::= [APPLICATION 16] MessageID
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -198,18 +213,22 @@ public class AbandonRequestTest
         }
 
         // Check that everything is OK
-        AbandonRequestCodec abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
+        AbandonRequest abandonRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAbandonRequest();
 
         assertEquals( 32787, abandonRequest.getMessageId() );
-        assertEquals( 2, abandonRequest.getAbandonedMessageId() );
+        assertEquals( 2, abandonRequest.getAbandoned() );
 
         // Check the length
-        assertEquals( 10, abandonRequest.computeLength() );
+        AbandonRequest internalAbandonRequest = new AbandonRequestImpl( abandonRequest.getMessageId() );
+        internalAbandonRequest.setAbandoned( abandonRequest.getAbandoned() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = abandonRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( internalAbandonRequest );
+
+            // Check the length
+            assertEquals( 0x0A, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -233,11 +252,10 @@ public class AbandonRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
-            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x50, 0x00                // CHOICE { ..., abandonRequest AbandonRequest,...
-                                        // AbandonRequest ::= [APPLICATION 16] MessageID
+            { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x50, 0x00 // CHOICE { ..., abandonRequest AbandonRequest,...
+            // AbandonRequest ::= [APPLICATION 16] MessageID
             } );
 
         stream.flip();
@@ -259,6 +277,7 @@ public class AbandonRequestTest
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a AbandonRequest with a bad Message Id
      */
@@ -269,11 +288,10 @@ public class AbandonRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0B );
         stream.put( new byte[]
-            { 
-            0x30, 0x09,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x50, 0x01, (byte)0xFF    // CHOICE { ..., abandonRequest AbandonRequest,...
-                                        // AbandonRequest ::= [APPLICATION 16] MessageID
+            { 0x30, 0x09, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x50, 0x01, ( byte ) 0xFF // CHOICE { ..., abandonRequest AbandonRequest,...
+            // AbandonRequest ::= [APPLICATION 16] MessageID
             } );
 
         stream.flip();

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddRequestTest.java Fri Aug 20 19:23:27 2010
@@ -27,7 +27,6 @@ import static org.junit.Assert.fail;
 import java.nio.ByteBuffer;
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
@@ -44,10 +43,12 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.entry.Entry;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Value;
+import org.apache.directory.shared.ldap.message.AddRequest;
 import org.apache.directory.shared.ldap.message.AddResponseImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Message;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
-import org.apache.directory.shared.ldap.message.internal.InternalMessage;
 import org.apache.directory.shared.ldap.util.StringTools;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -62,6 +63,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class AddRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a AddRequest
      */
@@ -73,34 +78,43 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x59 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x57,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x52,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+            {
+                0x30,
+                0x57, // LDAPMessage ::= SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x52, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
                 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x2E,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x0c,           // attribute 1
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                  0x30, 0x1E,           // attribute 2
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x15,         // vals SET
-                                        // OF
-                                        // AttributeValue
-                                        // }
-                      0x04, 0x05, 't', 'e', 's', 't', '1', 
-                      0x04, 0x05, 't', 'e', 's', 't', '2', 
-                      0x04, 0x05, 't', 'e', 's', 't', '3', 
-            } );
+                // attributes AttributeList }
+                0x30,
+                0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30,
+                0x0c, // attribute 1
+                0x04, 0x01,
+                'l', // type AttributeDescription,
+                0x31,
+                0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30,
+                0x1E, // attribute 2
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r',
+                's',
+                0x31,
+                0x15, // vals SET
+                // OF
+                // AttributeValue
+                // }
+                0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's',
+                't', '3', } );
 
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a LdapMessage Container
@@ -117,7 +131,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        AddRequestCodec addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
+        AddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );
@@ -150,7 +164,7 @@ public class AddRequestTest
 
         Set<String> vals = ( Set<String> ) typesVals.get( attribute.getId().toLowerCase() );
 
-        for ( Value<?> value:attribute )
+        for ( Value<?> value : attribute )
         {
             assertTrue( vals.contains( value.get() ) );
 
@@ -163,15 +177,41 @@ public class AddRequestTest
 
         vals = ( Set<String> ) typesVals.get( attribute.getId().toLowerCase() );
 
-        for ( Value<?> value:attribute )
+        for ( Value<?> value : attribute )
         {
             assertTrue( vals.contains( value.get() ) );
 
             vals.remove( value.get() );
         }
 
-        // Check the length
-        assertEquals( 0x59, addRequest.computeLength() );
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = encoder.encodeMessage( addRequest );
+
+            // Check the length
+            assertEquals( 0x59, bb.limit() );
+
+            // We cannot compare the PDU, as the attributes order is not
+            // kept. Let's decode again and compare the resulting AddRequest
+            try
+            {
+                ldapDecoder.decode( bb, ldapMessageContainer );
+            }
+            catch ( DecoderException de )
+            {
+                de.printStackTrace();
+                fail( de.getMessage() );
+            }
+
+            AddRequest addRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
+            assertEquals( addRequest, addRequest2 );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
     }
 
 
@@ -186,10 +226,9 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x05, // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01, // messageID MessageID
-              0x68, 0x00 // CHOICE { ..., addRequest AddRequest, ...
+            { 0x30, 0x05, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x68, 0x00 // CHOICE { ..., addRequest AddRequest, ...
             } );
 
         stream.flip();
@@ -223,31 +262,38 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x39 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x37,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x26,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
+            { 0x30,
+                0x37, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x26, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
                 0x04, 0x00,
-                                        // attributes AttributeList }
-                0x30, 0x2E,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x0c,           // attribute 1
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                  0x30, 0x1E,           // attribute 2
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x15,         // vals SET
-                                        // OF
-                                        // AttributeValue
-                                        // }
-                      0x04, 0x05, 't', 'e', 's', 't', '1', 
-                      0x04, 0x05, 't', 'e', 's', 't', '2', 
-                      0x04, 0x05, 't', 'e', 's', 't', '3', 
-            } );
+                // attributes AttributeList }
+                0x30,
+                0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30,
+                0x0c, // attribute 1
+                0x04, 0x01,
+                'l', // type AttributeDescription,
+                0x31,
+                0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30,
+                0x1E, // attribute 2
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r',
+                's',
+                0x31,
+                0x15, // vals SET
+                // OF
+                // AttributeValue
+                // }
+                0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's',
+                't', '3', } );
 
         stream.flip();
 
@@ -262,15 +308,17 @@ public class AddRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof AddResponseImpl );
-            assertEquals( ResultCodeEnum.NAMING_VIOLATION, ((AddResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.NAMING_VIOLATION, ( ( AddResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a AddRequest
      */
@@ -282,33 +330,41 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x59 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x57,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x52,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+            {
+                0x30,
+                0x57, // LDAPMessage ::= SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x52, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
                 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x2E,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x0c,           // attribute 1
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                  0x30, 0x1E,           // attribute 2
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x15,         // vals SET
-                                        // OF
-                                        // AttributeValue
-                                        // }
-                      0x04, 0x05, 't', 'e', 's', 't', '1', 
-                      0x04, 0x05, 't', 'e', 's', 't', '2', 
-                      0x04, 0x05, 't', 'e', 's', 't', '3', 
-            } );
+                // attributes AttributeList }
+                0x30,
+                0x2E, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30,
+                0x0c, // attribute 1
+                0x04, 0x01,
+                'l', // type AttributeDescription,
+                0x31,
+                0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30,
+                0x1E, // attribute 2
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r',
+                's',
+                0x31,
+                0x15, // vals SET
+                // OF
+                // AttributeValue
+                // }
+                0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's',
+                't', '3', } );
 
         stream.flip();
 
@@ -323,15 +379,17 @@ public class AddRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof AddResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((AddResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( AddResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a AddRequest with a null attributeList
      */
@@ -343,17 +401,18 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x29,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x24,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x00,             // AttributeList ::= SEQUENCE OF SEQUENCE {
+            { 0x30,
+                0x29, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x24, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
             } );
 
         stream.flip();
@@ -387,18 +446,19 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2B,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x26,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x02,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x00,           // AttributeList ::= SEQUENCE OF SEQUENCE {
+            { 0x30,
+                0x2B, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x26, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x02, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x00, // AttributeList ::= SEQUENCE OF SEQUENCE {
             } );
 
         stream.flip();
@@ -432,19 +492,20 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2F );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2D,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x28,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x04,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x02,           // attribute 1
-                    0x04, 0x00,         // type AttributeDescription,
+            { 0x30,
+                0x2D, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x28, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x04, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x02, // attribute 1
+                0x04, 0x00, // type AttributeDescription,
             } );
 
         stream.flip();
@@ -460,9 +521,10 @@ public class AddRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof AddResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((AddResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( AddResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
@@ -481,19 +543,20 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2E,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x29,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x05,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x03,           // attribute 1
-                    0x04, 0x01, 'A',    // type AttributeDescription,
+            { 0x30,
+                0x2E, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x29, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x05, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x03, // attribute 1
+                0x04, 0x01, 'A', // type AttributeDescription,
             } );
 
         stream.flip();
@@ -527,21 +590,21 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x32 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x30,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x2B,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x07,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x05,           // attribute 1
-                    0x04, 0x01, 'A',    // type AttributeDescription,
-                    0x31, 0x00 
-            } );
+            { 0x30,
+                0x30, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x2B, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x07, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x05, // attribute 1
+                0x04, 0x01, 'A', // type AttributeDescription,
+                0x31, 0x00 } );
 
         stream.flip();
 
@@ -574,22 +637,21 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x34 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x32,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x2D,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x09,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x07,           // attribute 1
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                  0x31, 0x02, 
-                    0x04, 0x00 
-            } );
+            { 0x30,
+                0x32, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x2D, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30, 0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x07, // attribute 1
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x02, 0x04, 0x00 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -608,7 +670,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        AddRequestCodec addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
+        AddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );
@@ -622,18 +684,18 @@ public class AddRequestTest
 
         assertEquals( "l", attribute.getId().toLowerCase() );
 
-        for ( Value<?> value:attribute )
+        for ( Value<?> value : attribute )
         {
             assertEquals( "", value.getString() );
         }
 
-        // Check the length
-        assertEquals( 0x34, addRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = addRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( addRequest );
+
+            // Check the length
+            assertEquals( 0x34, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -659,25 +721,29 @@ public class AddRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x51 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x4F,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x68, 0x2D,               // CHOICE { ..., addRequest AddRequest, ...
-                                        // AddRequest ::= [APPLICATION 8] SEQUENCE {
-                                        // entry LDAPDN,
-                0x04, 0x20, 
-                  'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
-                  's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
-                                        // attributes AttributeList }
-                0x30, 0x09,             // AttributeList ::= SEQUENCE OF SEQUENCE {
-                  0x30, 0x07,           // attribute 1
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                  0x31, 0x02, 
-                    0x04, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
+            {
+                0x30,
+                0x4F, // LDAPMessage ::= SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x68,
+                0x2D, // CHOICE { ..., addRequest AddRequest, ...
+                // AddRequest ::= [APPLICATION 8] SEQUENCE {
+                // entry LDAPDN,
+                0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u',
+                's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+                // attributes AttributeList }
+                0x30,
+                0x09, // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30,
+                0x07, // attribute 1
+                0x04, 0x01,
+                'l', // type AttributeDescription,
+                0x31, 0x02, 0x04, 0x00, ( 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 
-            } );
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -696,7 +762,7 @@ public class AddRequestTest
             fail( de.getMessage() );
         }
 
-        AddRequestCodec addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
+        AddRequest addRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getAddRequest();
 
         // Check the decoded message
         assertEquals( 1, addRequest.getMessageId() );
@@ -709,28 +775,30 @@ public class AddRequestTest
         EntryAttribute attribute = entry.get( "l" );
 
         assertEquals( "l", attribute.getId().toLowerCase() );
- 
-        for ( Value<?> value:attribute )
+
+        for ( Value<?> value : attribute )
         {
             assertEquals( "", value.getString() );
         }
 
-        // Check the length
-        assertEquals( 0x51, addRequest.computeLength() );
-
         // Check the Control
-        List<Control> controls = addRequest.getControls();
+        Map<String, Control> controls = addRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = addRequest.getControls( 0 );
+        assertTrue( addRequest.hasControl( "2.16.840.1.113730.3.4.2" ) );
+
+        Control control = controls.get( "2.16.840.1.113730.3.4.2" );
         assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
         assertEquals( "", StringTools.dumpBytes( ( byte[] ) control.getValue() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = addRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( addRequest );
+
+            // Check the length
+            assertEquals( 0x51, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 



Mime
View raw message