directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r348434 - /directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java
Date Wed, 23 Nov 2005 13:23:37 GMT
Author: elecharny
Date: Wed Nov 23 05:23:33 2005
New Revision: 348434

URL: http://svn.apache.org/viewcvs?rev=348434&view=rev
Log:
Added the Van Nhu test which check that controls are correctly handled

Modified:
    directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java

Modified: directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java?rev=348434&r1=348433&r2=348434&view=diff
==============================================================================
--- directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java
(original)
+++ directory/shared/ldap/trunk/apache2-provider/src/test/org/apache/asn1new/ldap/codec/SearchRequestTest.java
Wed Nov 23 05:23:33 2005
@@ -27,6 +27,7 @@
 import org.apache.asn1new.ber.containers.IAsn1Container;
 import org.apache.asn1new.ldap.codec.primitives.LdapString;
 import org.apache.asn1new.ldap.pojo.AttributeValueAssertion;
+import org.apache.asn1new.ldap.pojo.Control;
 import org.apache.asn1new.ldap.pojo.LdapMessage;
 import org.apache.asn1new.ldap.pojo.SearchRequest;
 import org.apache.asn1new.ldap.pojo.filters.AndFilter;
@@ -1772,4 +1773,101 @@
             Assert.fail( ee.getMessage() );
         }
     }
+    
+    /**
+    * Test the decoding of a SearchRequest with controls.
+    */
+    public void testDecodeSearchRequestWithControls()
+    {
+       byte[] asn1BER = new byte[]
+       {
+           0x30, 0x7f,
+               0x02, 0x01, 0x04, // messageID
+               0x63, 0x33,
+                   0x04, 0x13,
+                       0x64, 0x63, 0x3d, 0x6d, 0x79, 0x2d, 0x64, 0x6f, 0x6d, 0x61,
+                               0x69, 0x6e, 0x2c, 0x64, 0x63, 0x3d, 0x63, 0x6f, 0x6d, // baseObject:
dc=my-domain,dc=com
+                   0x0a, 0x01, 0x02, // scope: subtree
+                   0x0a, 0x01, 0x03, // derefAliases: derefAlways
+                   0x02, 0x01, 0x00, // sizeLimit: 0
+                   0x02, 0x01, 0x00, // timeLimit: 0
+                   0x01, 0x01, 0x00, // typesOnly: false
+                   (byte)0x87, 0x0b,
+                       0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x43, 0x6c, 0x61, 0x73, 0x73,
// filter: (objectClass=*)
+                   0x30, 0x00,
+               (byte)0xa0, 0x45, // controls
+                   0x30, 0x28,
+                       0x04, 0x16,
+                           0x31, 0x2e, 0x32, 0x2e, 0x38, 0x34, 0x30, 0x2e, 0x31, 0x31,
+                                   0x33, 0x35, 0x35, 0x36, 0x2e, 0x31, 0x2e, 0x34, 0x2e,
0x33,
+                                   0x31, 0x39, // control oid: 1.2.840.113556.1.4.319
+                       0x01, 0x01, (byte)0xff, // criticality: false
+                       0x04, 0x0b,
+                           0x30, 0x09, 0x02, 0x01, 0x02, 0x04, 0x04, 0x47, 0x00, 0x00, 0x00,
// value: pageSize=2
+                   0x30, 0x19,
+                       0x04, 0x17,
+                           0x32, 0x2e, 0x31, 0x36, 0x2e, 0x38, 0x34, 0x30, 0x2e, 0x31,
+                                   0x2e, 0x31, 0x31, 0x33, 0x37, 0x33, 0x30, 0x2e, 0x33,
0x2e,
+                                   0x34, 0x2e, 0x32 // control oid: 2.16.840.1.113730.3.4.2
+       };
+    
+       Asn1Decoder ldapDecoder = new LdapDecoder();
+    
+       ByteBuffer  stream      = ByteBuffer.allocate( asn1BER.length );
+       stream.put( asn1BER );
+       String decodedPdu       = StringUtils.dumpBytes( stream.array() );
+       stream.flip();
+    
+       IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+    
+       try
+       {
+           ldapDecoder.decode( stream, ldapMessageContainer );
+       }
+       catch ( DecoderException de )
+       {
+           de.printStackTrace();
+           Assert.fail( de.getMessage() );
+       }
+    
+       LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+       Assert.assertEquals( 4, message.getMessageId() );
+       Assert.assertEquals( 2, message.getControls().size() );
+    
+       // this is a constant in Java 5 API
+       String pagedResultsControlOID = "1.2.840.113556.1.4.319";
+       Control pagedResultsControl = message.getControls( 0 );
+       Assert.assertEquals( pagedResultsControlOID, pagedResultsControl.getControlType()
);
+       Assert.assertTrue( pagedResultsControl.getCriticality() );
+    
+       // this is a constant in Java 5 API
+       String manageReferralControlOID = "2.16.840.1.113730.3.4.2";
+       Control manageReferralControl = message.getControls( 1 );
+       Assert.assertEquals( manageReferralControlOID, manageReferralControl.getControlType()
);
+    
+       SearchRequest sr    = message.getSearchRequest();
+       Assert.assertEquals( "dc=my-domain,dc=com", sr.getBaseObject() );
+       Assert.assertEquals( LdapConstants.SCOPE_WHOLE_SUBTREE, sr.getScope() );
+       Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliases() );
+       Assert.assertEquals( 0, sr.getSizeLimit() );
+       Assert.assertEquals( 0, sr.getTimeLimit() );
+       Assert.assertEquals( false, sr.isTypesOnly() );
+    
+       Assert.assertTrue( sr.getFilter() instanceof PresentFilter );
+       Assert.assertEquals ( "objectClass",
+           ( (PresentFilter) sr.getFilter() ).getAttributeDescription().getString());
+    
+       // Check the encoding
+       try
+       {
+           ByteBuffer bb = message.encode( null );
+           String encodedPdu = StringUtils.dumpBytes( bb.array() );
+           Assert.assertEquals(encodedPdu, decodedPdu );
+       }
+       catch ( EncoderException ee )
+       {
+           ee.printStackTrace();
+           Assert.fail( ee.getMessage() );
+       }
+    }    
 }



Mime
View raw message