directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r191278 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/SearchRequestTest.java
Date Sat, 18 Jun 2005 11:44:40 GMT
Author: elecharny
Date: Sat Jun 18 04:44:40 2005
New Revision: 191278

URL: http://svn.apache.org/viewcvs?rev=191278&view=rev
Log:
Added a test on Extensible match.

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=191278&r1=191277&r2=191278&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
Sat Jun 18 04:44:40 2005
@@ -25,12 +25,12 @@
 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;
 import org.apache.asn1.ldap.pojo.filters.OrFilter;
 import org.apache.asn1.ldap.pojo.filters.PresentFilter;
+import org.apache.asn1.ldap.pojo.filters.SubstringFilter;
 import org.apache.asn1.util.MutableString;
 import org.apache.log4j.Logger;
 import org.apache.log4j.PropertyConfigurator;
@@ -1237,6 +1237,190 @@
         Assert.assertEquals("t", ((MutableString)substringFilter.getAnySubstrings().get(2)).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());
+        }
+    }
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testDecodeSearchRequestOrFilters()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x96 );
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0xFFFFFF81, 0xFFFFFF93, 
+                	0x02, 0x01, 0x21, 
+                	0x63, 0xFFFFFF81, 0xFFFFFF8D, // "dc=example,dc=com"
+                		0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65,
0x2C, 0x64, 0x63, 0x3D, 0x63, 0x6F, 0x6D, 
+                		0x0A, 0x01, 0x00, 
+                		0x0A, 0x01, 0x02, 
+                		0x02, 0x01, 0x02, 
+                		0x02, 0x01, 0x03, 
+                		0x01, 0x01, 0xFFFFFFFF, 
+                		0xFFFFFFA1, 0x52, 								// ( | 
+                			0xFFFFFFA3, 0x10, 							// ( uid=akarasulu )
+                				0x04, 0x03, 0x75, 0x69, 0x64, 			
+                				0x04, 0x09, 0x61, 0x6B, 0x61, 0x72, 0x61, 0x73, 0x75, 0x6C, 0x75, 
+                			0xFFFFFFA3, 0x09, 							// ( cn=aok )
+                				0x04, 0x02, 0x63, 0x6E, 
+                				0x04, 0x03, 0x61, 0x6F, 0x6B, 
+                			0xFFFFFFA3, 0x15, 							// ( ou = Human Resources )
+                				0x04, 0x02, 0x6F, 0x75, 
+                				0x04, 0x0F, 0x48, 0x75, 0x6D, 0x61, 0x6E, 0x20, 0x52, 0x65, 0x73, 0x6F,
0x75, 0x72, 0x63, 0x65, 0x73, 
+                			0xFFFFFFA3, 0x10, 
+                				0x04, 0x01, 0x6C, 						// ( l=Santa Clara )
+                				0x04, 0x0B, 0x53, 0x61, 0x6E, 0x74, 0x61, 0x20, 0x43, 0x6C, 0x61, 0x72,
0x61, 
+                			0xFFFFFFA3, 0x0A, 							// ( cn=abok )
+                				0x04, 0x02, 0x63, 0x6E, 
+                				0x04, 0x04, 0x61, 0x62, 0x6F, 0x6B, 
+                		0x30, 0x15,										// Attributes 
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30, 	// attr0
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 	// attr1
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32	// attr2
+            } );
+
+        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( 33, message.getMessageId() );
+        Assert.assertEquals( "dc=example,dc=com", sr.getBaseObject().toString() );
+        Assert.assertEquals( LdapConstants.SCOPE_BASE_OBJECT, sr.getScope() );
+        Assert.assertEquals( LdapConstants.DEREF_FINDING_BASE_OBJ, sr.getDerefAliases() );
+        Assert.assertEquals( 2, sr.getSizeLimit() );
+        Assert.assertEquals( 3, sr.getTimeLimit() );
+        Assert.assertEquals( true, sr.isTypesOnly() );
+        
+        // (objectclass=t*)
+        OrFilter orFilter = (OrFilter)sr.getFilter();
+        Assert.assertNotNull(orFilter);
+
+        // uid=akarasulu
+        AttributeValueAssertion assertion = ((AttributeValueAssertionFilter)orFilter.getOrFilter().get(0)).getAssertion();
+        
+        Assert.assertEquals("uid", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[61][6B][61][72][61][73][75][6C][75]", assertion.getAssertionValue().toString());
+
+        // cn=aok
+        assertion = ((AttributeValueAssertionFilter)orFilter.getOrFilter().get(1)).getAssertion();
+        
+        Assert.assertEquals("cn", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[61][6F][6B]", assertion.getAssertionValue().toString());
+
+        // ou = Human Resources
+        assertion = ((AttributeValueAssertionFilter)orFilter.getOrFilter().get(2)).getAssertion();
+        
+        Assert.assertEquals("ou", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[48][75][6D][61][6E][20][52][65][73][6F][75][72][63][65][73]",
assertion.getAssertionValue().toString());
+
+        // l=Santa Clara
+        assertion = ((AttributeValueAssertionFilter)orFilter.getOrFilter().get(3)).getAssertion();
+        
+        Assert.assertEquals("l", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[53][61][6E][74][61][20][43][6C][61][72][61]", assertion.getAssertionValue().toString());
+
+        // cn=abok
+        assertion = ((AttributeValueAssertionFilter)orFilter.getOrFilter().get(4)).getAssertion();
+        
+        Assert.assertEquals("cn", assertion.getAttributeDesc().toString());
+        Assert.assertEquals("[61][62][6F][6B]", 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());
+        }
+    }
+
+    /**
+     * Tests an search request decode with a simple equality match filter.
+     */
+    public void testDecodeSearchRequestExtensibleMatch()
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x75 );
+        stream.put(
+            new byte[]
+            {
+                    0x30, 0x73, 
+                	0x02, 0x01, 0x01, 
+                	0x63, 0x6E, // "dc=example,dc=com"
+                		0x04, 0x11, 0x64, 0x63, 0x3D, 0x65, 0x78, 0x61, 0x6D, 0x70, 0x6C, 0x65,
0x2C, 0x64, 0x63, 0x3D, 0x63, 0x6F, 0x6D, 
+                		0x0A, 0x01, 0x00, 
+                		0x0A, 0x01, 0x02, 
+                		0x02, 0x01, 0x02, 
+                		0x02, 0x01, 0x03, 
+                		0x01, 0x01, (byte)0xFF,
+                		(byte)0xA9, 0x23,
+                			0x30, 0x21,
+                				(byte)0x81, 0x02, 'c', 'n',
+                				(byte)0x82, 0x13, '1', '.', '2', '.', '8', '4', '0',   
+                								  '.', '4', '8', '0', '1', '8', '.',  
+                								  '1', '.', '2', '.', '2',
+                	            (byte)0x83, 0x03, 'a', 'o', 'k',
+                	            (byte)0x84, 0x01, (byte)0xFF,
+                		0x30, 0x15,										// Attributes 
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x30, 	// attr0
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x31, 	// attr1
+                			0x04, 0x05, 0x61, 0x74, 0x74, 0x72, 0x32	// attr2
+            } );
+
+        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( "dc=example,dc=com", sr.getBaseObject().toString() );
+        Assert.assertEquals( LdapConstants.SCOPE_BASE_OBJECT, sr.getScope() );
+        Assert.assertEquals( LdapConstants.DEREF_FINDING_BASE_OBJ, sr.getDerefAliases() );
+        Assert.assertEquals( 2, sr.getSizeLimit() );
+        Assert.assertEquals( 3, sr.getTimeLimit() );
+        Assert.assertEquals( true, sr.isTypesOnly() );
+        
         // The attributes
         ArrayList attributes = sr.getAttributes();
         



Mime
View raw message