You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/10/15 17:33:10 UTC

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

Author: elecharny
Date: Sat Oct 15 08:33:05 2005
New Revision: 321350

URL: http://svn.apache.org/viewcvs?rev=321350&view=rev
Log:
Added a test that was failing in the Stefan Zörner test suite, because of a bug was found in the codec.

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=321350&r1=321349&r2=321350&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 Sat Oct 15 08:33:05 2005
@@ -166,4 +166,146 @@
             Assert.fail( ee.getMessage() );
         }
     }
+    
+    /**
+     * Test the decoding of a ModifyRequest, with different operations
+     */
+    public void testDecodeModifyRequestManyOperations() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x18C );
+        
+        stream.put(
+            new byte[]
+            {
+                      0x30, (byte)0x81, (byte)0x89, 
+                        0x02, 0x01, 0x15, 
+                        0x66, 0x67,         // 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, 0x38,               // Modifications
+                            0x30, 0x24,             // Modification
+                              0x0A, 0x01, 0x00,     // Operation = ADD
+                              0x30, 0x1F,           // type : telephoneNumber
+                                0x04, 0x0F, 
+                                  0x74, 0x65, 0x6C, 0x65, 0x70, 0x68, 0x6F, 0x6E,
+                                  0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 
+                              0x31, 0x0C,           // vals : 1234567890
+                                0x04, 0x0A, 
+                                  0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, // 1234567890
+                                  0x39, 0x30, 
+                            0x30, 0x10,             // Modification
+                              0x0A, 0x01, 0x02,     // Operation = REPLACE
+                              0x30, 0x0B,           // type : cn
+                                0x04, 0x02, 
+                                  0x63, 0x6E, 
+                                0x31, 0x05,         // vals : XXX
+                                  0x04, 0x03, 
+                                    0x58, 0x58, 0x58, 
+                        (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( 21, message.getMessageId() );
+        Assert.assertEquals( "cn=Tori Amos,ou=playground,dc=apache,dc=org", modifyRequest.getObject() );
+
+        ArrayList modifications = modifyRequest.getModifications();
+        
+        Assert.assertEquals( 2, modifications.size() );
+        
+        HashSet expectedTypes = new HashSet();
+        
+        expectedTypes.add("telephoneNumber");
+        expectedTypes.add("cn");
+        
+        HashMap typesVals = new HashMap();
+        
+        HashSet telephoneVals = new HashSet();
+        telephoneVals.add("1234567890");
+        typesVals.put("telephoneNumber", telephoneVals);
+        
+        HashSet cnVals = new HashSet();
+        cnVals.add("XXX");
+        typesVals.put("cn", cnVals);
+        
+        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(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() );
+        }
+    }
 }