directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r159200 - in directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber: ./ tlv/ tlv/LdapDecoderTest.java
Date Sun, 27 Mar 2005 22:25:52 GMT
Author: elecharny
Date: Sun Mar 27 14:25:51 2005
New Revision: 159200

URL: http://svn.apache.org/viewcvs?view=rev&rev=159200
Log:
Added a Ldap decoder unit test

Added:
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/
    directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/LdapDecoderTest.java

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/LdapDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/LdapDecoderTest.java?view=auto&rev=159200
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/LdapDecoderTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ber/tlv/LdapDecoderTest.java
Sun Mar 27 14:25:51 2005
@@ -0,0 +1,163 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ber.tlv;
+
+import junit.framework.TestCase;
+
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.codec.DecoderException;
+import org.apache.asn1.ldap.codec.LdapMessageContainer;
+import org.apache.asn1.ldap.codec.LdapMessageGrammar;
+import org.apache.asn1.ldap.pojo.BindRequestPOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.asn1.ldap.pojo.SimpleAuthenticationPOJO;
+import org.apache.asn1.util.pools.PoolEnum;
+import org.apache.asn1.util.pools.PoolException;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Test the Ldap decoder
+ * 
+ */
+public class LdapDecoderTest extends TestCase
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** The logger */
+    private static Logger log = Logger.getLogger( LdapDecoderTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * DOCUMENT ME!
+     */
+    public void testDecodeBindRequest()
+    {
+        //ILdapContainer bindRequestContainer = BindRequestContainerPool.alloc();
+
+        Asn1Decoder ldapDecoder = new Asn1Decoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 19 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x11, 				// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 			//         messageID MessageID
+				0x60, 0x0C, 				//        CHOICE { ..., bindRequest BindRequest, ...
+                        					// BindRequest ::= APPLICATION[0] SEQUENCE {
+				0x02, 0x01, 0x01, 			//        version INTEGER (1..127),
+				0x04, 0x03, 'a', '.', 'b', 	//        name LDAPDN,
+				0x04, 0x02, 'a', 'b'
+            } ); //        authentication AuthenticationChoice
+                 // AuthenticationChoice ::= CHOICE { simple [0] OCTET STRING, ...
+        stream.flip();
+
+        try
+        {
+
+            long t0 = System.currentTimeMillis();
+
+            for ( int i = 0; i < 1000000; i++ )
+            {
+                log.debug( "---------------------> " + i );
+
+                // Allocate a BindRequest Container
+                IAsn1Container ldapMessageContainer = null;
+
+                try
+                {
+                    ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
+                            PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+                }
+                catch ( PoolException pe )
+                {
+                    log.error( "Cannot allocat a LdapMessageContainer : " + pe.getMessage()
);
+
+                    return;
+                }
+
+                ldapMessageContainer.setGrammar( LdapMessageGrammar.getInstance() );
+                ldapMessageContainer.setPoolManager( ldapDecoder.getPoolManager() );
+
+                ldapDecoder.decode( stream, ldapMessageContainer );
+
+                // Free the BindRequest Container. It will be put back in the IPool
+                // after being reset.
+                ldapMessageContainer.free();
+                stream.flip();
+            }
+
+            long t1 = System.currentTimeMillis();
+
+            System.out.println( "Delta = " + ( t1 - t0 ) );
+        }
+        catch ( DecoderException de )
+        {
+            log.error( de.getMessage() );
+            de.printStackTrace();
+        }
+
+        try
+        {
+
+            IAsn1Container ldapMessageContainer = ( IAsn1Container ) ldapDecoder.allocate(
+                    PoolEnum.LDAP_MESSAGE_CONTAINER_POOL );
+
+            ldapDecoder.decode( stream, ldapMessageContainer );
+
+            // Free the BindRequest Container. It will be put back in the IPool
+            // after being reset.
+            //bindRequestContainer.free();
+            LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer )
+                .getLdapMessage();
+            BindRequestPOJO br      = ( BindRequestPOJO ) ( message.getProtocolOp() );
+
+            System.out.println( "BindRequest decoded :" );
+            System.out.println( "	MessageId 	= " + message.getMessageId() );
+            System.out.println( "	Version 	= " + br.getVersion() );
+            System.out.println( "	Name	 	= " + br.getName() );
+            System.out.println( "	Authentication	= " +
+                ( ( br.getAuthentication() instanceof SimpleAuthenticationPOJO ) ? "Simple"
: "sasl" ) );
+            System.out.println( "	simple		= " +
+                ( ( SimpleAuthenticationPOJO ) br.getAuthentication() ).getSimple() );
+
+            ldapMessageContainer.free();
+        }
+        catch ( DecoderException de )
+        {
+            log.error( de.getMessage() );
+            de.printStackTrace();
+        }
+        catch ( PoolException pe )
+        {
+            log.error( "Cannot allocat a BindRequestContainer : " + pe.getMessage() );
+
+            return;
+        }
+    }
+} // end class TLVTagDecoderTest



Mime
View raw message