directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208987 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
Date Sun, 03 Jul 2005 21:43:25 GMT
Author: elecharny
Date: Sun Jul  3 14:43:24 2005
New Revision: 208987

URL: http://svn.apache.org/viewcvs?rev=208987&view=rev
Log:
Added the ExtendedRequest tests

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

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java?rev=208987&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ExtendedRequestTest.java
Sun Jul  3 14:43:24 2005
@@ -0,0 +1,134 @@
+/*
+ *   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 javax.naming.NamingException;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.ExtendedRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+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 {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( ExtendedRequestTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * 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'
+            } );
+
+        stream.flip();
+
+        // Allocate a DelRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getName() );
+        Assert.assertEquals( "[76][61][6C][75][65]", extendedRequest.getValue().toString()
);
+    }
+
+    /**
+     * Test the decoding of a name only ExtendedRequest
+     */
+    public void testDecodeExtendedRequestName() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x10 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x0E, 		// 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,
+            } );
+
+        stream.flip();
+
+        // Allocate a DelRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        ExtendedRequest extendedRequest      = message.getExtendedRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "1.3.6.1.5.5.2", extendedRequest.getName() );
+    }
+}



Mime
View raw message