directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20644 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap
Date Sun, 30 May 2004 07:53:16 GMT
Author: akarasulu
Date: Sun May 30 00:53:16 2004
New Revision: 20644

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareAVARule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareEntryRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareRequestRuleTest.java
      - copied, changed from rev 20627, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRuleTest.java
Removed:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRuleTest.java
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteRequestRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Log:
finished and tested the compare request rules

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareAVARule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareAVARule.java
Sun May 30 00:53:16 2004
@@ -0,0 +1,80 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.CompareRequest ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * A BERDigester rule to set the AVA variables of the CompareRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class CompareAVARule extends PrimitiveOctetStringRule
+{
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at the CompareRequest underneath whose name we set
+        CompareRequest req = ( CompareRequest ) getDigester().peek() ;
+
+        byte[] octets = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            octets = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            octets = new byte[buf.remaining()] ;
+            buf.get( octets ) ;
+        }
+
+        if ( req.getAttributeId() == null )
+        {
+            req.setAttributeId( new String( octets ) ) ;
+        }
+        else
+        {
+            req.setAssertionValue( new String( octets ) ) ;
+        }
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareEntryRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareEntryRule.java
Sun May 30 00:53:16 2004
@@ -0,0 +1,73 @@
+/*
+ *   Copyright 2004 The Apache Software Foundation
+ *
+ *   Licensed under the Apache License, Version 2.0 (the "License");
+ *   you may not use this file except in compliance with the License.
+ *   You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *   Unless required by applicable law or agreed to in writing, software
+ *   distributed under the License is distributed on an "AS IS" BASIS,
+ *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *   See the License for the specific language governing permissions and
+ *   limitations under the License.
+ *
+ */
+package org.apache.snickers.ldap ;
+
+
+import java.nio.ByteBuffer ;
+
+import org.apache.ldap.common.message.CompareRequest ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+
+
+/**
+ * A BERDigester rule to set the entry DN of the CompareRequest's entry field.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class CompareEntryRule extends PrimitiveOctetStringRule
+{
+    /**
+     * Allows the super method to push a ByteBuffer onto the top of the stack
+     * which contains the drained contents of the superclass' ByteAccumulator.
+     * This ByteBuffer is popped first then used to populate the credentials.
+     * There is no need to copy this buffer since it will not be used again
+     * by the ByteAccumulator of the superclass so we should be able to use
+     * the byte[] based backing store if one is present.  However it might
+     * have to be copied even then.  Situations requiring a copy are when the
+     * buffer has a limit less than the capacity or when there is no
+     * accessible array to the buffer.
+     *
+     * @see org.apache.snickers.ber.digester.Rule#finish()
+     */
+    public void finish()
+    {
+        // pushes a ByteBuffer onto the stack
+        super.finish() ;
+
+        // pop the ByteBuffer the super method pushed
+        ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
+        // peek at the CompareRequest underneath whose name we set
+        CompareRequest req = ( CompareRequest ) getDigester().peek() ;
+
+        byte[] name = null ;
+        if ( buf.limit() == buf.capacity() && buf.hasArray() )
+        {
+            // use the backing store
+            name = buf.array() ;
+        }
+        else
+        {
+            // copy because we don't have accessible array or data < array
+            name = new byte[buf.remaining()] ;
+            buf.get( name ) ;
+        }
+
+        req.setName( new String( name ) ) ;
+    }
+}

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRule.java
Sun May 30 00:53:16 2004
@@ -17,13 +17,46 @@
 package org.apache.snickers.ldap ;
 
 
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+import org.apache.ldap.common.message.CompareRequestImpl ;
+
+
 /**
- * Document this class.
+ * Digester rule that instantiates CompareRequest objects and pushes them onto
+ * the object stack to be populated.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
  *         Project</a>
  * @version $Rev$
  */
-public class CompareRequestRule
+public class CompareRequestRule extends AbstractRule
 {
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#tag(int, boolean,
+     * org.apache.snickers.ber.TypeClass)
+     */
+    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
+    {
+        LdapTag tag = LdapTag.getLdapTagById( id ) ;
+
+        if ( LdapTag.COMPARE_REQUEST != tag )
+        {
+            throw new IllegalArgumentException( "Expected a CompareRequest tag "
+                + "id but got a " + tag ) ;
+        }
+
+        CompareRequestImpl req = new
+                CompareRequestImpl( getDigester().popInt() ) ;
+        getDigester().push( req ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        getDigester().pop() ;
+    }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteRequestRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteRequestRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteRequestRule.java
Sun May 30 00:53:16 2004
@@ -17,22 +17,20 @@
 package org.apache.snickers.ldap ;
 
 
-import org.apache.ldap.common.message.AbandonRequest ;
-import org.apache.ldap.common.message.AbandonRequestImpl ;
-import org.apache.ldap.common.message.DeleteRequestImpl;
-import org.apache.ldap.common.message.DeleteRequest;
+import org.apache.ldap.common.message.DeleteRequest ;
+import org.apache.ldap.common.message.DeleteRequestImpl ;
 
 import org.apache.snickers.ber.TypeClass ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
 
-import java.nio.ByteBuffer;
+import java.nio.ByteBuffer ;
 
 
 /**
  * A rule that creates an DeleteRequest and populates it.
  * 
- * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
  * @version $Rev$
  */
 public class DeleteRequestRule extends PrimitiveOctetStringRule

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Sun May 30 00:53:16 2004
@@ -77,6 +77,7 @@
     {
         BERDigester digester = new BERDigester() ;
 
+        addMessageIdRules( digester ) ;
         addAbandonRequestRules( digester ) ;
         addUnbindRequestRules( digester ) ;
         addBindRequestRules( digester ) ;
@@ -91,6 +92,20 @@
 
 
     /**
+     * Generic rules used to capture the messageId for the LDAP message.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addMessageIdRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
+        pattern[1] = UniversalTag.INTEGER.getValue() ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+    }
+
+
+    /**
      * Adds digester rules for processing LDAPv3 Delete responses.
      *
      * @param digester the digester to add the rules to
@@ -99,11 +114,8 @@
     {
         int[] pattern = new int[2] ;
 
-        pattern[0] = 0x10000000 ;
-        pattern[1] = 0x02000000 ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
-
         // for the DeleteResponse and the LdapResult
+        pattern[0] = 0x10000000 ;
         pattern[1] = 0x4b000000 ;
         digester.addRule( pattern, new DeleteResponseRule() ) ;
 
@@ -142,11 +154,10 @@
     private void addDeleteRequestRules( BERDigester digester )
     {
         int[] pattern = new int[2] ;
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
-        pattern[1] = UniversalTag.INTEGER.getValue() ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
 
-        pattern[1] = LdapTag.DEL_REQUEST.getValue() ;
+        // for the DeleteRequest and the LdapResult
+        pattern[0] = 0x10000000 ;
+        pattern[1] = LdapTag.DEL_REQUEST.getPrimitiveTag() ;
         digester.addRule( pattern, new DeleteRequestRule() ) ;
     }
 
@@ -158,7 +169,23 @@
      */
     private void addCompareRequestRules( BERDigester digester )
     {
+        int[] pattern = new int[2] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_REQUEST.getPrimitiveTag() ;
+        digester.addRule( pattern, new CompareRequestRule() ) ;
+
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_REQUEST.getPrimitiveTag() ;
+        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new CompareEntryRule() ) ;
 
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_REQUEST.getPrimitiveTag() ;
+        pattern[2] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new CompareAVARule() ) ;
     }
 
 
@@ -169,7 +196,12 @@
      */
     private void addCompareResponseRules( BERDigester digester )
     {
+        int[] pattern = new int[2] ;
 
+        // modify pattern and addRule for the CompareResponse
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_RESPONSE.getPrimitiveTag() ;
+        // digester.addRule( pattern, new CompareResponseRule() ) ;
     }
 
 
@@ -182,12 +214,8 @@
     {
         int[] pattern = new int[2] ;
 
-        // build pattern and addRule for the messageId
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
-        pattern[1] = UniversalTag.INTEGER.getPrimitiveTag() ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
-
         // modify pattern and addRule for the BindResponse
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
         pattern[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
         digester.addRule( pattern, new BindResponseRule() ) ;
 
@@ -231,9 +259,6 @@
      */
     private void addBindRequestRules( BERDigester digester )
     {
-        int[] msgIdPat = { 0x10000000, 0x02000000 } ;
-        digester.addRule( msgIdPat, new PrimitiveIntDecodeRule() ) ;
-
         int[] reqPat = { 0x10000000, 0x40000000 } ;
         digester.addRule( reqPat, new BindRequestRule() ) ;
 
@@ -257,9 +282,6 @@
     {
         int[] pattern = new int[2] ;
         pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
-        pattern[1] = UniversalTag.INTEGER.getValue() ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
-
         pattern[1] = LdapTag.UNBIND_REQUEST.getValue() ;
         digester.addRule( pattern, new UnbindRequestRule() ) ;
     }
@@ -274,9 +296,6 @@
     {
         int[] pattern = new int[2] ;
         pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
-        pattern[1] = UniversalTag.INTEGER.getValue() ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
-
         pattern[1] = LdapTag.ABANDON_REQUEST.getValue() ;
         digester.addRule( pattern, new AbandonRequestRule() ) ;
     }

Copied: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareRequestRuleTest.java
(from rev 20627, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRuleTest.java)
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareRequestRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareRequestRuleTest.java
Sun May 30 00:53:16 2004
@@ -17,12 +17,9 @@
 package org.apache.snickers.ldap ;
 
 
-import java.nio.ByteBuffer ;
-
 import org.apache.ldap.common.message.* ;
-import org.apache.snickers.ber.TupleTreeDecoder ;
-import org.apache.snickers.ber.DefaultMutableTupleNode ;
-import org.apache.commons.codec.stateful.CallbackHistory ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
 
 
 /**
@@ -32,36 +29,23 @@
  *         Project</a>
  * @version $Rev$
  */
-public class CompareRequestRuleTest
+public class CompareRequestRuleTest extends RuleTestCase
 {
-
-    public void testBindResponseOutput() throws Exception
+    public void testCompareRequest() throws Exception
     {
         // build the PDU
-        BindResponseImpl resp = new BindResponseImpl( 540 ) ;
-        resp.setServerSaslCreds( "hello".getBytes() ) ;
-        LdapResultImpl result = new LdapResultImpl( resp ) ;
-        result.setResultCode( ResultCodeEnum.BUSY ) ;
-        result.setErrorMessage( "An Error Message!" ) ;
-        result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
-        ReferralImpl referral = new ReferralImpl( result ) ;
-        referral.addLdapUrl( "hello" ) ;
-        referral.addLdapUrl( "world" ) ;
-        result.setReferral( referral ) ;
-        resp.setLdapResult( result ) ;
-        MessageEncoder encoder = new MessageEncoder() ;
-        byte[] pdu = encoder.encode( resp ) ;
-        ByteBuffer buf = ByteBuffer.wrap( pdu ) ;
-
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory cb = new CallbackHistory() ;
-        decoder.setCallback( cb ) ;
-        decoder.decode( buf ) ;
-        DefaultMutableTupleNode node = ( DefaultMutableTupleNode ) cb.getMostRecent() ;
-        StringBuffer sb = new StringBuffer() ;
-        node.printDepthFirst( sb, 0 ) ;
-        System.out.println( sb.toString() ) ;
+        CompareRequestImpl req = new CompareRequestImpl( 7 ) ;
+        req.setAttributeId( "hello" ) ;
+        req.setAssertionValue( "world" ) ;
+        req.setName( "uid=akarasulu,dc=example,dc=com" ) ;
+        System.out.println( "Generated CompareRequest for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( req ) ) ;
+
+        CompareRequest decoded = ( CompareRequest )
+                snickersDecode( snaccEncode( req ) ) ;
+        assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
+        assertEquals( req.getName(), decoded.getName() ) ;
+        assertEquals( req.getAttributeId(), decoded.getAttributeId() ) ;
+        assertEquals( req.getAssertionValue(), decoded.getAssertionValue() ) ;
     }
-
-
 }

Mime
View raw message