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/26 11:56:29 UTC

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

Author: elecharny
Date: Sat Jun 25 00:51:35 2005
New Revision: 201735

URL: http://svn.apache.org/viewcvs?rev=201735&view=rev
Log:
Added a test with two attributes to get

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

Modified: 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=201735&r1=201734&r2=201735&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchResultEntryTest.java Sat Jun 25 00:51:35 2005
@@ -132,4 +132,98 @@
             }
         }
     }
+
+    /**
+     * Test the decoding of a SearchResultEntry
+     */
+    public void testDecodeSearchResultEntry2AttrsSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x7c );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x7a, 		// LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	//     messageID MessageID
+				0x64, 0x74, 		//     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, 0x55, 
+                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',
+                0x30, 0x29, 
+				//     type    AttributeDescription,
+				0x04, 0x0c, 'o', 'b', 'j', 'e', 'c', 't', 'C', 'l', 'a', 's', 's', '2',
+								//     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( 2, partialAttributesList.size() );
+        
+        String[] expectedAttributes = new String[]{"objectClass", "objectClass2"}; 
+        
+        for ( int i = 0; i < partialAttributesList.size(); i++ )
+        {
+            BasicAttribute attributeValue = (BasicAttribute)partialAttributesList.get( i );
+            
+            Assert.assertEquals( expectedAttributes[i], 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() );
+            }
+        }
+    }
 }