directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r234277 [2/4] - in /directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test: ./ org/ org/apache/ org/apache/asn1new/ org/apache/asn1new/ldap/ org/apache/asn1new/ldap/codec/ org/apache/asn1new/ldap/codec/utils/
Date Sun, 21 Aug 2005 17:17:41 GMT
Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
(added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
Sun Aug 21 10:17:28 2005
@@ -0,0 +1,378 @@
+/*
+ *   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.asn1new.ldap.codec;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.BindRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.SimpleAuthentication;
+
+import org.apache.log4j.PropertyConfigurator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * A global Ldap Decoder test
+ * 
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class LdapDecoderTest extends TestCase
+{
+    //~ Static fields/initializers -----------------------------------------------------------------
+
+    /** Logger */
+    protected static Logger log = LoggerFactory.getLogger( LdapDecoderTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "../../conf/log4j.conf" );
+    }
+
+    //~ Methods ------------------------------------------------------------------------------------
+
+    /**
+     * Test the decoding of a full PDU
+     */
+    public void testDecodeFull()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        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', '=', '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();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        // Check the decoded PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindRequest br      = message.getBindRequest();
+
+        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 SimpleAuthentication
) );
+        Assert.assertEquals( "password",
+            ( ( SimpleAuthentication ) br.getAuthentication() ).getSimple().toString() );
+    }
+
+    /**
+     * Test the decoding of a partial PDU
+     */
+    public void testDecodePartial()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        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 LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU
+        boolean isDecoded = false;
+        
+        try
+        {
+            isDecoded = ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( isDecoded, false );
+        
+        // Check the decoded PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindRequest br      = message.getBindRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 3, br.getVersion() );
+        Assert.assertEquals( null, br.getName() );
+        Assert.assertEquals( false, ( br.getAuthentication() instanceof SimpleAuthentication
) );
+    }
+
+    /**
+     * Test the decoding of a splitted PDU
+     */
+    public void testDecodeSplittedPDU()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        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 LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU first block of data
+        boolean isDecoded = false;
+
+        try
+        {
+            isDecoded = ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( isDecoded, false );
+
+        // 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();
+
+        // Decode a BindRequest PDU second block of data
+        try
+        {
+            isDecoded = ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( isDecoded, true );
+        
+        // Check the decoded PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindRequest br      = message.getBindRequest();
+
+        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 SimpleAuthentication
) );
+        Assert.assertEquals( "password",
+            ( ( SimpleAuthentication ) br.getAuthentication() ).getSimple().toString() );
+    }
+
+    /**
+     * Test the decoding of a PDU with a bad Length.
+     * The first TLV has a length of 0x32 when the PDU is 0x33 bytes long.
+     */
+    public void testDecodeBadLengthTooSmall()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        stream.put(
+            new byte[]
+            {
+                    				// Length should be 0x33...
+                0x30, 0x32, 		// 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', '=', '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();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertEquals( "The current Value length is above the expected length",
+                de.getMessage() );
+            return;
+        }
+
+        Assert.fail( "Should never reach this point.." );
+    }
+
+    /**
+     * Test the decoding of a PDU with a bad primitive Length.
+     * The second TLV has a length of 0x02 when the PDU is 0x01 bytes long.
+     */
+    public void testDecodeBadPrimitiveLengthTooBig()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x33, 		// LDAPMessage ::=SEQUENCE {
+                					// Length should be 0x01...
+                0x02, 0x02, 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', '=', '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'
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertEquals( "Universal tag 14 is reserved", de.getMessage() );
+            return;
+        }
+
+        Assert.fail( "Should never reach this point." );
+    }
+
+    /**
+     * Test the decoding of a PDU with a bad primitive Length.
+     * The second TLV has a length of 0x02 when the PDU is 0x01 bytes long.
+     */
+    public void testDecodeBadTagTransition()
+    {
+
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x35 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x33, 		// LDAPMessage ::=SEQUENCE {
+                					// Length should be 0x01...
+                0x02, 0x01, 0x01, 	//         messageID MessageID
+                0x2D, 0x2D, 		//        CHOICE { ..., bindRequest BindRequest, ...
+                        			// BindRequest ::= APPLICATION[0] SEQUENCE {
+                0x02, 0x01, 0x03, 	//        version INTEGER (1..127),
+                0x04, 0x1F, 		//        name LDAPDN,
+                'u', 'i', 'd', '=', '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();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a BindRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertEquals( "Bad transition !",
+                de.getMessage() );
+            return;
+        }
+
+        Assert.fail( "Should never reach this point." );
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
(added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
Sun Aug 21 10:17:28 2005
@@ -0,0 +1,190 @@
+/*
+ *   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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.ModifyDNRequest;
+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;
+
+/**
+ * Test the ModifyDNRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyDNRequestTest extends TestCase {
+    /** Logger */
+    protected static Logger log = LoggerFactory.getLogger( ModifyDNRequestTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "../../conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a full ModifyDNRequest
+     */
+    public void testDecodeModifyDNRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x4A );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x48, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x6C, 0x43, 		//     CHOICE { ..., modifyDNRequest   ModifyDNRequest, ...
+                        			// ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+									//     entry           LDAPDN,
+				0x04, 0x22, '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',
+			                        //     newrdn          RelativeLDAPDN,
+                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i',
'f', 'y',
+                0x01, 0x01, 0x00,   //     deleteoldrdn    BOOLEAN,
+                                    // newSuperior     [0] LDAPDN OPTIONAL }
+                (byte)0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a ModifyRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyDNRequest modifyDNRequest      = message.getModifyDNRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", modifyDNRequest.getEntry()
);
+        Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+        Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+        Assert.assertEquals( "ou=system", modifyDNRequest.getNewSuperior() );
+
+        // Check the length
+        Assert.assertEquals(0x4A, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of a ModifyDNRequest without a superior
+     */
+    public void testDecodeModifyDNRequestWithoutSuperior() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3F );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x3D, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x6C, 0x38, 		//     CHOICE { ..., modifyDNRequest   ModifyDNRequest, ...
+                        			// ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+									//     entry           LDAPDN,
+				0x04, 0x22, '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',
+			                        //     newrdn          RelativeLDAPDN,
+                0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i',
'f', 'y',
+                0x01, 0x01, 0x00   //     deleteoldrdn    BOOLEAN,
+                                    // newSuperior     [0] LDAPDN OPTIONAL }
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a ModifyRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyDNRequest modifyDNRequest      = message.getModifyDNRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", modifyDNRequest.getEntry()
);
+        Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+        Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+        
+        // Check the length
+        Assert.assertEquals(0x3F, message.computeLength());
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
(added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
Sun Aug 21 10:17:28 2005
@@ -0,0 +1,121 @@
+/*
+ *   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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.ModifyDNResponse;
+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;
+
+/**
+ * Test the ModifyDNResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyDNResponseTest extends TestCase {
+    /** Logger */
+    protected static Logger log = LoggerFactory.getLogger( ModifyDNResponseTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "../../conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a ModifyDNResponse
+     */
+    public void testDecodeModifyResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x6D, 0x26, 		//        CHOICE { ..., modifyDNResponse ModifyDNResponse, ...
+                        			// ModifyDNResponse ::= [APPLICATION 13] LDAPResult
+				0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
+									//		resultCode ENUMERATED {
+									//			success (0), ...
+				 					//      },
+				0x04, 0x1F,			//		matchedDN    LDAPDN,
+				'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+                'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+				0x04, 0x00  		//      errorMessage LDAPString,
+									//		referral     [3] Referral OPTIONAL }
+									// }
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ModifyDNResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ModifyDNResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyDNResponse modifyDNResponse      = message.getModifyDNResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, modifyDNResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", modifyDNResponse.getLdapResult().getMatchedDN()
);
+        Assert.assertEquals( "", modifyDNResponse.getLdapResult().getErrorMessage() );
+        
+        // Check the length
+        Assert.assertEquals(0x2D, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
(added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
Sun Aug 21 10:17:28 2005
@@ -0,0 +1,180 @@
+/*
+ *   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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.directory.BasicAttribute;
+import javax.naming.directory.ModificationItem;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+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;
+
+/**
+ * Test the ModifyRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyRequestTest extends TestCase {
+    /** Logger */
+    protected static Logger log = LoggerFactory.getLogger( ModifyRequestTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "../../conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a ModifyRequest
+     */
+    public void testDecodeModifyRequest2AttrsSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x56 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x54, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x66, 0x4f, 		//     CHOICE { ..., modifyRequest   ModifyRequest, ...
+                        			// ModifyRequest ::= [APPLICATION 6] SEQUENCE {
+									//     object          LDAPDN,
+				0x04, 0x22, '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 {
+                0x04, 0x05, 'a', 't', 't', 'r', 's', //     type    AttributeDescription,
+                0x31, 0x06,         //     vals    SET OF AttributeValue }
+                0x04, 0x04, 't', 'e', 's', 't'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        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( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", modifyRequest.getObject()
);
+
+        ArrayList modifications = modifyRequest.getModifications();
+        
+        Assert.assertEquals( 2, modifications.size() );
+        
+        HashSet expectedTypes = new HashSet();
+        
+        expectedTypes.add("l");
+        expectedTypes.add("attrs");
+        
+        HashMap typesVals = new HashMap();
+        
+        HashSet lVals = new HashSet();
+        lVals.add("Paris");
+        typesVals.put("l", lVals);
+        
+        HashSet attrsVals = new HashSet();
+        attrsVals.add("test");
+        typesVals.put("attrs", attrsVals);
+        
+        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(0x56, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}

Added: directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java?rev=234277&view=auto
==============================================================================
--- directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
(added)
+++ directory/shared/ldap/branches/new-codec-integration/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
Sun Aug 21 10:17:28 2005
@@ -0,0 +1,122 @@
+/*
+ *   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.asn1new.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1new.DecoderException;
+import org.apache.asn1new.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.ModifyResponse;
+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;
+
+/**
+ * Test the ModifyResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyResponseTest extends TestCase {
+    /** Logger */
+    protected static Logger log = LoggerFactory.getLogger( ModifyResponseTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "../../conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a ModifyResponse
+     */
+    public void testDecodeModifyResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x67, 0x26, 		//        CHOICE { ..., modifyResponse ModifyResponse, ...
+                        			// ModifyResponse ::= [APPLICATION 7] LDAPResult
+				0x0A, 0x01, 0x00, 	//   LDAPResult ::= SEQUENCE {
+									//		resultCode ENUMERATED {
+									//			success (0), ...
+				 					//      },
+				0x04, 0x1F,			//		matchedDN    LDAPDN,
+				'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+                'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+				0x04, 0x00  		//      errorMessage LDAPString,
+									//		referral     [3] Referral OPTIONAL }
+									// }
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a ModifyResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ModifyResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ModifyResponse modifyResponse      = message.getModifyResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, modifyResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", modifyResponse.getLdapResult().getMatchedDN()
);
+        Assert.assertEquals( "", modifyResponse.getLdapResult().getErrorMessage() );
+        
+        // Check the length
+        Assert.assertEquals(0x2D, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringUtils.dumpBytes( bb.array() ); 
+            
+            Assert.assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            Assert.fail( ee.getMessage() );
+        }
+    }
+}



Mime
View raw message