directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r191031 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Date Thu, 16 Jun 2005 23:13:06 GMT
Author: elecharny
Date: Thu Jun 16 16:13:04 2005
New Revision: 191031

URL: http://svn.apache.org/viewcvs?rev=191031&view=rev
Log:
Added the tests of the Substring Filter grammar.

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=191031&r1=191030&r2=191031&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
Thu Jun 16 16:13:04 2005
@@ -489,6 +489,580 @@
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x65 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x63,                   // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, 0x5D,                   //	      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, 0x12,        	  // Filter ::= CHOICE {
+				                         	  //    substrings      [4] SubstringFilter
+											  // }
+									     	  // SubstringFilter ::= SEQUENCE {
+				0x04, 0x0B,                   //     type            AttributeDescription,
+				'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+				0x30, 0x03,
+				(byte)0x80, 0x01, 't',        //
+                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());
+
+        // 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 testDecodeSearchRequestSubstringAny()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x65 );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x63,                   // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, 0x5D,                   //	      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, 0x12,        	  // Filter ::= CHOICE {
+				                         	  //    substrings      [4] SubstringFilter
+											  // }
+									     	  // SubstringFilter ::= SEQUENCE {
+				0x04, 0x0B,                   //     type            AttributeDescription,
+				'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+				0x30, 0x03,
+				(byte)0x81, 0x01, 't',        //
+                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(null, substringFilter.getInitialSubstrings());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
+        Assert.assertEquals(null, substringFilter.getFinalSubstrings());
+
+        // 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 testDecodeSearchRequestSubstringAnyFinal()
+    {
+        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)0x81, 0x01, 't',        //
+				(byte)0x82, 0x01, 't',        //
+                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(null, substringFilter.getInitialSubstrings());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
+        Assert.assertEquals("t", substringFilter.getFinalSubstrings().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 testDecodeSearchRequestSubstringInitialAnyFinal()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x6B );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x69,                   // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, 0x63,                   //	      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, 0x18,        	  // Filter ::= CHOICE {
+				                         	  //    substrings      [4] SubstringFilter
+											  // }
+									     	  // SubstringFilter ::= SEQUENCE {
+				0x04, 0x0B,                   //     type            AttributeDescription,
+				'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+				0x30, 0x09,
+				(byte)0x80, 0x01, 't',        //
+				(byte)0x81, 0x01, 't',        //
+				(byte)0x82, 0x01, 't',        //
+                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("t", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
+        Assert.assertEquals("t", substringFilter.getFinalSubstrings().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 testDecodeSearchRequestSubstringInitialAnyAnyFinal()
+    {
+        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();
+        
+        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 testDecodeSearchRequestSubstringAnyAnyFinal()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x66B );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x69,                   // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, 0x63,                   //	      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, 0x18,        	  // Filter ::= CHOICE {
+				                         	  //    substrings      [4] SubstringFilter
+											  // }
+									     	  // SubstringFilter ::= SEQUENCE {
+				0x04, 0x0B,                   //     type            AttributeDescription,
+				'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+				0x30, 0x09,
+				(byte)0x81, 0x01, 't',        //
+				(byte)0x81, 0x01, 't',        //
+				(byte)0x82, 0x01, 't',        //
+                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(null, substringFilter.getInitialSubstrings());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(1)).toString());
+        Assert.assertEquals("t", substringFilter.getFinalSubstrings().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 testDecodeSearchRequestSubstringInitialAnyAny()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
         ByteBuffer  stream      = ByteBuffer.allocate( 0x68 );
         stream.put(
             new byte[]
@@ -563,6 +1137,105 @@
         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();
+        
+        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*t*t*)
+     */
+    public void testDecodeSearchRequestSubstringAnyAnyAny()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x6B );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x69,                   // LDAPMessage ::=SEQUENCE {
+				  0x02, 0x01, 0x01, 	          //        messageID MessageID
+				  0x63, 0x63,                   //	      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, 0x18,        	  // Filter ::= CHOICE {
+				                         	  //    substrings      [4] SubstringFilter
+											  // }
+									     	  // SubstringFilter ::= SEQUENCE {
+				      0x04, 0x0B,                   //     type            AttributeDescription,
+				      'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+				      0x30, 0x09,
+				        (byte)0x81, 0x01, 't',        //
+				        (byte)0x81, 0x01, 't',        //
+				        (byte)0x81, 0x01, 't',        //
+                    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(null, substringFilter.getInitialSubstrings());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(0)).toString());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(1)).toString());
+        Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(2)).toString());
+        Assert.assertEquals(null, substringFilter.getFinalSubstrings());
 
         // The attributes
         ArrayList attributes = sr.getAttributes();



Mime
View raw message