directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r987606 [17/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/add/AddResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddResponseTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddResponseTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/add/AddResponseTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,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;
@@ -34,6 +34,8 @@ 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.AddResponse;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -48,6 +50,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class AddResponseTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a AddResponse
      */
@@ -91,19 +97,19 @@ public class AddResponseTest
         }
 
         // 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() );
 
@@ -164,21 +170,29 @@ public class AddResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 0x30, 0x29, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x69, 0x07, // CHOICE { ..., addResponse AddResponse, ...
+            { 0x30,
+                0x29, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x69,
+                0x07, // CHOICE { ..., addResponse AddResponse, ...
                 // AddResponse ::= [APPLICATION 9] LDAPResult
-                  0x0A, 0x01, 0x00,// LDAPResult ::= SEQUENCE {
+                0x0A,
+                0x01,
+                0x00,// LDAPResult ::= SEQUENCE {
                 // resultCode ENUMERATED {
                 // success (0), ...
                 // },
-                  0x04, 0x00, // matchedDN LDAPDN,
-                  0x04, 0x00, // errorMessage LDAPString,
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 // }
-                ( byte ) 0xA0, 0x1B, // A control
-                  0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
-                  0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
+                ( byte ) 0xA0,
+                0x1B, // A control
+                0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -198,28 +212,29 @@ public class AddResponseTest
         }
 
         // 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( 0x2B, addResponse.computeLength() );
-
         // Check the Control
-        List<Control> controls = addResponse.getControls();
+        Map<String, Control> controls = addResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = addResponse.getControls( 0 );
+        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() ) );
 
         try
         {
-            ByteBuffer bb = addResponse.encode();
+            /** The encoder instance */
+            ByteBuffer bb = encoder.encodeMessage( addResponse );
+
+            // Check the length
+            assertEquals( 0x02B, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestPerfTest.java Fri Aug 20 19:23:27 2010
@@ -21,10 +21,11 @@ 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;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -34,9 +35,13 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.controls.ControlImpl;
+import org.apache.directory.shared.ldap.message.BindRequest;
+import org.apache.directory.shared.ldap.message.BindRequestImpl;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.name.DN;
 import org.apache.directory.shared.ldap.util.StringTools;
+import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -48,36 +53,46 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class BindRequestPerfTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a BindRequest with Simple authentication and no
      * controls
      */
     @Test
+    @Ignore
     public void testDecodeBindRequestSimpleNoControlsPerf()
     {
         Asn1Decoder ldapDecoder = new Asn1Decoder();
 
         ByteBuffer stream = ByteBuffer.allocate( 0x52 );
         stream.put( new byte[]
-             { 
-             0x30, 0x50,                 // 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,
-                 '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', 'd', 
-               ( 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 
-             } );
+            {
+                0x30,
+                0x50, // 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,
+                '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', 'd', ( byte ) 0xA0,
+                0x1B, // A control
+                0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
+                0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -88,19 +103,20 @@ public class BindRequestPerfTest
         // Decode the BindRequest PDU
         try
         {
-            int nbLoops = 1;
-            //long t0 = System.currentTimeMillis();
-            
+            int nbLoops = 1000000;
+            long t0 = System.currentTimeMillis();
+
             for ( int i = 0; i < nbLoops; i++ )
             {
                 ldapDecoder.decode( stream, ldapMessageContainer );
-                ( ( LdapMessageContainer ) ldapMessageContainer).clean();
+                ( ( LdapMessageContainer ) ldapMessageContainer ).clean();
                 stream.flip();
             }
-            
-            //long t1 = System.currentTimeMillis();
-            //System.out.println( "testDecodeBindRequestSimpleNoControlsPerf, " + nbLoops + " loops, Delta = " + ( t1 - t0 ) );
-            
+
+            long t1 = System.currentTimeMillis();
+            System.out.println( "testDecodeBindRequestSimpleNoControlsPerf, " + nbLoops + " loops, Delta = "
+                + ( t1 - t0 ) );
+
             ldapDecoder.decode( stream, ldapMessageContainer );
         }
         catch ( DecoderException de )
@@ -110,31 +126,30 @@ public class BindRequestPerfTest
         }
 
         // Check the decoded BindRequest
-        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() ) );
 
         // Check the Control
-        List<Control> controls = bindRequest.getControls();
+        Map<String, Control> controls = bindRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindRequest.getControls( 0 );
+        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 length
-        assertEquals( 0x52, bindRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x52, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -147,37 +162,35 @@ public class BindRequestPerfTest
         }
     }
 
+
     /**
      * Test the decoding of a BindRequest with Simple authentication and no
      * controls
      */
     @Test
+    @Ignore
     public void testEncodeBindRequestPerf() throws Exception
     {
         DN name = new DN( "uid=akarasulu,dc=example,dc=com" );
-        int nbLoops = 1;
+        int nbLoops = 1000000;
         long t0 = System.currentTimeMillis();
-        
-        for ( int i = 0; i< nbLoops; i++)
+
+        for ( int i = 0; i < nbLoops; i++ )
         {
             // Check the decoded BindRequest
-            BindRequestCodec bindRequest = new BindRequestCodec();
-            bindRequest.setMessageId( 1 );
-            
+            BindRequest bindRequest = new BindRequestImpl( 1 );
+
+            bindRequest.setSimple( true );
             bindRequest.setName( name );
-            
+            bindRequest.setCredentials( StringTools.getBytesUtf8( "password" ) );
             Control control = new ControlImpl( "2.16.840.1.113730.3.4.2" );
 
-            LdapAuthentication authentication = new SimpleAuthentication();
-            ((SimpleAuthentication)authentication).setSimple( StringTools.getBytesUtf8( "password" ) );
-
             bindRequest.addControl( control );
-            bindRequest.setAuthentication( authentication );
-    
+
             // Check the encoding
             try
             {
-                bindRequest.encode();
+                ByteBuffer bb = encoder.encodeMessage( bindRequest );
             }
             catch ( EncoderException ee )
             {
@@ -187,6 +200,6 @@ public class BindRequestPerfTest
         }
 
         long t1 = System.currentTimeMillis();
-        //System.out.println( "BindRequest testEncodeBindRequestPerf, " + nbLoops + " loops, Delta = " + (t1 - t0));
+        System.out.println( "BindRequest testEncodeBindRequestPerf, " + nbLoops + " loops, Delta = " + ( t1 - t0 ) );
     }
 }

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindRequestTest.java Fri Aug 20 19:23:27 2010
@@ -21,11 +21,12 @@ package org.apache.directory.shared.ldap
 
 
 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;
@@ -35,10 +36,12 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
+import org.apache.directory.shared.ldap.message.BindRequest;
 import org.apache.directory.shared.ldap.message.BindResponseImpl;
+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;
@@ -51,6 +54,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class BindRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a BindRequest with Simple authentication and no
      * controls
@@ -161,20 +168,22 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
-            { 
-            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,
+            { 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,
                 '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', 'd' 
-            } );
+                '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', 'd' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -194,22 +203,21 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        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() ) );
-
-        // Check the length
-        assertEquals( 0x35, bindRequest.computeLength() );
+        assertTrue( bindRequest.isSimple() );
+        assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x35, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -222,6 +230,7 @@ public class BindRequestTest
         }
     }
 
+
     /**
      * Test the decoding of a BindRequest with Simple authentication and
      * controls
@@ -233,20 +242,22 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
         stream.put( new byte[]
-            { 
-            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,
-                  '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', 'd' 
-            } );
+            { 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,
+                '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', 'd' } );
 
         stream.flip();
 
@@ -261,9 +272,10 @@ public class BindRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof BindResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((BindResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( BindResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
@@ -282,17 +294,15 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x15 );
         stream.put( new byte[]
-            { 
-            0x30, 0x13,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x0D,               // CHOICE { ..., bindRequest BindRequest, ...
-                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                ( byte ) 0x80, 0x08,    // authentication AuthenticationChoice
-                                        // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
-                                        // ...
-                'p', 'a', 's', 's', 'w', 'o', 'r', 'd' 
-            } );
+            { 0x30, 0x13, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x0D, // CHOICE { ..., bindRequest BindRequest, ...
+                // BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+                // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+                // ...
+                'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
 
         stream.flip();
 
@@ -325,18 +335,16 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x16 );
         stream.put( new byte[]
-            { 
-            0x30, 0x14,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x0F,               // CHOICE { ..., bindRequest BindRequest, ...
-                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00,             // name LDAPDN,
-                ( byte ) 0x80, 0x08,    // authentication AuthenticationChoice
-                                        // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
-                                        // ...
-                'p', 'a', 's', 's', 'w', 'o', 'r', 'd' 
-            } );
+            { 0x30, 0x14, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x0F, // CHOICE { ..., bindRequest BindRequest, ...
+                // BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                0x04, 0x00, // name LDAPDN,
+                ( byte ) 0x80, 0x08, // authentication AuthenticationChoice
+                // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING,
+                // ...
+                'p', 'a', 's', 's', 'w', 'o', 'r', 'd' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
 
@@ -357,22 +365,21 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) );
-        assertEquals( "password", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() )
-            .getSimple() ) );
-
-        // Check the length
-        assertEquals( 0x16, bindRequest.computeLength() );
+        assertTrue( bindRequest.isSimple() );
+        assertEquals( "password", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x16, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -397,24 +404,25 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x3A );
         stream.put( new byte[]
-            { 
-            0x30, 0x38,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x33,               // 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 ) 0xA3, 0x0D,    // authentication AuthenticationChoice
-                                        // AuthenticationChoice ::= CHOICE { ... sasl [3]
-                                        // SaslCredentials }
-                                        // SaslCredentials ::= SEQUENCE {
-                                        // mechanism LDAPSTRING,
-                                        // ...
-                  0x04, 0x0B, 
-                    'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4' 
-            } );
+            { 0x30,
+                0x38, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x33, // 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 ) 0xA3, 0x0D, // authentication AuthenticationChoice
+                // AuthenticationChoice ::= CHOICE { ... sasl [3]
+                // SaslCredentials }
+                // SaslCredentials ::= SEQUENCE {
+                // mechanism LDAPSTRING,
+                // ...
+                0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -434,21 +442,21 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        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 SaslCredentials ) );
-        assertEquals( "KERBEROS_V4", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-
-        // Check the length
-        assertEquals( 0x3A, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x3A, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -473,31 +481,30 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x42 );
         stream.put( new byte[]
-            { 
-            0x30, 0x40,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x3B,               // CHOICE { ..., bindRequest BindRequest, ...
-                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x1F,             // name LDAPDN,
+            { 0x30,
+                0x40, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x3B, // 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 ) 0xA3, 0x15,    // authentication AuthenticationChoice
-                                        // }
-                                        // AuthenticationChoice ::= CHOICE { ... sasl [3]
-                                        // SaslCredentials }
-                                        // SaslCredentials ::= SEQUENCE {
-                                        // mechanism LDAPSTRING,
-                                        // ...
-                  0x04, 0x0B, 
-                    'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4', 
-                  ( byte ) 0x04, 0x06,  // SaslCredentials ::= SEQUENCE {
-                                        // ...
-                                        // credentials OCTET STRING OPTIONAL }
-                                        // 
-                  'a', 'b', 'c', 'd', 'e', 'f' 
-            } );
-        
+                'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', ( byte ) 0xA3, 0x15, // authentication AuthenticationChoice
+                // }
+                // AuthenticationChoice ::= CHOICE { ... sasl [3]
+                // SaslCredentials }
+                // SaslCredentials ::= SEQUENCE {
+                // mechanism LDAPSTRING,
+                // ...
+                0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4', ( byte ) 0x04, 0x06, // SaslCredentials ::= SEQUENCE {
+                // ...
+                // credentials OCTET STRING OPTIONAL }
+                // 
+                'a', 'b', 'c', 'd', 'e', 'f' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -517,23 +524,22 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        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 SaslCredentials ) );
-        assertEquals( "KERBEROS_V4", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-        assertEquals( "abcdef", StringTools.utf8ToString( ( ( SaslCredentials ) bindRequest.getAuthentication() )
-            .getCredentials() ) );
-
-        // Check the length
-        assertEquals( 0x42, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
+        assertEquals( "abcdef", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x42, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -558,29 +564,24 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x23 );
         stream.put( new byte[]
-            { 
-            0x30, 0x21,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x1C,               // CHOICE { ..., bindRequest BindRequest, ...
-                                        // BindRequest ::= APPLICATION[0] SEQUENCE {
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00,             // name LDAPDN,
-                ( byte ) 0xA3, 0x15,    // authentication AuthenticationChoice
-                                        // }
-                                        // AuthenticationChoice ::= CHOICE { ... sasl [3]
-                                        // SaslCredentials }
-                                        // SaslCredentials ::= SEQUENCE {
-                                        // mechanism LDAPSTRING,
-                                        // ...
-                  0x04, 0x0B, 
-                    'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4', 
-                  ( byte ) 0x04, 0x06,  // SaslCredentials ::= SEQUENCE {
-                                        // ...
-                                        // credentials OCTET STRING OPTIONAL }
-                                        // 
-                    'a', 'b', 'c', 'd', 'e', 'f' 
-            } );
-        
+            { 0x30, 0x21, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x1C, // CHOICE { ..., bindRequest BindRequest, ...
+                // BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                0x04, 0x00, // name LDAPDN,
+                ( byte ) 0xA3, 0x15, // authentication AuthenticationChoice
+                // }
+                // AuthenticationChoice ::= CHOICE { ... sasl [3]
+                // SaslCredentials }
+                // SaslCredentials ::= SEQUENCE {
+                // mechanism LDAPSTRING,
+                // ...
+                0x04, 0x0B, 'K', 'E', 'R', 'B', 'E', 'R', 'O', 'S', '_', 'V', '4', ( byte ) 0x04, 0x06, // SaslCredentials ::= SEQUENCE {
+                // ...
+                // credentials OCTET STRING OPTIONAL }
+                // 
+                'a', 'b', 'c', 'd', 'e', 'f' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -600,23 +601,22 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SaslCredentials ) );
-        assertEquals( "KERBEROS_V4", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-        assertEquals( "abcdef", StringTools.utf8ToString( ( ( SaslCredentials ) bindRequest.getAuthentication() )
-            .getCredentials() ) );
-
-        // Check the length
-        assertEquals( 0x23, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "KERBEROS_V4", bindRequest.getSaslMechanism() );
+        assertEquals( "abcdef", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x23, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -640,10 +640,9 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
         stream.put( new byte[]
-            { 
-            0x30, 0x05,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x00                // CHOICE { ..., bindRequest BindRequest, ...
+            { 0x30, 0x05, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x00 // CHOICE { ..., bindRequest BindRequest, ...
             } );
 
         stream.flip();
@@ -676,11 +675,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
         stream.put( new byte[]
-            { 
-            0x30, 0x07,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x02,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x00              // version INTEGER (1..127),
+            { 0x30, 0x07, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x02, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x00 // version INTEGER (1..127),
             } );
 
         stream.flip();
@@ -713,11 +711,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
-            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x03,             // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x00        // version INTEGER (1..127),
+            { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x00 // version INTEGER (1..127),
             } );
 
         stream.flip();
@@ -750,11 +747,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
-            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x03,             // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x04        // version INTEGER (1..127),
+            { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x04 // version INTEGER (1..127),
             } );
 
         stream.flip();
@@ -787,12 +783,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0C );
         stream.put( new byte[]
-            { 
-            0x30, 0x0A,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x04,             // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x02, 0x00, 
-                ( byte ) 0x80           // version INTEGER (1..127),
+            { 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x04, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x02, 0x00, ( byte ) 0x80 // version INTEGER (1..127),
             } );
 
         stream.flip();
@@ -825,11 +819,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0A );
         stream.put( new byte[]
-            { 
-            0x30, 0x08,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x03,             // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03        // version INTEGER (1..127),
+            { 0x30, 0x08, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x03, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03 // version INTEGER (1..127),
             } );
 
         stream.flip();
@@ -862,11 +855,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0C );
         stream.put( new byte[]
-            { 
-            0x30, 0x0A,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x05,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
+            { 0x30, 0x0A, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x05, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
                 0x04, 0x00 } );
 
         stream.flip();
@@ -899,11 +891,10 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0E );
         stream.put( new byte[]
-            { 
-            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x07,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
+            { 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x07, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
                 0x04, 0x00, ( byte ) 0x80, 0x00 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -924,21 +915,21 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SimpleAuthentication ) );
-        assertEquals( "", StringTools.utf8ToString( ( ( SimpleAuthentication ) bindRequest.getAuthentication() ).getSimple() ) );
-
-        // Check the length
-        assertEquals( 0x0E, bindRequest.computeLength() );
+        assertTrue( bindRequest.isSimple() );
+        assertEquals( "", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -962,14 +953,11 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x0E );
         stream.put( new byte[]
-            { 
-            0x30, 0x0C,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x07,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00, 
-                ( byte ) 0xA3, 0x00 
-            } );
+            { 0x30, 0x0C, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x07, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                0x04, 0x00, ( byte ) 0xA3, 0x00 } );
 
         stream.flip();
 
@@ -984,9 +972,10 @@ public class BindRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof BindResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ((BindResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_CREDENTIALS, ( ( BindResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
@@ -1004,15 +993,11 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x10 );
         stream.put( new byte[]
-            { 
-            0x30, 0x0E,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x09,             // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00, 
-                ( byte ) 0xA3, 0x02, 
-                  0x04, 0x00 
-            } );
+            { 0x30, 0x0E, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x09, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                0x04, 0x00, ( byte ) 0xA3, 0x02, 0x04, 0x00 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1032,21 +1017,21 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SaslCredentials ) );
-        assertEquals( "", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-
-        // Check the length
-        assertEquals( 0x10, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "", bindRequest.getSaslMechanism() );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x10, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1114,15 +1099,11 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x12 );
         stream.put( new byte[]
-            { 
-            0x30, 0x10,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-                0x60, 0x0B,             // CHOICE { ..., bindRequest BindRequest, ...
-                  0x02, 0x01, 0x03,     // version INTEGER (1..127),
-                  0x04, 0x00, 
-                  ( byte ) 0xA3, 0x04, 
-                    0x04, 0x00, 
-                    0x04, 0x00, } );
+            { 0x30, 0x10, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01, 0x01, // messageID MessageID
+                0x60, 0x0B, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01, 0x03, // version INTEGER (1..127),
+                0x04, 0x00, ( byte ) 0xA3, 0x04, 0x04, 0x00, 0x04, 0x00, } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1142,22 +1123,22 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SaslCredentials ) );
-        assertEquals( "", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-        assertEquals( "", StringTools.utf8ToString( ( ( SaslCredentials ) bindRequest.getAuthentication() ).getCredentials() ) );
-
-        // Check the length
-        assertEquals( 0x12, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "", bindRequest.getSaslMechanism() );
+        assertEquals( "", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x12, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1182,19 +1163,18 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x2F );
         stream.put( new byte[]
-            { 
-            0x30, 0x2D,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x0B,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00, 
-                ( byte ) 0xA3, 0x04, 
-                  0x04, 0x00, 
-                  0x04, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
+            { 0x30,
+                0x2D, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x0B, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04, 0x00, ( byte ) 0xA3, 0x04, 0x04, 0x00, 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();
@@ -1214,31 +1194,31 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SaslCredentials ) );
-        assertEquals( "", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-        assertEquals( "", StringTools.utf8ToString( ( ( SaslCredentials ) bindRequest.getAuthentication() ).getCredentials() ) );
-
-        // Check the length
-        assertEquals( 0x2F, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "", bindRequest.getSaslMechanism() );
+        assertEquals( "", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the Control
-        List<Control> controls = bindRequest.getControls();
+        Map<String, Control> controls = bindRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindRequest.getControls( 0 );
+        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 = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x2F, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1262,18 +1242,18 @@ public class BindRequestTest
 
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
         stream.put( new byte[]
-            { 
-            0x30, 0x2B,                 // LDAPMessage ::=SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x60, 0x09,               // CHOICE { ..., bindRequest BindRequest, ...
-                0x02, 0x01, 0x03,       // version INTEGER (1..127),
-                0x04, 0x00, 
-                ( byte ) 0xA3, 0x02, 
-                  0x04, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
+            { 0x30,
+                0x2B, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x60,
+                0x09, // CHOICE { ..., bindRequest BindRequest, ...
+                0x02, 0x01,
+                0x03, // version INTEGER (1..127),
+                0x04, 0x00, ( byte ) 0xA3, 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();
@@ -1293,31 +1273,31 @@ public class BindRequestTest
         }
 
         // Check the decoded BindRequest
-        BindRequestCodec bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
+        BindRequest bindRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindRequest();
 
         assertEquals( 1, bindRequest.getMessageId() );
-        assertEquals( 3, bindRequest.getVersion() );
+        assertTrue( bindRequest.isVersion3() );
         assertEquals( "", bindRequest.getName().toString() );
-        assertEquals( true, ( bindRequest.getAuthentication() instanceof SaslCredentials ) );
-        assertEquals( "", ( ( SaslCredentials ) bindRequest.getAuthentication() ).getMechanism() );
-        assertEquals( "", StringTools.utf8ToString( ( ( SaslCredentials ) bindRequest.getAuthentication() ).getCredentials() ) );
-
-        // Check the length
-        assertEquals( 0x2D, bindRequest.computeLength() );
+        assertFalse( bindRequest.isSimple() );
+        assertEquals( "", bindRequest.getSaslMechanism() );
+        assertEquals( "", StringTools.utf8ToString( bindRequest.getCredentials() ) );
 
         // Check the Control
-        List<Control> controls = bindRequest.getControls();
+        Map<String, Control> controls = bindRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindRequest.getControls( 0 );
+        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 = bindRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindRequest );
+
+            // Check the length
+            assertEquals( 0x2D, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/bind/BindResponseTest.java Fri Aug 20 19:23:27 2010
@@ -26,7 +26,7 @@ import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 import java.util.Arrays;
-import java.util.List;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -36,6 +36,8 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.search.controls.pagedSearch.PagedResultsControl;
+import org.apache.directory.shared.ldap.message.BindResponse;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.message.control.Control;
 import org.apache.directory.shared.ldap.util.StringTools;
@@ -50,6 +52,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class BindResponseTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a BindResponse
      */
@@ -94,20 +100,20 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
+        BindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x0E, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -132,32 +138,38 @@ public class BindResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x3C );
 
         stream.put( new byte[]
-            { 
-              0x30, 0x3A,                      // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01,              // messageID MessageID
-                0x61, 0x07,                    // CHOICE { ..., bindResponse BindResponse, ...
-                                               // BindResponse ::= APPLICATION[1] SEQUENCE {
-                                               // COMPONENTS OF LDAPResult,
-                  0x0A, 0x01, 0x00,            // LDAPResult ::= SEQUENCE {
-                                               // resultCode ENUMERATED {
-                                               // success (0), ...
-                                               // },
-                  0x04, 0x00,                  // matchedDN LDAPDN,
-                  0x04, 0x00,                  // errorMessage LDAPString,
-                                               // referral [3] Referral OPTIONAL }
-                                               // serverSaslCreds [7] OCTET STRING OPTIONAL }
-                  ( byte ) 0xa0, 0x2C,         // controls
-                    0x30, 0x2A,                // The PagedSearchControl
-                      0x04, 0x16,              // Oid : 1.2.840.113556.1.4.319
-                        0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 
-                        0x31, 0x31, 0x33, 0x35, 0x35, 0x36, 0x2e, 0x31, 
-                        0x2e, 0x34, 0x2e, 0x33, 0x31, 0x39, // control
-                    0x01, 0x01, ( byte ) 0xff, // criticality: false
-                    0x04, 0x0D,
-                      0x30, 0x0B,
-                        0x02, 0x01, 0x05,      // Size = 5, cookie = "abcdef" 
-                        0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f'
-              } );
+            { 0x30,
+                0x3A, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x61,
+                0x07, // CHOICE { ..., bindResponse BindResponse, ...
+                // BindResponse ::= APPLICATION[1] SEQUENCE {
+                // COMPONENTS OF LDAPResult,
+                0x0A,
+                0x01,
+                0x00, // LDAPResult ::= SEQUENCE {
+                // resultCode ENUMERATED {
+                // success (0), ...
+                // },
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
+                // referral [3] Referral OPTIONAL }
+                // serverSaslCreds [7] OCTET STRING OPTIONAL }
+                ( byte ) 0xa0,
+                0x2C, // controls
+                0x30,
+                0x2A, // The PagedSearchControl
+                0x04,
+                0x16, // Oid : 1.2.840.113556.1.4.319
+                0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 0x31, 0x31, 0x33, 0x35, 0x35, 0x36, 0x2e, 0x31, 0x2e,
+                0x34, 0x2e, 0x33, 0x31, 0x39, // control
+                0x01, 0x01, ( byte ) 0xff, // criticality: false
+                0x04, 0x0D, 0x30, 0x0B, 0x02, 0x01, 0x05, // Size = 5, cookie = "abcdef" 
+                0x04, 0x06, 'a', 'b', 'c', 'd', 'e', 'f' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -177,34 +189,34 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
+        BindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x3C, bindResponse.computeLength() );
-
         // Check the Control
-        List<Control> controls = bindResponse.getControls();
+        Map<String, Control> controls = bindResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindResponse.getControls( 0 );
+        Control control = controls.get( "1.2.840.113556.1.4.319" );
         assertEquals( "1.2.840.113556.1.4.319", control.getOid() );
         assertTrue( control instanceof PagedResultsControl );
-        
-        PagedResultsControl pagedSearchControl = (PagedResultsControl)control;
-        
+
+        PagedResultsControl pagedSearchControl = ( PagedResultsControl ) control;
+
         assertEquals( 5, pagedSearchControl.getSize() );
         assertTrue( Arrays.equals( "abcdef".getBytes(), pagedSearchControl.getCookie() ) );
 
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x3C, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -242,7 +254,7 @@ public class BindResponseTest
                 0x04, 0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 ( byte ) 0x87, 0x00 // serverSaslCreds [7] OCTET STRING OPTIONAL
-                                    // }
+            // }
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -263,21 +275,21 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
+        BindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "", StringTools.utf8ToString( bindResponse.getServerSaslCreds() ) );
 
-        // Check the length
-        assertEquals( 0x10, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x10, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -303,21 +315,31 @@ public class BindResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 0x30, 0x2B, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x61, 0x09, // CHOICE { ..., bindResponse BindResponse, ...
+            { 0x30,
+                0x2B, // LDAPMessage ::=SEQUENCE {
+                0x02,
+                0x01,
+                0x01, // messageID MessageID
+                0x61,
+                0x09, // CHOICE { ..., bindResponse BindResponse, ...
                 // BindResponse ::= APPLICATION[1] SEQUENCE {
                 // COMPONENTS OF LDAPResult,
-                0x0A, 0x01, 0x00, // LDAPResult ::= SEQUENCE {
+                0x0A,
+                0x01,
+                0x00, // LDAPResult ::= SEQUENCE {
                 // resultCode ENUMERATED {
                 // success (0), ...
                 // },
-                0x04, 0x00, // matchedDN LDAPDN,
-                0x04, 0x00, // errorMessage LDAPString,
+                0x04,
+                0x00, // matchedDN LDAPDN,
+                0x04,
+                0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
-                ( byte ) 0x87, 0x00, // serverSaslCreds [7] OCTET STRING
-                                        // OPTIONAL }
-                ( byte ) 0xA0, 0x1B, // A control
+                ( byte ) 0x87,
+                0x00, // serverSaslCreds [7] OCTET STRING
+                // OPTIONAL }
+                ( byte ) 0xA0,
+                0x1B, // A control
                 0x30, 0x19, 0x04, 0x17, 0x32, 0x2E, 0x31, 0x36, 0x2E, 0x38, 0x34, 0x30, 0x2E, 0x31, 0x2E, 0x31, 0x31,
                 0x33, 0x37, 0x33, 0x30, 0x2E, 0x33, 0x2E, 0x34, 0x2E, 0x32 } );
 
@@ -339,30 +361,30 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
+        BindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "", StringTools.utf8ToString( bindResponse.getServerSaslCreds() ) );
 
         // Check the Control
-        List<Control> controls = bindResponse.getControls();
+        Map<String, Control> controls = bindResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = bindResponse.getControls( 0 );
+        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 length
-        assertEquals( 0x2D, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x2D, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -400,7 +422,7 @@ public class BindResponseTest
                 0x04, 0x00, // errorMessage LDAPString,
                 // referral [3] Referral OPTIONAL }
                 ( byte ) 0x87, 0x02, 'A', 'B' // serverSaslCreds [7] OCTET
-                                                // STRING OPTIONAL }
+            // STRING OPTIONAL }
             } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
@@ -421,21 +443,21 @@ public class BindResponseTest
         }
 
         // Check the decoded BindResponse
-        BindResponseCodec bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
+        BindResponse bindResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getBindResponse();
 
         assertEquals( 1, bindResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, bindResponse.getLdapResult().getResultCode() );
-        assertEquals( "", bindResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", bindResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", bindResponse.getLdapResult().getErrorMessage() );
         assertEquals( "AB", StringTools.utf8ToString( bindResponse.getServerSaslCreds() ) );
 
-        // Check the length
-        assertEquals( 0x12, bindResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = bindResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( bindResponse );
+
+            // Check the length
+            assertEquals( 0x12, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 



Mime
View raw message