directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r373025 - in /directory/trunks/common/ldap/src: main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java
Date Fri, 27 Jan 2006 23:19:22 GMT
Author: elecharny
Date: Fri Jan 27 15:19:13 2006
New Revision: 373025

URL: http://svn.apache.org/viewcvs?rev=373025&view=rev
Log:
- Added a pop transition
- Added a test

Modified:
    directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
    directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java

Modified: directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java?rev=373025&r1=373024&r2=373025&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
(original)
+++ directory/trunks/common/ldap/src/main/java/org/apache/ldap/common/codec/compare/CompareRequestGrammar.java
Fri Jan 27 15:19:13 2006
@@ -300,6 +300,9 @@
 
                         // We can have an END transition
                         ldapMessageContainer.grammarEndAllowed( true );
+
+                        // We can have an POP transition
+                        ldapMessageContainer.grammarPopAllowed( true );
                     }
                 } );
     }

Modified: directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java?rev=373025&r1=373024&r2=373025&view=diff
==============================================================================
--- directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java
(original)
+++ directory/trunks/common/ldap/src/test/java/org/apache/ldap/common/codec/compare/CompareRequestTest.java
Fri Jan 27 15:19:13 2006
@@ -17,6 +17,7 @@
 package org.apache.ldap.common.codec.compare;
 
 import java.nio.ByteBuffer;
+import java.util.List;
 
 import javax.naming.NamingException;
 
@@ -24,6 +25,7 @@
 import org.apache.asn1.codec.EncoderException;
 import org.apache.asn1.ber.Asn1Decoder;
 import org.apache.asn1.ber.IAsn1Container;
+import org.apache.ldap.common.codec.Control;
 import org.apache.ldap.common.codec.LdapDecoder;
 import org.apache.ldap.common.codec.LdapMessage;
 import org.apache.ldap.common.codec.LdapMessageContainer;
@@ -320,6 +322,92 @@
 
         // Check the length
         assertEquals(0x33, message.computeLength());
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = message.encode( null );
+            
+            String encodedPdu = StringTools.dumpBytes( bb.array() ); 
+            
+            assertEquals(encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    /**
+     * Test the decoding of an compare request with controls
+     */
+    public void testDecodeCompareRequestWithControls() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x55 );
+        
+        stream.put(
+            new byte[]
+            {
+                0x30, 0x53,         // LDAPMessage ::= SEQUENCE {
+                  0x02, 0x01, 0x01, //     messageID MessageID
+                                    //     CHOICE { ..., compareRequest   CompareRequest,
...
+                  0x6E, 0x31,       // CompareRequest ::= [APPLICATION 14] SEQUENCE {
+                                    //     entry           LDAPDN,
+                    0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f',
'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't',
'e', 'm',
+                                    //     ava             AttributeValueAssertion }
+                    0x30, 0x0D,     // AttributeValueAssertion ::= SEQUENCE {
+                                    //     attributeDesc   AttributeDescription,
+                      0x04, 0x04, 't', 'e', 's', 't',
+                                    //     assertionValue  AssertionValue }
+                      0x04, 0x05, 'v', 'a', 'l', 'u', 'e',
+                  (byte)0xA0, 0x1B,   // A control 
+                    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
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a LdapMessage Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        // Decode the CompareRequest PDU
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            fail( de.getMessage() );
+        }
+        
+        // Ceck the decoded CompareRequest PDU
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+        CompareRequest compareRequest      = message.getCompareRequest();
+
+        assertEquals( 1, message.getMessageId() );
+        assertEquals( "cn=testModify,ou=users,ou=system", compareRequest.getEntry() );
+        assertEquals( "test", compareRequest.getAttributeDesc() );
+        assertEquals( "value", compareRequest.getAssertionValue().toString() );
+
+        // Check the Control
+        List controls = message.getControls();
+        
+        assertEquals( 1, controls.size() );
+        
+        Control control = message.getControls( 0 );
+        assertEquals( "2.16.840.1.113730.3.4.2", control.getControlType() );
+        assertEquals( "", StringTools.dumpBytes( (byte[])control.getControlValue() ) );
+
+        // Check the length
+        assertEquals(0x55, message.computeLength());
 
         // Check the encoding
         try



Mime
View raw message