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/09/09 23:43:24 UTC

svn commit: r279887 [13/15] - in /directory/shared/ldap/branches/elecharny-cleanup/apache2-provider: ./ conf/ perfs/ perfs/org/ perfs/org/apache/ perfs/org/apache/asn1new/ perfs/org/apache/asn1new/ber/ src/ src/java/ src/java/main/ src/java/main/org/ s...

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,184 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.BindResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class BindResponseTest extends TestCase {
+    /**
+     * Test the decoding of a BindResponse
+     */
+    public void testDecodeBindResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x61, 0x26, 		//        CHOICE { ..., bindResponse BindResponse, ...
+                        			// BindResponse ::= APPLICATION[1] SEQUENCE {
+									//        COMPONENTS OF 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 }
+									// serverSaslCreds [7] OCTET STRING OPTIONAL }
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the BindResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded BindResponse
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindResponse br      = message.getBindResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, br.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", br.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() );
+        }
+    }
+
+    /**
+     * Test the decoding of a BindResponse with a credentials
+     */
+    public void testDecodeBindResponseServerSASL()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x31 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2F, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x61, 0x2A, 		//        CHOICE { ..., bindResponse BindResponse, ...
+                        			// BindResponse ::= APPLICATION[1] SEQUENCE {
+									//        COMPONENTS OF 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 }
+				(byte)0x87, 0x02, 'A', 'B' // serverSaslCreds [7] OCTET STRING OPTIONAL }
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the BindResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded BindResponse
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        BindResponse br      = message.getBindResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, br.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", br.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", br.getLdapResult().getErrorMessage() );
+        Assert.assertEquals( "AB", br.getServerSaslCreds().toString());
+
+        // Check the length
+        Assert.assertEquals(0x31, 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/BindResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,153 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.CompareRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the CompareRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareRequestTest extends TestCase {
+
+    /**
+     * Test the decoding of a full CompareRequest
+     */
+    public void testDecodeCompareRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3A );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x38, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., compareRequest   CompareRequest, ...
+				0x6E, 0x33,         // CompareRequest ::= [APPLICATION 14] 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',
+				                    //     ava             AttributeValueAssertion }
+				0x30, 0x0D,         // AttributeValueAssertion ::= SEQUENCE {
+                                    //     attributeDesc   AttributeDescription,
+				0x04, 0x04, 't', 'e', 's', 't',
+				                    //     assertionValue  AssertionValue }
+				0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the CompareRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Ceck the decoded CompareRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        CompareRequest compareRequest      = message.getCompareRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", compareRequest.getEntry() );
+        Assert.assertEquals( "test", compareRequest.getAttributeDesc() );
+        Assert.assertEquals( "value", compareRequest.getAssertionValue().toString() );
+
+        // Check the length
+        Assert.assertEquals(0x3A, 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 an empty entry CompareRequest
+     */
+    public void testDecodeCompareRequestEmptyEntry() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x18 );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x16, 		// LDAPMessage ::= SEQUENCE {
+    				0x02, 0x01, 0x01, 	//     messageID MessageID
+    				            		//     CHOICE { ..., compareRequest   CompareRequest, ...
+    				0x6E, 0x11,         // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+    				0x04, 0x00,         //     entry           LDAPDN,
+    				                    //     ava             AttributeValueAssertion }
+    				0x30, 0x0D,         // AttributeValueAssertion ::= SEQUENCE {
+                                        //     attributeDesc   AttributeDescription,
+    				0x04, 0x04, 't', 'e', 's', 't',
+    				                    //     assertionValue  AssertionValue }
+    				0x04, 0x05, 'v', 'a', 'l', 'u', 'e'
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the CompareRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            Assert.fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,110 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.CompareResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the CompareResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class CompareResponseTest extends TestCase {
+    /**
+     * Test the decoding of a CompareResponse
+     */
+    public void testDecodeCompareResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x6F, 0x26, 		//        CHOICE { ..., compareResponse CompareResponse, ...
+                        			// CompareResponse ::= [APPLICATION 15] 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 CompareResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded CompareResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        CompareResponse compareResponse      = message.getCompareResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, compareResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", compareResponse.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", compareResponse.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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/CompareResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,141 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.DelRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the DelRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DelRequestTest extends TestCase {
+    /**
+     * Test the decoding of a full DelRequest
+     */
+    public void testDecodeDelRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x29 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x27, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., delRequest   DelRequest, ...
+                        			// DelRequest ::= [APPLICATION 10] LDAPDN;
+				0x4A, 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'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded DelRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        DelRequest delRequest      = message.getDelRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", delRequest.getEntry() );
+
+        // Check the length
+        Assert.assertEquals(0x29, 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 aempty DelRequest
+     */
+    public void testDecodeDelRequestEmpty() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x05, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., delRequest   DelRequest, ...
+                        			// DelRequest ::= [APPLICATION 10] LDAPDN;
+				0x4A, 0x00          // Empty DN
+            } );
+
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode a DelRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            Assert.fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            Assert.assertTrue( true );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,110 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.DelResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the DelResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class DelResponseTest extends TestCase {
+    /**
+     * Test the decoding of a DelResponse
+     */
+    public void testDecodeDelResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x6B, 0x26, 		//        CHOICE { ..., delResponse DelResponse, ...
+                        			// DelResponse ::= [APPLICATION 11] 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 DelResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded DelResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        DelResponse delResponse      = message.getDelResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, delResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", delResponse.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", delResponse.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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/DelResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,168 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.ExtendedRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the ExtendedRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedRequestTest extends TestCase {
+    /**
+     * Test the decoding of a full ExtendedRequest
+     */
+    public void testDecodeExtendedRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x16 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x14, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., extendedReq     ExtendedRequest, ...
+				0x77, 0x0F,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+				                    //     requestName      [0] LDAPOID,
+				(byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+				                    //     requestValue     [1] OCTET STRING OPTIONAL }
+				(byte)0x81, 0x05, 'v', 'a', 'l', 'u', 'e'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ExtendedRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+        Assert.assertEquals( "value", extendedRequest.getRequestValue().toString() );
+        
+        // Check the length
+        Assert.assertEquals(0x16, 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 name only ExtendedRequest
+     */
+    public void testDecodeExtendedRequestName() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x0F );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x0D, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., extendedReq     ExtendedRequest, ...
+				0x77, 0x08,         // ExtendedRequest ::= [APPLICATION 23] SEQUENCE {
+				                    //     requestName      [0] LDAPOID,
+				(byte)0x80, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ExtendedRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getRequestName() );
+        
+        // Check the length
+        Assert.assertEquals(0x0F, 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,191 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.EncoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ldap.pojo.ExtendedResponse;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.util.StringUtils;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the ExtendedResponse codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ExtendedResponseTest extends TestCase {
+    /**
+     * Test the decoding of a full ExtendedResponse
+     */
+    public void testDecodeExtendedResponseSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x3C );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x3A, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				            		//     CHOICE { ..., extendedResp     ExtendedResponse, ...
+				0x78, 0x35,         // ExtendedResponse ::= [APPLICATION 23] SEQUENCE {
+				                    //     COMPONENTS OF 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 }				                    //     requestName      [0] LDAPOID,
+				                    //    responseName     [10] LDAPOID OPTIONAL,
+				(byte)0x8A, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02,
+				                    //    response         [11] OCTET STRING OPTIONAL }
+				(byte)0x8B, 0x05, 'v', 'a', 'l', 'u', 'e'
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", extendedResponse.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", extendedResponse.getLdapResult().getErrorMessage() );
+        Assert.assertEquals( "1.3.6.1.5.5.2", extendedResponse.getResponseName() );
+        Assert.assertEquals( "value", extendedResponse.getResponse().toString() );
+        
+        // Check the length
+        Assert.assertEquals(0x3C, 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 ExtendedRequest with only a name
+     */
+    public void testDecodeExtendedRequestName() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x2B, 		// LDAPMessage ::= SEQUENCE {
+    				0x02, 0x01, 0x01, 	//     messageID MessageID
+    				            		//     CHOICE { ..., extendedResp     Response, ...
+    				0x78, 0x26,         // ExtendedResponse ::= [APPLICATION 24] SEQUENCE {
+    				                    //     COMPONENTS OF 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 }				                    //     requestName      [0] LDAPOID,
+            } );
+
+        String decodedPdu = StringUtils.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the ExtendedResponse PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        // Check the decoded ExtendedResponse PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedResponse extendedResponse      = message.getExtendedResponse();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( 0, extendedResponse.getLdapResult().getResultCode() );
+        Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", extendedResponse.getLdapResult().getMatchedDN() );
+        Assert.assertEquals( "", extendedResponse.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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ExtendedResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,361 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1new.ber.Asn1Decoder;
+import org.apache.asn1new.ber.containers.IAsn1Container;
+import org.apache.asn1new.ber.tlv.TLVStateEnum;
+import org.apache.asn1new.ldap.pojo.BindRequest;
+import org.apache.asn1new.ldap.pojo.LdapMessage;
+import org.apache.asn1new.ldap.pojo.SimpleAuthentication;
+
+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
+{
+    //~ 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
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( TLVStateEnum.VALUE_STATE_PENDING, ldapMessageContainer.getState() );
+        
+        // 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
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( TLVStateEnum.VALUE_STATE_PENDING, ldapMessageContainer.getState() );
+
+        // 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
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        Assert.assertEquals( ldapMessageContainer.getState(), TLVStateEnum.PDU_DECODED );
+        
+        // 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." );
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/LdapDecoderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,179 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.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 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 {
+    /**
+     * 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,110 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.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 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 {
+    /**
+     * 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyDNResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,169 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.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 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 {
+    /**
+     * 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyRequestTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java?rev=279887&view=auto
==============================================================================
--- directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java (added)
+++ directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java Fri Sep  9 14:41:22 2005
@@ -0,0 +1,110 @@
+/*
+ *   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.asn1.codec.DecoderException;
+import org.apache.asn1.codec.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 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 {
+    /**
+     * 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() );
+        }
+    }
+}

Propchange: directory/shared/ldap/branches/elecharny-cleanup/apache2-provider/src/test/org/apache/asn1new/ldap/codec/ModifyResponseTest.java
------------------------------------------------------------------------------
    svn:eol-style = native