directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159465 - directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
Date Wed, 30 Mar 2005 06:31:38 GMT
Author: elecharny
Date: Tue Mar 29 22:31:37 2005
New Revision: 159465

URL: http://svn.apache.org/viewcvs?view=rev&rev=159465
Log:
Added a junit test for LdapDecoder : decoding a splitted PDU.

Modified:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java

Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java?view=diff&r1=159464&r2=159465
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
(original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/LdapDecoderTest.java
Tue Mar 29 22:31:37 2005
@@ -118,7 +118,7 @@
     {
         Asn1Decoder ldapDecoder = new Asn1Decoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        ByteBuffer  stream      = ByteBuffer.allocate( 16 );
         stream.put(
             new byte[]
             {
@@ -166,6 +166,93 @@
         Assert.assertEquals( 3, br.getVersion() );
         Assert.assertEquals( null, br.getName() );
         Assert.assertEquals( false, ( br.getAuthentication() instanceof SimpleAuthenticationPOJO
) );
+
+        // Free the BindRequest Container. It will be put back in the IPool
+        // after being reset.
+        ldapMessageContainer.free();
+    }
+
+    /**
+     * Test the decoding of a splitted PDU
+     */
+    public void testDecodeSplittedPDU()
+    {
+        Asn1Decoder ldapDecoder = new Asn1Decoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 16 );
+        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', '=' 
+            } );
+
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = null;
+
+        try
+        {
+            ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
+                    PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+        }
+        catch ( PoolException pe )
+        {
+            Assert.fail("Cannot allocat a LdapMessageContainer : " + pe.getMessage());
+        }
+
+        ldapMessageContainer.setGrammar( LdapMessageGrammar.getInstance() );
+        ldapMessageContainer.setPoolManager( ldapDecoder.getPoolManager() );
+
+        // First block of data
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Second block of data
+        stream      = ByteBuffer.allocate( 37 );
+        stream.put(
+            new byte[]
+            {
+    				'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+	                'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+					( byte ) 0x80, 0x08, //        authentication AuthenticationChoice
+	                                     // AuthenticationChoice ::= CHOICE { simple [0] OCTET
STRING, ...
+					'p', 'a', 's', 's', 'w', 'o', 'r', 'd'
+            } );
+
+        stream.flip();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindRequestPOJO br      = ( BindRequestPOJO ) ( message.getProtocolOp() );
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 3, br.getVersion() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getName() );
+        Assert.assertEquals( true, ( br.getAuthentication() instanceof SimpleAuthenticationPOJO
) );
+        Assert.assertEquals( "password", ( ( SimpleAuthenticationPOJO ) br.getAuthentication()
).getSimple() );
 
         // Free the BindRequest Container. It will be put back in the IPool
         // after being reset.



Mime
View raw message