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/06/01 01:48:07 UTC

svn commit: r179315 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddResponseTest.java

Author: elecharny
Date: Tue May 31 16:48:07 2005
New Revision: 179315

URL: http://svn.apache.org/viewcvs?rev=179315&view=rev
Log:
Added this AddResponse testcase

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

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddResponseTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddResponseTest.java?rev=179315&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddResponseTest.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddResponseTest.java Tue May 31 16:48:07 2005
@@ -0,0 +1,95 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.AddResponsePOJO;
+import org.apache.asn1.ldap.pojo.LdapMessagePOJO;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddResponseTest extends TestCase {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( AddResponseTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a AddResponse
+     */
+    public void testDecodeAddResponseSuccess()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x2D );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x2B, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//         messageID MessageID
+				0x69, 0x26, 		//        CHOICE { ..., addResponse AddResponse, ...
+                        			// AddResponse ::= [APPLICATION 9] 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 }
+            } );
+
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessagePOJO message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        AddResponsePOJO br      = ( AddResponsePOJO ) ( message.getProtocolOp() );
+
+        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() );
+    }
+}