You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2010/08/20 21:23:37 UTC

svn commit: r987606 [20/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...

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyRequestTest.java Fri Aug 20 19:23:27 2010
@@ -25,7 +25,8 @@ import static org.junit.Assert.assertTru
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
-import java.util.List;
+import java.util.Collection;
+import java.util.Map;
 
 import org.apache.directory.junit.tools.Concurrent;
 import org.apache.directory.junit.tools.ConcurrentJunitRunner;
@@ -33,16 +34,17 @@ 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.LdapMessageCodec;
 import org.apache.directory.shared.ldap.codec.LdapMessageContainer;
 import org.apache.directory.shared.ldap.codec.ResponseCarryingException;
 import org.apache.directory.shared.ldap.entry.EntryAttribute;
 import org.apache.directory.shared.ldap.entry.Modification;
 import org.apache.directory.shared.ldap.exception.LdapException;
+import org.apache.directory.shared.ldap.message.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.Message;
+import org.apache.directory.shared.ldap.message.ModifyRequest;
 import org.apache.directory.shared.ldap.message.ModifyResponseImpl;
 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;
@@ -57,6 +59,10 @@ import org.junit.runner.RunWith;
 @Concurrent()
 public class ModifyRequestTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a ModifyRequest
      */
@@ -68,39 +74,37 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            {
-            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object 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', 0x30, 0x29, 
-                                        // modification SEQUENCE OF SEQUENCE {
-                0x30, 0x11, 
-                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
-                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x06,         // vals SET OF AttributeValue }
-                      0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x52, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object 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', 0x30, 0x29,
+                // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -120,19 +124,19 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 1, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Collection<Modification> modifications = modifyRequest.getModifications();
 
         assertEquals( 2, modifications.size() );
 
-        for ( Modification modification:modifications )
+        for ( Modification modification : modifications )
         {
-            EntryAttribute attribute =  modification.getAttribute();
-            
+            EntryAttribute attribute = modification.getAttribute();
+
             if ( "l".equalsIgnoreCase( attribute.getId() ) )
             {
                 String attrValue = attribute.getString();
@@ -145,13 +149,13 @@ public class ModifyRequestTest
             }
         }
 
-        // Check the length
-        assertEquals( 0x54, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x54, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -164,6 +168,7 @@ public class ModifyRequestTest
         }
     }
 
+
     /**
      * Test the decoding of a ModifyRequest
      */
@@ -175,39 +180,37 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            {
-            0x30, 0x52,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x4d,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object 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', 0x30, 0x29, 
-                                        // modification SEQUENCE OF SEQUENCE {
-                0x30, 0x11, 
-                  0x0A, 0x01, 0x02,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0c,           // AttributeTypeAndValues ::= SEQUENCE {
-                    0x04, 0x01, 'l',    // type AttributeDescription,
-                    0x31, 0x07,         // vals SET OF AttributeValue }
-                      0x04, 0x05, 'P', 'a', 'r', 'i', 's',
-
-                0x30, 0x14,             // modification SEQUENCE OF *SEQUENCE* {
-                  0x0A, 0x01, 0x00,     // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                  0x30, 0x0f,           // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                    0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                    0x31, 0x06,         // vals SET OF AttributeValue }
-                      0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x52, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x4d, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object 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', 0x30, 0x29,
+                // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x11, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0c, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x07, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x14, // modification SEQUENCE OF *SEQUENCE* {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         stream.flip();
 
@@ -222,15 +225,17 @@ public class ModifyRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof ModifyResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_DN_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
 
         fail( "We should not reach this point" );
     }
 
+
     /**
      * Test the decoding of a ModifyRequest, with different operations
      */
@@ -242,35 +247,34 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 
-            0x30, ( byte ) 0x81, ( byte ) 0x89, 
-              0x02, 0x01, 0x15, 
-              0x66, 0x67,               
-                0x04, 0x2B,             // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
-                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
-                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
-                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
-                0x30, 0x38,             // Modifications
-                  0x30, 0x24,           // Modification
-                    0x0A, 0x01, 0x00,   // Operation = ADD
-                    0x30, 0x1F,         // type : telephoneNumber
-                      0x04, 0x0F,
-                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0C,         // vals : 1234567890
-                        0x04, 0x0A, 
-                          '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
-                  0x30, 0x10,           // Modification
-                    0x0A, 0x01, 0x02,   // Operation = REPLACE
-                    0x30, 0x0B,         // type : cn
-                      0x04, 0x02, 'c', 'n', 
-                      0x31, 0x05,       // vals : XXX
-                        0x04, 0x03, 'X', 'X', 'X', 
-              ( byte ) 0xA0, 0x1B,      // Control : 2.16.840.1.113730.3.4.2
-                0x30, 0x19, 
-                  0x04, 0x17,
-                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
-                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
-            } );
+            { 0x30, ( byte ) 0x81, ( byte ) 0x89, 0x02, 0x01, 0x15, 0x66,
+                0x67,
+                0x04,
+                0x2B, // ModifyRequest object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', '=', 'p', 'l', 'a', 'y',
+                'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=',
+                'o', 'r', 'g', 0x30,
+                0x38, // Modifications
+                0x30,
+                0x24, // Modification
+                0x0A, 0x01,
+                0x00, // Operation = ADD
+                0x30,
+                0x1F, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0C, // vals : 1234567890
+                0x04, 0x0A, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x30,
+                0x10, // Modification
+                0x0A, 0x01,
+                0x02, // Operation = REPLACE
+                0x30,
+                0x0B, // type : cn
+                0x04, 0x02, 'c', 'n', 0x31,
+                0x05, // vals : XXX
+                0x04, 0x03, 'X', 'X', 'X', ( byte ) 0xA0,
+                0x1B, // Control : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+                '0', '.', '3', '.', '4', '.', '2' } );
 
         stream.flip();
 
@@ -289,16 +293,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 21, modifyRequest.getMessageId() );
-        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject().toString() );
+        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 2, modifications.size() );
+        assertEquals( 2, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "telephonenumber", attributeValue.getId().toLowerCase() );
@@ -306,7 +310,7 @@ public class ModifyRequestTest
         String attrValue = attributeValue.getString();
         assertEquals( "1234567890", attrValue );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         assertEquals( "cn", attributeValue.getId().toLowerCase() );
@@ -314,13 +318,14 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "XXX", attrValue );
 
-        // Check the length
-        assertEquals( 0x8C, modifyRequest.computeLength() );
-
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x8C, bb.limit() );
+
             String decodedPdu1 = StringTools.dumpBytes( bb.array() );
 
             try
@@ -333,10 +338,10 @@ public class ModifyRequestTest
                 fail( de.getMessage() );
             }
 
-            LdapMessageCodec message2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+            ModifyRequest modifyRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
-            ByteBuffer bb2 = message2.encode();
-            String decodedPdu2 = StringTools.dumpBytes( bb2.array() );
+            bb = encoder.encodeMessage( modifyRequest2 );
+            String decodedPdu2 = StringTools.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
         }
@@ -359,41 +364,50 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x18C );
 
         stream.put( new byte[]
-            { 
-            0x30, ( byte ) 0x81, ( byte ) 0xB6,     // LdapMessage
-              0x02, 0x01, 0x31,                     // Message ID : 49
-              0x66, ( byte ) 0x81, ( byte ) 0x93,   // ModifyRequest
-                0x04, 0x2B,                         // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
-                  'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', 
-                  '=', 'p', 'l', 'a', 'y', 'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=',
-                  'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=', 'o', 'r', 'g',
-                0x30, 0x64,                         // Modifications
-                  0x30, 0x14,                       // Modification
-                    0x0A, 0x01, 0x01,               // Operation : Delete
-                    0x30, 0x0F,                     // type : description
-                      0x04, 0x0B, 
-                        0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 
-                    0x31, 0x00,                     // Vals = null
-                  0x30, 0x25,                       // Modification
-                    0x0A, 0x01, 0x00,               // Operation : Add
-                    0x30, 0x20,                     // type : telephoneNumber
-                      0x04, 0x0F, 
-                        't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0D,                   // Vals : 01234567890
-                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0',
-                  0x30, 0x25,                       // Modification
-                    0x0A, 0x01, 0x00,               // Operation : Add
-                    0x30, 0x20,                     // type : telephoneNumber
-                      0x04, 0x0F, 
-                      't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r',
-                      0x31, 0x0D,                   // Vals : 01234567890
-                        0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 
-              ( byte ) 0xA0, 0x1B,                  // Controls : 2.16.840.1.113730.3.4.2
-                0x30, 0x19, 
-                  0x04, 0x17,
-                    '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', 
-                    '1', '1', '3', '7', '3', '0', '.', '3', '.', '4', '.', '2'
-            } );
+            {
+                0x30,
+                ( byte ) 0x81,
+                ( byte ) 0xB6, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                ( byte ) 0x81,
+                ( byte ) 0x93, // ModifyRequest
+                0x04,
+                0x2B, // object : cn=Tori Amos,ou=playground,dc=apache,dc=org
+                'c', 'n', '=', 'T', 'o', 'r', 'i', ' ', 'A', 'm', 'o', 's', ',', 'o', 'u', '=', 'p', 'l', 'a', 'y',
+                'g', 'r', 'o', 'u', 'n', 'd', ',', 'd', 'c', '=', 'a', 'p', 'a', 'c', 'h', 'e', ',', 'd', 'c', '=',
+                'o', 'r', 'g', 0x30,
+                0x64, // Modifications
+                0x30,
+                0x14, // Modification
+                0x0A, 0x01,
+                0x01, // Operation : Delete
+                0x30,
+                0x0F, // type : description
+                0x04, 0x0B, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x31,
+                0x00, // Vals = null
+                0x30,
+                0x25, // Modification
+                0x0A, 0x01,
+                0x00, // Operation : Add
+                0x30,
+                0x20, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0D, // Vals : 01234567890
+                0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 0x30,
+                0x25, // Modification
+                0x0A, 0x01,
+                0x00, // Operation : Add
+                0x30,
+                0x20, // type : telephoneNumber
+                0x04, 0x0F, 't', 'e', 'l', 'e', 'p', 'h', 'o', 'n', 'e', 'N', 'u', 'm', 'b', 'e', 'r', 0x31,
+                0x0D, // Vals : 01234567890
+                0x04, 0x0B, '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ( byte ) 0xA0,
+                0x1B, // Controls : 2.16.840.1.113730.3.4.2
+                0x30, 0x19, 0x04, 0x17, '2', '.', '1', '6', '.', '8', '4', '0', '.', '1', '.', '1', '1', '3', '7', '3',
+                '0', '.', '3', '.', '4', '.', '2' } );
 
         stream.flip();
 
@@ -412,22 +426,22 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject().toString() );
+        assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 3, modifications.size() );
+        assertEquals( 3, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "description", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         String attrValue = attributeValue.getString();
@@ -436,7 +450,7 @@ public class ModifyRequestTest
 
         assertEquals( "01234567890", attrValue );
 
-        modification = modifications.get( 2 );
+        modification = ( Modification ) modifications[2];
         attributeValue = modification.getAttribute();
 
         attrValue = attributeValue.getString();
@@ -446,13 +460,14 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "01234567890", attrValue );
 
-        // Check the length
-        assertEquals( 0xB9, modifyRequest.computeLength() );
-
         // Check the encoding, by decoding and re-encoding the result
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0xB9, bb.limit() );
+
             String decodedPdu1 = StringTools.dumpBytes( bb.array() );
 
             try
@@ -465,10 +480,10 @@ public class ModifyRequestTest
                 fail( de.getMessage() );
             }
 
-            LdapMessageCodec message2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+            ModifyRequest modifyRequest2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
-            ByteBuffer bb2 = message2.encode();
-            String decodedPdu2 = StringTools.dumpBytes( bb2.array() );
+            bb = encoder.encodeMessage( modifyRequest2 );
+            String decodedPdu2 = StringTools.dumpBytes( bb.array() );
 
             assertEquals( decodedPdu1, decodedPdu2 );
         }
@@ -491,39 +506,34 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x5C );
 
         stream.put( new byte[]
-            {
-            0x30, 0x5A,                 // LDAPMessage ::= SEQUENCE {
-              0x02, 0x01, 0x01,         // messageID MessageID
-              0x66, 0x55,               // CHOICE { ..., modifyRequest ModifyRequest, ...
-                                        // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
-                                        // object 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', 
-                0x30, 0x31,             // modification SEQUENCE OF SEQUENCE {
-                  0x30, 0x19, 
-                    0x0A, 0x01, 0x02,   // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                    0x30, 0x14,         // AttributeTypeAndValues ::= SEQUENCE {
-                      0x04, 0x01, 'l',  // type AttributeDescription,
-                      0x31, 0x0F,       // vals SET OF AttributeValue }
-                        0x04, 0x05, 'P', 'a', 'r', 'i', 's', 
-                        0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 
-                  0x30, 0x14,           // modification SEQUENCE OF *SEQUENCE*  {
-                    0x0A, 0x01, 0x00,   // operation ENUMERATED {
-                                        // add (0),
-                                        // delete (1),
-                                        // replace (2) },
-                                        // modification AttributeTypeAndValues } }
-                    0x30, 0x0f,         // AttributeTypeAndValues ::= SEQUENCE {
-                                        // type AttributeDescription,
-                      0x04, 0x05, 'a', 't', 't', 'r', 's', 
-                      0x31, 0x06,       // vals SET OF AttributeValue }
-                        0x04, 0x04, 't', 'e', 's', 't' 
-            } );
+            { 0x30,
+                0x5A, // LDAPMessage ::= SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x66,
+                0x55, // CHOICE { ..., modifyRequest ModifyRequest, ...
+                // ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+                // object 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', 0x30, 0x31, // modification SEQUENCE OF SEQUENCE {
+                0x30, 0x19, 0x0A, 0x01, 0x02, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x14, // AttributeTypeAndValues ::= SEQUENCE {
+                0x04, 0x01, 'l', // type AttributeDescription,
+                0x31, 0x0F, // vals SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x04, 0x06, 'L', 'o', 'n', 'd', 'o', 'n', 0x30, 0x14, // modification SEQUENCE OF *SEQUENCE*  {
+                0x0A, 0x01, 0x00, // operation ENUMERATED {
+                // add (0),
+                // delete (1),
+                // replace (2) },
+                // modification AttributeTypeAndValues } }
+                0x30, 0x0f, // AttributeTypeAndValues ::= SEQUENCE {
+                // type AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, 0x06, // vals SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -543,16 +553,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 1, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 2, modifications.size() );
+        assertEquals( 2, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
@@ -563,7 +573,7 @@ public class ModifyRequestTest
         attrValue = attributeValue.get( 1 ).getString();
         assertEquals( "London", attrValue );
 
-        modification = modifications.get( 1 );
+        modification = ( Modification ) modifications[1];
         attributeValue = modification.getAttribute();
 
         assertEquals( "attrs", attributeValue.getId().toLowerCase() );
@@ -571,13 +581,13 @@ public class ModifyRequestTest
         attrValue = attributeValue.getString();
         assertEquals( "test", attrValue );
 
-        // Check the length
-        assertEquals( 0x5C, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x5C, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -604,10 +614,9 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x07 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x05,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x00                // ModifyRequest
+            { 0x30, 0x05, // LdapMessage
+                0x02, 0x01, 0x31, // Message ID : 49
+                0x66, 0x00 // ModifyRequest
             } );
 
         stream.flip();
@@ -639,12 +648,10 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x09 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x07,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x02,               // ModifyRequest
-                0x04, 0x00 
-            } );
+            { 0x30, 0x07, // LdapMessage
+                0x02, 0x01, 0x31, // Message ID : 49
+                0x66, 0x02, // ModifyRequest
+                0x04, 0x00 } );
 
         stream.flip();
 
@@ -675,14 +682,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x29 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x27,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x22,               // ModifyRequest
-                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' 
-            } );
+            { 0x30,
+                0x27, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x22, // ModifyRequest
+                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' } );
 
         stream.flip();
 
@@ -713,15 +720,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x29,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x24,               // ModifyRequest
-                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', 
-                0x30, 0x00 
-            } );
+            { 0x30,
+                0x29, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x24, // ModifyRequest
+                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', 0x30, 0x00 } );
 
         stream.flip();
 
@@ -752,16 +758,14 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2D );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2B,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x26,               // ModifyRequest
-                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', 
-                0x30, 0x02, 
-                  0x30, 0x00 
-            } );
+            { 0x30,
+                0x2B, // LdapMessage
+                0x02, 0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x26, // ModifyRequest
+                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', 0x30, 0x02, 0x30, 0x00 } );
 
         stream.flip();
 
@@ -792,17 +796,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2F );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2D,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x28,               // ModifyRequest
-                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', 
-                0x30, 0x04, 
-                  0x30, 0x02, 
-                    0x0A, 0x00 
-            } );
+            {
+                0x30,
+                0x2D, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x28, // ModifyRequest
+                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', 0x30, 0x04, 0x30, 0x02, 0x0A,
+                0x00 } );
 
         stream.flip();
 
@@ -833,17 +837,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2E,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x29,               // ModifyRequest
-                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', 
-                0x30, 0x05, 
-                  0x30, 0x03, 
-                    0x0A, 0x01, 0x04 
-            } );
+            {
+                0x30,
+                0x2E, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x29, // ModifyRequest
+                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', 0x30, 0x05, 0x30, 0x03, 0x0A,
+                0x01, 0x04 } );
 
         stream.flip();
 
@@ -875,17 +879,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x30 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x2E,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x29,               // ModifyRequest
-                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', 
-                0x30, 0x05, 
-                  0x30, 0x03, 
-                    0x0A, 0x01, 0x00 
-            } );
+            {
+                0x30,
+                0x2E, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x29, // ModifyRequest
+                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', 0x30, 0x05, 0x30, 0x03, 0x0A,
+                0x01, 0x00 } );
 
         stream.flip();
 
@@ -917,18 +921,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x32 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x30,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2B,               // ModifyRequest
-                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', 
-                0x30, 0x07, 
-                  0x30, 0x05, 
-                    0x0A, 0x01, 0x00, 
-                  0x30, 0x00 
-            } );
+            {
+                0x30,
+                0x30, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2B, // ModifyRequest
+                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', 0x30, 0x07, 0x30, 0x05, 0x0A,
+                0x01, 0x00, 0x30, 0x00 } );
 
         stream.flip();
 
@@ -960,19 +963,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x34 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x32,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2D,               // ModifyRequest
-                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', 
-                0x30, 0x09, 
-                  0x30, 0x07, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x02, 
-                      0x04, 0x00 
-            } );
+            {
+                0x30,
+                0x32, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2D, // ModifyRequest
+                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', 0x30, 0x09, 0x30, 0x07, 0x0A,
+                0x01, 0x00, 0x30, 0x02, 0x04, 0x00 } );
 
         stream.flip();
 
@@ -988,9 +989,10 @@ public class ModifyRequestTest
         catch ( DecoderException de )
         {
             assertTrue( de instanceof ResponseCarryingException );
-            InternalMessage response = ((ResponseCarryingException)de).getResponse();
+            Message response = ( ( ResponseCarryingException ) de ).getResponse();
             assertTrue( response instanceof ModifyResponseImpl );
-            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((ModifyResponseImpl)response).getLdapResult().getResultCode() );
+            assertEquals( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ( ( ModifyResponseImpl ) response ).getLdapResult()
+                .getResultCode() );
             return;
         }
     }
@@ -1008,19 +1010,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x35 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x33,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x2E,               // ModifyRequest
-                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', 
-                0x30, 0x0A, 
-                  0x30, 0x08, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x03, 
-                    0x04, 0x01, 'l' 
-            } );
+            {
+                0x30,
+                0x33, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x2E, // ModifyRequest
+                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', 0x30, 0x0A, 0x30, 0x08, 0x0A,
+                0x01, 0x00, 0x30, 0x03, 0x04, 0x01, 'l' } );
 
         stream.flip();
 
@@ -1052,20 +1052,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x37 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x35,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x30,               // ModifyRequest
-                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', 
-                0x30, 0x0C, 
-                  0x30, 0x0A, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x05, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x00 
-            } );
+            {
+                0x30,
+                0x35, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x30, // ModifyRequest
+                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', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
+                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 0x00 } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1085,28 +1082,28 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
-        // Check the length
-        assertEquals( 0x37, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x37, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1132,23 +1129,20 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x54 );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x52,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x30,               // ModifyRequest
-                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', 
-                0x30, 0x0C, 
-                  0x30, 0x0A, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x05, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x00, 
-              ( byte ) 0xA0, 0x1B,      // A control
+            {
+                0x30,
+                0x52, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x30, // ModifyRequest
+                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', 0x30, 0x0C, 0x30, 0x0A, 0x0A,
+                0x01, 0x00, 0x30, 0x05, 0x04, 0x01, 'l', 0x31, 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();
@@ -1168,37 +1162,37 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
         assertEquals( 0, attributeValue.size() );
 
         // Check the Control
-        List<Control> controls = modifyRequest.getControls();
+        Map<String, Control> controls = modifyRequest.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = modifyRequest.getControls( 0 );
+        Control control = modifyRequest.getControl( "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( 0x54, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x54, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -1224,22 +1218,17 @@ public class ModifyRequestTest
         ByteBuffer stream = ByteBuffer.allocate( 0x3D );
 
         stream.put( new byte[]
-            { 
-            0x30, 0x3B,                 // LdapMessage
-              0x02, 0x01, 0x31,         // Message ID : 49
-              0x66, 0x36,               // ModifyRequest
-                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', 
-                0x30, 0x12, 
-                  0x30, 0x10, 
-                    0x0A, 0x01, 0x00, 
-                    0x30, 0x0B, 
-                      0x04, 0x01, 'l', 
-                      0x31, 0x06, 
-                        0x04, 0x01, 'a', 
-                        0x04, 0x01, 'b' 
-            } );
+            {
+                0x30,
+                0x3B, // LdapMessage
+                0x02,
+                0x01,
+                0x31, // Message ID : 49
+                0x66,
+                0x36, // ModifyRequest
+                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', 0x30, 0x12, 0x30, 0x10, 0x0A,
+                0x01, 0x00, 0x30, 0x0B, 0x04, 0x01, 'l', 0x31, 0x06, 0x04, 0x01, 'a', 0x04, 0x01, 'b' } );
 
         String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
@@ -1259,16 +1248,16 @@ public class ModifyRequestTest
         }
 
         // Check the decoded PDU
-        ModifyRequestCodec modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
+        ModifyRequest modifyRequest = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyRequest();
 
         assertEquals( 49, modifyRequest.getMessageId() );
-        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getObject().toString() );
+        assertEquals( "cn=testModify,ou=users,ou=system", modifyRequest.getName().toString() );
 
-        List<Modification> modifications = modifyRequest.getModifications();
+        Object[] modifications = modifyRequest.getModifications().toArray();
 
-        assertEquals( 1, modifications.size() );
+        assertEquals( 1, modifications.length );
 
-        Modification modification = modifications.get( 0 );
+        Modification modification = ( Modification ) modifications[0];
         EntryAttribute attributeValue = modification.getAttribute();
 
         assertEquals( "l", attributeValue.getId().toLowerCase() );
@@ -1280,13 +1269,13 @@ public class ModifyRequestTest
         attrValue = attributeValue.get( 1 ).getString();
         assertEquals( "b", attrValue );
 
-        // Check the length
-        assertEquals( 0x3D, modifyRequest.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyRequest.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyRequest );
+
+            // Check the length
+            assertEquals( 0x3D, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 

Modified: directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyResponseTest.java
URL: http://svn.apache.org/viewvc/directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyResponseTest.java?rev=987606&r1=987605&r2=987606&view=diff
==============================================================================
--- directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyResponseTest.java (original)
+++ directory/shared/trunk/ldap/src/test/java/org/apache/directory/shared/ldap/codec/modify/ModifyResponseTest.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.LdapProtocolEncoder;
+import org.apache.directory.shared.ldap.message.ModifyResponse;
 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 ModifyResponseTest
 {
+    /** The encoder instance */
+    LdapProtocolEncoder encoder = new LdapProtocolEncoder();
+
+
     /**
      * Test the decoding of a ModifyResponse
      */
@@ -93,20 +99,21 @@ public class ModifyResponseTest
         }
 
         // Check the decoded ModifyResponse PDU
-        ModifyResponseCodec modifyResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyResponse();
+        ModifyResponse modifyResponse = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getModifyResponse();
 
         assertEquals( 1, modifyResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode() );
-        assertEquals( "", modifyResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", modifyResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", modifyResponse.getLdapResult().getErrorMessage() );
 
-        // Check the length
-        assertEquals( 0x0E, modifyResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyResponse );
+
+            // Check the length
+            assertEquals( 0x0E, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );
 
@@ -131,19 +138,27 @@ public class ModifyResponseTest
         ByteBuffer stream = ByteBuffer.allocate( 0x2B );
 
         stream.put( new byte[]
-            { 0x30, 0x29, // LDAPMessage ::=SEQUENCE {
-                0x02, 0x01, 0x01, // messageID MessageID
-                0x67, 0x07, // CHOICE { ..., modifyResponse ModifyResponse, ...
+            { 0x30,
+                0x29, // LDAPMessage ::=SEQUENCE {
+                0x02, 0x01,
+                0x01, // messageID MessageID
+                0x67,
+                0x07, // CHOICE { ..., modifyResponse ModifyResponse, ...
                 // ModifyResponse ::= [APPLICATION 7] 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
+                ( 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 } );
 
@@ -165,29 +180,30 @@ public class ModifyResponseTest
         }
 
         // Check the decoded ModifyResponse PDU
-        ModifyResponseCodec modifyResponse = ( ( LdapMessageContainer ) ldapMessageContainer ).getModifyResponse();
+        ModifyResponse modifyResponse = ( ( LdapMessageContainer ) ldapMessageContainer )
+            .getModifyResponse();
 
         assertEquals( 1, modifyResponse.getMessageId() );
         assertEquals( ResultCodeEnum.SUCCESS, modifyResponse.getLdapResult().getResultCode() );
-        assertEquals( "", modifyResponse.getLdapResult().getMatchedDN() );
+        assertEquals( "", modifyResponse.getLdapResult().getMatchedDn().getName() );
         assertEquals( "", modifyResponse.getLdapResult().getErrorMessage() );
 
         // Check the Control
-        List<Control> controls = modifyResponse.getControls();
+        Map<String, Control> controls = modifyResponse.getControls();
 
         assertEquals( 1, controls.size() );
 
-        Control control = modifyResponse.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( 0x2B, modifyResponse.computeLength() );
-
         // Check the encoding
         try
         {
-            ByteBuffer bb = modifyResponse.encode();
+            ByteBuffer bb = encoder.encodeMessage( modifyResponse );
+
+            // Check the length
+            assertEquals( 0x2B, bb.limit() );
 
             String encodedPdu = StringTools.dumpBytes( bb.array() );