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/24 23:49:07 UTC

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

Author: elecharny
Date: Fri Jun 24 14:49:06 2005
New Revision: 201683

URL: http://svn.apache.org/viewcvs?rev=201683&view=rev
Log:
Added a SearchResultEntry test case

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

Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java?rev=201683&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java Fri Jun 24 14:49:06 2005
@@ -0,0 +1,135 @@
+/*
+ *   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.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.LdapMessage;
+import org.apache.asn1.ldap.pojo.SearchResultEntry;
+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 SearchResultEntry codec
+ * 
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class SearchResultEntryTest extends TestCase {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( SearchResultEntryTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a SearchResultEntry
+     */
+    public void testDecodeSearchResultEntrySuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x50 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x4e, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x64, 0x49, 		//     CHOICE { ..., searchResEntry  SearchResultEntry, ...
+                        			// SearchResultEntry ::= [APPLICATION 4] SEQUENCE {
+									//     objectName      LDAPDN,
+				0x04, 0x1b, 'o', 'u', '=', 'c', 'o', 'n', 't', 'a', 'c', 't', 's', ',', 'd', 'c', '=', 'i', 'k', 't', 'e', 'k', ',', 'd', 'c', '=', 'c', 'o', 'm',
+									//     attributes      PartialAttributeList }
+									// PartialAttributeList ::= SEQUENCE OF SEQUENCE {
+                0x30, 0x2a, 
+                0x30, 0x28, 
+                					//     type    AttributeDescription,
+                0x04, 0x0b, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's',
+                					//     vals    SET OF AttributeValue }
+                0x31, 0x19, 
+                					// AttributeValue ::= OCTET STRING
+                0x04, 0x03, 't', 'o', 'p', 
+									// AttributeValue ::= OCTET STRING
+                0x04, 0x12, 'o', 'r', 'g', 'a', 'n', 'i', 'z', 'a', 't', 'i', 'o', 'n', 'a', 'l', 'U', 'n', 'i', 't'
+            } );
+
+        stream.flip();
+
+        // Allocate a BindRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+    	
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        SearchResultEntry searchResultEntry      = message.getSearchResultEntry();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "ou=contacts,dc=iktek,dc=com", searchResultEntry.getObjectName() );
+
+        ArrayList partialAttributesList = searchResultEntry.getPartialAttributeList();
+        
+        Assert.assertEquals( 1, partialAttributesList.size() );
+        
+        for ( int i = 0; i < partialAttributesList.size(); i++ )
+        {
+            BasicAttribute attributeValue = (BasicAttribute)partialAttributesList.get( i );
+            
+            Assert.assertEquals( "objectClass", attributeValue.getID() );
+            
+            NamingEnumeration values = attributeValue.getAll();
+            
+            HashSet expectedValues = new HashSet();
+            
+            expectedValues.add( "[74][6F][70]" );
+            expectedValues.add( "[6F][72][67][61][6E][69][7A][61][74][69][6F][6E][61][6C][55][6E][69][74]" ); 
+            
+            while ( values.hasMore() )
+            {
+                OctetString value = (OctetString)values.next();
+                
+                Assert.assertTrue( expectedValues.contains( value.toString() ) );
+                
+                expectedValues.remove( value.toString() );
+            }
+        }
+    }
+}