directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r190326 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Date Sun, 12 Jun 2005 23:07:11 GMT
Author: elecharny
Date: Sun Jun 12 16:07:11 2005
New Revision: 190326

URL: http://svn.apache.org/viewcvs?rev=190326&view=rev
Log:
Added tests for the added filters.

SearchRequest is closed to be finished, as only Substrings filter and Extensible Match are
to be done.

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=190326&r1=190325&r2=190326&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
Sun Jun 12 16:07:11 2005
@@ -29,6 +29,7 @@
 import org.apache.asn1.ldap.pojo.filters.AttributeValueAssertionFilter;
 import org.apache.asn1.ldap.pojo.filters.NotFilter;
 import org.apache.asn1.ldap.pojo.filters.OrFilter;
+import org.apache.asn1.ldap.pojo.filters.PresentFilter;
 import org.apache.asn1.util.MutableString;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
@@ -53,7 +54,7 @@
      * The search filter is : 
      * (&(|(objectclass=top)(ou=contacts))(!(objectclass=ttt)))
      */
-    public void testDecodeSearchRequestNoControls()
+    public void testDecodeSearchRequestGlobalNoControls()
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
@@ -195,68 +196,210 @@
     }
 
     /**
-     * Test the decoding of a SearchRequest with no controls
+     * Test the decoding of a SearchRequest with no controls.
+     * Test the various types of filter : >=, <=, ~=
+     * The search filter is : 
+     * (&(|(objectclass~=top)(ou<=contacts))(!(objectclass>=ttt)))
      */
-/*    public void testDecodeSearchRequestSimpleNoControls()
+    public void testDecodeSearchRequestCompareFiltersNoControls()
     {
         Asn1Decoder ldapDecoder = new LdapDecoder();
 
-        ByteBuffer  stream      = ByteBuffer.allocate( 0x8F );
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x90 );
         stream.put(
             new byte[]
             {
-                0x30, (byte)0x81, (byte)0x8C,	 // LDAPMessage ::=SEQUENCE {
-				0x02, 0x01, 0x01, 	     //        messageID MessageID
-				0x63, (byte)0x81, (byte)0x86,  //	      CHOICE { ..., searchRequest SearchRequest, ...
-                        			     // SearchRequest ::= APPLICATION[3] SEQUENCE {
-				0x04, 0x1F, 		     //    baseObject LDAPDN,
+                0x30, (byte)0x81, (byte)0x8D, // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, (byte)0x81, (byte)0x87,                   //	      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)
+				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)
+                					     	  //    timeLimit INTEGER (0 .. maxInt), (1000)
 				0x02, 0x02, 0x03, (byte)0xE8,
-				0x01, 0x01, 0x3E,        //    typesOnly BOOLEAN, (TRUE)
-				                         //    filter    Filter,
-				(byte)0xA0, 0x52,        // Filter ::= CHOICE {
-				                         //    and             [0] SET OF Filter,
-				(byte)0xA1, 0x24,        //    or              [1] SET of Filter,
-				(byte)0xA3, 0x12,        //    equalityMatch   [3] AttributeValueAssertion,
-									     // AttributeValueAssertion ::= SEQUENCE {
-								 	     //    attributeDesc   AttributeDescription (LDAPString),
+				0x01, 0x01, 0x3E,        	  //    typesOnly BOOLEAN, (TRUE)
+				                         	  //    filter    Filter,
+				(byte)0xA0, 0x3C,        	  // Filter ::= CHOICE {
+				                         	  //    and             [0] SET OF Filter,
+				(byte)0xA1, 0x24,        	  //    or              [1] SET of Filter,
+				(byte)0xA8, 0x12,        	  //    approxMatch     [8] AttributeValueAssertion,
+									     	  // AttributeValueAssertion ::= SEQUENCE {
+								 	          //    attributeDesc   AttributeDescription (LDAPString),
 				0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
-									     //    assertionValue  AssertionValue (OCTET STRING) }
+									          //    assertionValue  AssertionValue (OCTET STRING) }
 				0x04, 0x03, 't', 'o', 'p',
-				(byte)0xA3, 0x0E,        //    equalityMatch   [3] AttributeValueAssertion,
-				                         // AttributeValueAssertion ::= SEQUENCE {
-				0x04, 0x02, 'o', 'u',    //    attributeDesc   AttributeDescription (LDAPString),
-			                             //    assertionValue  AssertionValue (OCTET STRING) }
+				(byte)0xA6, 0x0E,             //    lessOrEqual     [3] AttributeValueAssertion,
+				                              // AttributeValueAssertion ::= SEQUENCE {
+				0x04, 0x02, 'o', 'u',         //    attributeDesc   AttributeDescription (LDAPString),
+			                                  //    assertionValue  AssertionValue (OCTET STRING)
}
 				0x04, 0x08, 'c', 'o', 'n', 't', 'a', 'c', 't', 's',
-				(byte)0xA2, 0x14,        //    not             [2] Filter,
-				(byte)0xA3, 0x12,        //    equalityMatch   [3] AttributeValueAssertion,
-			                             // AttributeValueAssertion ::= SEQUENCE {
-		 	                             //    attributeDesc   AttributeDescription (LDAPString),
+				(byte)0xA2, 0x14,             //    not             [2] Filter,
+				(byte)0xA5, 0x12,             //    greaterOrEqual  [5] AttributeValueAssertion,
+			                                  // AttributeValueAssertion ::= SEQUENCE {
+		 	                                  //    attributeDesc   AttributeDescription (LDAPString),
                 0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
-			                             //    assertionValue  AssertionValue (OCTET STRING) }
+			                                  //    assertionValue  AssertionValue (OCTET STRING)
}
                 0x04, 0x03, 't', 't', 't',
-				(byte)0xA4, 0x14,        //    substrings      [4] SubstringFilter,
-				                         // SubstringFilter ::= SEQUENCE {
-				                         //    type            AttributeDescription (LDAPString),
-				0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
-				0x30, 0x05,              //    substrings      SEQUENCE OF CHOICE {
-				                         //       ...
-				                         //       final   [2] LDAPString } }
-				(byte)0x82, 0x03, 't', 'o', 'p'
-				
+              						          //    attributes      AttributeDescriptionList }
+                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() );
+        
+        // (& (...
+        AndFilter andFilter = (AndFilter)sr.getFilter();
+        Assert.assertNotNull(andFilter);
+        
+        ArrayList andFilters = andFilter.getAndFilter();
+        
+        // (& (| (...
+        Assert.assertEquals(2, andFilters.size());
+        OrFilter orFilter = (OrFilter)andFilters.get(0);
+        Assert.assertNotNull(orFilter);
+        
+        // (& (| (objectclass~=top) (...
+        ArrayList orFilters = orFilter.getOrFilter();
+        Assert.assertEquals(2, orFilters.size());
+        AttributeValueAssertionFilter approxMatch = (AttributeValueAssertionFilter)orFilters.get(0);
 
+        Assert.assertNotNull(approxMatch);
+        
+        AttributeValueAssertion assertion = approxMatch.getAssertion();
+        Assert.assertNotNull(assertion);
+        
+        Assert.assertEquals("objectclass", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[74][6F][70]", assertion.getAssertionValue().toString());
+        
+        // (& (| (objectclass~=top) (ou<=contacts) ) (...
+        AttributeValueAssertionFilter lessOrEqual = (AttributeValueAssertionFilter)orFilters.get(1);
 
+        Assert.assertNotNull(lessOrEqual);
+        
+        assertion = lessOrEqual.getAssertion();
+        Assert.assertNotNull(assertion);
+        
+        Assert.assertEquals("ou", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[63][6F][6E][74][61][63][74][73]", assertion.getAssertionValue().toString());
+        
+        // (& (| (objectclass~=top) (ou<=contacts) ) (! ...
+        NotFilter notFilter = (NotFilter)andFilters.get(1);
+        Assert.assertNotNull(notFilter);
+        
+        // (& (| (objectclass~=top) (ou<=contacts) ) (! (objectclass>=ttt) ) )
+        AttributeValueAssertionFilter greaterOrEqual = (AttributeValueAssertionFilter)notFilter.getNotFilter();
 
+        Assert.assertNotNull(greaterOrEqual);
+        
+        assertion = greaterOrEqual.getAssertion();
+        Assert.assertNotNull(assertion);
+        
+        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 no controls.
+     * Test the present filter : =*
+     * The search filter is : 
+     * (&(|(objectclass=*)(ou=*))(!(objectclass>=ttt)))
+     */
+    public void testDecodeSearchRequestPresentNoControls()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x7B );
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x79,                   // LDAPMessage ::=SEQUENCE {
+				0x02, 0x01, 0x01, 	          //        messageID MessageID
+				0x63, 0x74,                   //	      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)0xA0, 0x29,        	  // Filter ::= CHOICE {
+				                         	  //    and             [0] SET OF Filter,
+				(byte)0xA1, 0x11,        	  //    or              [1] SET of Filter,
+				(byte)0x87, 0x0B,        	  //    present         [7] AttributeDescription,
+									     	  // AttributeDescription ::= LDAPString
+				'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+									          //    assertionValue  AssertionValue (OCTET STRING) }
+				(byte)0x87, 0x02, 'o', 'u',   //    present         [7] AttributeDescription,
+				                              // AttributeDescription ::= LDAPString
+				(byte)0xA2, 0x14,             //    not             [2] Filter,
+				(byte)0xA5, 0x12,             //    greaterOrEqual  [5] AttributeValueAssertion,
+			                                  // AttributeValueAssertion ::= SEQUENCE {
+		 	                                  //    attributeDesc   AttributeDescription (LDAPString),
+                0x04, 0x0B, 'o', 'b', 'j', 'e', 'c', 't', 'c', 'l', 'a', 's', 's',
+			                                  //    assertionValue  AssertionValue (OCTET STRING)
}
+                0x04, 0x03, 't', 't', 't',
+              						          //    attributes      AttributeDescriptionList }
+                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();
@@ -284,5 +427,55 @@
         Assert.assertEquals( 1000, sr.getSizeLimit() );
         Assert.assertEquals( 1000, sr.getTimeLimit() );
         Assert.assertEquals( true, sr.isTypesOnly() );
-    }*/
+        
+        // (& (...
+        AndFilter andFilter = (AndFilter)sr.getFilter();
+        Assert.assertNotNull(andFilter);
+        
+        ArrayList andFilters = andFilter.getAndFilter();
+        
+        // (& (| (...
+        Assert.assertEquals(2, andFilters.size());
+        OrFilter orFilter = (OrFilter)andFilters.get(0);
+        Assert.assertNotNull(orFilter);
+        
+        // (& (| (objectclass=*) (...
+        ArrayList orFilters = orFilter.getOrFilter();
+        Assert.assertEquals(2, orFilters.size());
+
+        PresentFilter presentFilter = (PresentFilter)orFilters.get(0);  
+        Assert.assertNotNull(presentFilter);
+        
+        Assert.assertEquals("objectclass", presentFilter.getAttributeDescription().toString());
+        
+        // (& (| (objectclass=*) (ou=*) ) (...
+        presentFilter = (PresentFilter)orFilters.get(1);  
+        Assert.assertNotNull(presentFilter);
+        
+        Assert.assertEquals("ou", presentFilter.getAttributeDescription().toString());
+        
+        // (& (| (objectclass=*) (ou=*) ) (! ...
+        NotFilter notFilter = (NotFilter)andFilters.get(1);
+        Assert.assertNotNull(notFilter);
+        
+        // (& (| (objectclass=*) (ou=*) ) (! (objectclass>=ttt) ) )
+        AttributeValueAssertionFilter greaterOrEqual = (AttributeValueAssertionFilter)notFilter.getNotFilter();
 
+        Assert.assertNotNull(greaterOrEqual);
+        
+        AttributeValueAssertion assertion = greaterOrEqual.getAssertion();
+        Assert.assertNotNull(assertion);
+        
+        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());
+        }
+    }
 }



Mime
View raw message