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/16 01:33:16 UTC
svn commit: r190835 -
/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Author: elecharny
Date: Wed Jun 15 16:33:16 2005
New Revision: 190835
URL: http://svn.apache.org/viewcvs?rev=190835&view=rev
Log:
Added a new test on substringFilters
Modified:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Modified: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java?rev=190835&r1=190834&r2=190835&view=diff
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java (original)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java Wed Jun 15 16:33:16 2005
@@ -25,6 +25,7 @@
import org.apache.asn1.ldap.pojo.AttributeValueAssertion;
import org.apache.asn1.ldap.pojo.LdapMessage;
import org.apache.asn1.ldap.pojo.SearchRequest;
+import org.apache.asn1.ldap.pojo.SubstringFilter;
import org.apache.asn1.ldap.pojo.filters.AndFilter;
import org.apache.asn1.ldap.pojo.filters.AttributeValueAssertionFilter;
import org.apache.asn1.ldap.pojo.filters.NotFilter;
@@ -467,6 +468,101 @@
Assert.assertEquals("objectclass", assertion.getAttributeDesc().toString());
Assert.assertEquals("[74][74][74]", assertion.getAssertionValue().toString());
+
+ // The attributes
+ ArrayList attributes = sr.getAttributes();
+
+ for (int i = 0; i < attributes.size(); i++)
+ {
+ MutableString attribute = (MutableString)attributes.get(i);
+
+ Assert.assertEquals("attr" + i, attribute.toString());
+ }
+ }
+
+ /**
+ * Test the decoding of a SearchRequest with a substring filter.
+ * Test the initial filter :
+ * (objectclass=t*)
+ */
+ public void testDecodeSearchRequestSubstringInitialAny()
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x68 );
+ stream.put(
+ new byte[]
+ {
+ 0x30, 0x66, // LDAPMessage ::=SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x63, 0x60, // CHOICE { ..., searchRequest SearchRequest, ...
+ // SearchRequest ::= APPLICATION[3] SEQUENCE {
+ 0x04, 0x1F, // baseObject LDAPDN,
+ 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=',
+ 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm',
+ 0x0A, 0x01, 0x01, // scope ENUMERATED {
+ // baseObject (0),
+ // singleLevel (1),
+ // wholeSubtree (2) },
+ 0x0A, 0x01, 0x03, // derefAliases ENUMERATED {
+ // neverDerefAliases (0),
+ // derefInSearching (1),
+ // derefFindingBaseObj (2),
+ // derefAlways (3) },
+ // sizeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ // timeLimit INTEGER (0 .. maxInt), (1000)
+ 0x02, 0x02, 0x03, (byte)0xE8,
+ 0x01, 0x01, 0x3E, // typesOnly BOOLEAN, (TRUE)
+ // filter Filter,
+ (byte)0xA4, 0x15, // Filter ::= CHOICE {
+ // substrings [4] SubstringFilter
+ // }
+ // SubstringFilter ::= SEQUENCE {
+ 0x04, 0x0B, // type AttributeDescription,
+ 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+ 0x30, 0x06,
+ (byte)0x80, 0x01, 't', //
+ (byte)0x81, 0x01, '*', //
+ 0x30, 0x15, // AttributeDescriptionList ::= SEQUENCE OF AttributeDescription
+ 0x04, 0x05, 'a', 't', 't', 'r', '0', // AttributeDescription ::= LDAPString
+ 0x04, 0x05, 'a', 't', 't', 'r', '1', // AttributeDescription ::= LDAPString
+ 0x04, 0x05, 'a', 't', 't', 'r', '2' // AttributeDescription ::= LDAPString
+ } );
+
+ 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();
+ SearchRequest sr = ( SearchRequest ) ( message.getProtocolOp() );
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "uid=akarasulu,dc=example,dc=com", sr.getBaseObject().toString() );
+ Assert.assertEquals( LdapConstants.SCOPE_SINGLE_LEVEL, sr.getScope() );
+ Assert.assertEquals( LdapConstants.DEREF_ALWAYS, sr.getDerefAliases() );
+ Assert.assertEquals( 1000, sr.getSizeLimit() );
+ Assert.assertEquals( 1000, sr.getTimeLimit() );
+ Assert.assertEquals( true, sr.isTypesOnly() );
+
+ // (objectclass=t*)
+ SubstringFilter substringFilter = (SubstringFilter)sr.getFilter();
+ Assert.assertNotNull(substringFilter);
+
+ Assert.assertEquals("objectclass", substringFilter.getType().toString());
+ Assert.assertEquals("t", substringFilter.getInitialSubstrings().toString());
+ Assert.assertEquals("*", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
// The attributes
ArrayList attributes = sr.getAttributes();