directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r208910 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddRequestTest.java
Date Sun, 03 Jul 2005 12:31:44 GMT
Author: elecharny
Date: Sun Jul  3 05:31:43 2005
New Revision: 208910

URL: http://svn.apache.org/viewcvs?rev=208910&view=rev
Log:
Added the AddRequest test case

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

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddRequestTest.java?rev=208910&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddRequestTest.java
(added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/AddRequestTest.java
Sun Jul  3 05:31:43 2005
@@ -0,0 +1,163 @@
+/*
+ *   Copyright 2005 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.asn1.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 org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.AddRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.primitives.OctetString;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the AddRequest codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class AddRequestTest extends TestCase {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( AddRequestTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a AddRequest
+     */
+    public void testDecodeAddRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x5B );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x59, 		// LDAPMessage ::= SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x68, 0x54, 		//     CHOICE { ..., addRequest   AddRequest, ...
+                        			// AddRequest ::= [APPLICATION 8] 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',
+									//     attributes      AttributeList }
+                0x30, 0x2E,         // AttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x0c,         // attribute 1
+                0x04, 0x01, 'l',    //     type    AttributeDescription,
+                0x31, 0x07,         //     vals    SET OF AttributeValue }
+                0x04, 0x05, 'P', 'a', 'r', 'i', 's',
+
+                0x30, 0x1E,         // attribute 2
+                					//     type    AttributeDescription,
+                0x04, 0x05, 'a', 't', 't', 'r', 's', 
+                0x31, 0x15,         //     vals    SET OF AttributeValue }
+                0x04, 0x05, 't', 'e', 's', 't', '1',
+                0x04, 0x05, 't', 'e', 's', 't', '2',
+                0x04, 0x05, 't', 'e', 's', 't', '3',
+            } );
+
+        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();
+        AddRequest addRequest      = message.getAddRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", addRequest.getEntry()
);
+
+        ArrayList attributes = addRequest.getAttributes();
+        
+        Assert.assertEquals( 2, attributes.size() );
+        
+        HashSet expectedTypes = new HashSet();
+        
+        expectedTypes.add("l");
+        expectedTypes.add("attrs");
+        
+        HashMap typesVals = new HashMap();
+        
+        HashSet lVal1 = new HashSet();
+        lVal1.add("[50][61][72][69][73]");
+        typesVals.put("l", lVal1);
+        
+        HashSet lVal2 = new HashSet();
+        lVal2.add("[74][65][73][74][31]");
+        lVal2.add("[74][65][73][74][32]");
+        lVal2.add("[74][65][73][74][33]");
+        typesVals.put("attrs", lVal2);
+        
+        BasicAttribute attributeValue = (BasicAttribute)attributes.get( 0 );
+            
+        Assert.assertTrue( expectedTypes.contains( attributeValue.getID() ) );
+            
+        NamingEnumeration values = attributeValue.getAll();
+        HashSet vals = (HashSet)typesVals.get( attributeValue.getID() );
+
+        while ( values.hasMore() )
+        {
+            OctetString value = (OctetString)values.next();
+            
+            Assert.assertTrue( vals.contains( value.toString() ) );
+            
+            vals.remove( value.toString() );
+        }
+
+        attributeValue = (BasicAttribute)attributes.get( 1 );
+        
+	    Assert.assertTrue( expectedTypes.contains( attributeValue.getID() ) );
+	        
+	    values = attributeValue.getAll();
+	    vals = (HashSet)typesVals.get( attributeValue.getID() );
+	
+	    while ( values.hasMore() )
+	    {
+	        OctetString value = (OctetString)values.next();
+	        
+	        Assert.assertTrue( vals.contains( value.toString() ) );
+	        
+	        vals.remove( value.toString() );
+	    }
+
+    }
+}



Mime
View raw message