directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r322501 - /directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
Date Sun, 16 Oct 2005 19:17:06 GMT
Author: elecharny
Date: Sun Oct 16 12:16:59 2005
New Revision: 322501

URL: http://svn.apache.org/viewcvs?rev=322501&view=rev
Log:
Add a test to check another bug condition in the ModifyRequest grammar.

Modified:
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java

Modified: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java?rev=322501&r1=322500&r2=322501&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
(original)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
Sun Oct 16 12:16:59 2005
@@ -30,10 +30,14 @@
 import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1new.ber.Asn1Decoder;
 import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.codec.grammar.ModifyRequestGrammar;
 import org.apache.asn1new.ldap.pojo.LdapMessage;
 import org.apache.asn1new.ldap.pojo.ModifyRequest;
 import org.apache.asn1new.primitives.OctetString;
 import org.apache.asn1new.util.StringUtils;
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import junit.framework.Assert;
 import junit.framework.TestCase;
@@ -44,6 +48,12 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
 public class ModifyRequestTest extends TestCase {
+    private static final Logger log = LoggerFactory.getLogger( ModifyRequestTest.class );
+    
+    static 
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
     /**
      * Test the decoding of a ModifyRequest
      */
@@ -277,6 +287,152 @@
 
         // Check the length
         Assert.assertEquals(0x8C, message.computeLength());
+
+        // Check the encoding, by decoding and re-encoding the result
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            String decodedPdu1 = StringUtils.dumpBytes( bb.array() );
+            
+            try
+            {
+                ldapDecoder.decode( bb, ldapMessageContainer );
+            }
+            catch ( DecoderException de )
+            {
+                de.printStackTrace();
+                Assert.fail( de.getMessage() );
+            }
+            
+            LdapMessage message2 = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+            
+            
+            ByteBuffer bb2 = message2.encode( null );
+            String decodedPdu2 = StringUtils.dumpBytes( bb2.array() );
+
+            Assert.assertEquals( decodedPdu1, decodedPdu2 );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of a ModifyRequest, with different operations, take 2
+     */
+    public void testDecodeModifyRequestManyOperations2() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        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

+                          0x63, 0x6E, 0x3D, 0x54, 0x6F, 0x72, 0x69, 0x20, 
+                          0x41, 0x6D, 0x6F, 0x73, 0x2C, 0x6F, 0x75, 0x3D, 
+                          0x70, 0x6C, 0x61, 0x79, 0x67, 0x72, 0x6F, 0x75, 
+                          0x6E, 0x64, 0x2C, 0x64, 0x63, 0x3D, 0x61, 0x70, 
+                          0x61, 0x63, 0x68, 0x65, 0x2C, 0x64, 0x63, 0x3D, 
+                          0x6F, 0x72, 0x67, 
+                        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, 
+                                0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E, 
+                                0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 
+                              0x31, 0x0D,                   // Vals : 01234567890
+                                0x04, 0x0B, 
+                                  0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+                                  0x38, 0x39, 0x30, 
+                          0x30, 0x25,                       // Modification
+                            0x0A, 0x01, 0x00,               // Operation : Add
+                            0x30, 0x20,                     // type : telephoneNumber
+                              0x04, 0x0F, 
+                                0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E, 
+                                0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 
+                            0x31, 0x0D,                     // Vals : 01234567890
+                              0x04, 0x0B, 
+                                0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 
+                                0x38, 0x39, 0x30, 
+                    (byte)0xA0, 0x1B,                       // Controls : 2.16.840.1.113730.3.4.2
+                      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             } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+        
+        // Check the decoded PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyRequest modifyRequest      = message.getModifyRequest();
+        
+        Assert.assertEquals( 49, message.getMessageId() );
+        Assert.assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject()
);
+
+        ArrayList modifications = modifyRequest.getModifications();
+        
+        Assert.assertEquals( 3, modifications.size() );
+        
+        HashSet expectedTypes = new HashSet();
+        
+        expectedTypes.add("telephonenumber");
+        expectedTypes.add("description");
+        
+        HashMap typesVals = new HashMap();
+        
+        HashSet telephoneVals = new HashSet();
+        telephoneVals.add("01234567890");
+        typesVals.put("telephonenumber", telephoneVals);
+        
+        ModificationItem modification = (ModificationItem)modifications.get( 1 );
+        BasicAttribute attributeValue = (BasicAttribute)modification.getAttribute();
+            
+        Assert.assertTrue( expectedTypes.contains( attributeValue.getID().toLowerCase() )
);
+            
+        NamingEnumeration values = attributeValue.getAll();
+        HashSet vals = (HashSet)typesVals.get( attributeValue.getID().toLowerCase() );
+
+        while ( values.hasMore() )
+        {
+            OctetString value = (OctetString)values.next();
+            
+            Assert.assertTrue( vals.contains( value.toString() ) );
+            
+            vals.remove( value.toString() );
+        }
+
+        // Check the length
+        Assert.assertEquals(0xB9, message.computeLength());
 
         // Check the encoding, by decoding and re-encoding the result
         try



Mime
View raw message