directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20643 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap test/org/apache/snickers/ldap/testutils
Date Sun, 30 May 2004 06:35:29 GMT
Author: akarasulu
Date: Sat May 29 23:35:28 2004
New Revision: 20643

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/LdapDigesterFactory.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindRequestTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteRequestRuleTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/testutils/RuleTestCase.java
Log:
Commit changes ...

 o finished off the RuleTestCase abstract class
 o moved all rule additions to digester in test cases to the digester factory
 o made all rules extend the RuleTestCase base
 o cleaned up and removed ugly old stuff across tests



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
Sat May 29 23:35:28 2004
@@ -24,6 +24,6 @@
  *         Project</a>
  * @version $Rev$
  */
-public class CompareRequestRule 
+public class CompareRequestRule
 {
 }

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
Sat May 29 23:35:28 2004
@@ -17,7 +17,10 @@
 package org.apache.snickers.ldap ;
 
 
-import org.apache.snickers.ber.digester.BERDigester;
+import org.apache.snickers.ber.digester.BERDigester ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
+import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
 
 
 /**
@@ -34,12 +37,247 @@
  */
 public class LdapDigesterFactory
 {
+    /** static singleton singleton */
+    private static LdapDigesterFactory singleton ;
+
+
+    /**
+     * Private default (only) constructor which is only called once to create
+     * the singleton.
+     */
+    private LdapDigesterFactory()
+    {
+        singleton = this ;
+    }
+
+
+    /**
+     * Gets a handle on the singleton factory instance.
+     *
+     * @return the singlton instance for the ldap digester factory
+     */
+    public static LdapDigesterFactory getSingleton()
+    {
+        if ( singleton == null )
+        {
+            singleton = new LdapDigesterFactory() ;
+        }
+
+        return singleton ;
+    }
+
+
+    /**
+     * Creates and populates the BERDigester with rules to process all LDAPv3
+     * message types.
+     *
+     * @return a digester that can process all LDAPv3 PDU types
+     */
     public BERDigester create()
     {
         BERDigester digester = new BERDigester() ;
 
-        
+        addAbandonRequestRules( digester ) ;
+        addUnbindRequestRules( digester ) ;
+        addBindRequestRules( digester ) ;
+        addBindResponseRules( digester ) ;
+        addCompareRequestRules( digester ) ;
+        addCompareResponseRules( digester ) ;
+        addDeleteRequestRules( digester ) ;
+        addDeleteResponseRules( digester ) ;
 
         return digester ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Delete responses.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addDeleteResponseRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x02000000 ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+
+        // for the DeleteResponse and the LdapResult
+        pattern[1] = 0x4b000000 ;
+        digester.addRule( pattern, new DeleteResponseRule() ) ;
+
+        pattern = new int[3] ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x4b000000 ;
+
+        // for the resultCode
+        pattern[2] = 0x0a000000 ;
+        digester.addRule( pattern, new ResultCodeRule() ) ;
+
+        // for matchedDN and errorMessage
+        pattern[2] = 0x04000000 ;
+        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
+        digester.addRule( pattern, new ErrorMessageRule() ) ;
+
+        // for referral
+        pattern[2] = 0x83000000 ;
+        digester.addRule( pattern, new ReferralRule() ) ;
+
+        // for LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = 0x10000000 ;
+        pattern[1] = 0x4b000000 ;
+        pattern[2] = 0x83000000 ;
+        pattern[3] = 0x04000000 ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Delete requests.
+     *
+     * @param digester the digester to add the rules to
+     */
+    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() ;
+        digester.addRule( pattern, new DeleteRequestRule() ) ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Compare requests.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addCompareRequestRules( BERDigester digester )
+    {
+
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Compare responses.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addCompareResponseRules( BERDigester digester )
+    {
+
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Bind Responses.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addBindResponseRules( BERDigester digester )
+    {
+        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[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
+        digester.addRule( pattern, new BindResponseRule() ) ;
+
+        // modify pattern and addRule for the BindResponse
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
+
+        // for the resultCode
+        pattern[2] = UniversalTag.ENUMERATED.getPrimitiveTag() ;
+
+        // for matchedDN and errorMessage
+        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
+        digester.addRule( pattern, new ErrorMessageRule() ) ;
+
+        // for referral
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralRule() ) ;
+
+        // for serverSaslCreds
+        pattern[2] = LdapTag.SERVER_SASL_CREDS_TAG.getPrimitiveTag() ;
+        digester.addRule( pattern, new PrimitiveOctetStringRule(
+                LdapTag.SERVER_SASL_CREDS_TAG ) ) ;
+
+        // for LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
+        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Bind requests.
+     *
+     * @todo implement sasl based binds as well - for now its only simple auth
+     * @param digester the digester to add the rules to
+     */
+    private void addBindRequestRules( BERDigester digester )
+    {
+        int[] msgIdPat = { 0x10000000, 0x02000000 } ;
+        digester.addRule( msgIdPat, new PrimitiveIntDecodeRule() ) ;
+
+        int[] reqPat = { 0x10000000, 0x40000000 } ;
+        digester.addRule( reqPat, new BindRequestRule() ) ;
+
+        int[] versionPat = { 0x10000000, 0x40000000, 0x02000000 } ;
+        digester.addRule( versionPat, new BindVersionRule() ) ;
+
+        int[] namePat = { 0x10000000, 0x40000000, 0x04000000 } ;
+        digester.addRule( namePat, new BindNameRule() ) ;
+
+        int[] credPat = { 0x10000000, 0x40000000, 0x80000000 } ;
+        digester.addRule( credPat, new BindSimpleCredentialsRule() ) ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Unbind requests.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addUnbindRequestRules( 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.UNBIND_REQUEST.getValue() ;
+        digester.addRule( pattern, new UnbindRequestRule() ) ;
+    }
+
+
+    /**
+     * Adds digester rules for processing LDAPv3 Abandon requests.
+     *
+     * @param digester the digester to add the rules to
+     */
+    private void addAbandonRequestRules( 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.ABANDON_REQUEST.getValue() ;
+        digester.addRule( pattern, new AbandonRequestRule() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AbandonRequestRuleTest.java
Sat May 29 23:35:28 2004
@@ -17,30 +17,21 @@
 package org.apache.snickers.ldap ;
 
 
-import java.nio.ByteBuffer ;
-
-import junit.framework.TestCase ;
-
-import org.apache.ldap.common.message.MessageEncoder ;
 import org.apache.ldap.common.message.AbandonRequest ;
 import org.apache.ldap.common.message.AbandonRequestImpl ;
 
-import org.apache.snickers.ber.TupleTreeDecoder ;
-import org.apache.snickers.ber.digester.BERDigester ;
-import org.apache.snickers.ber.DefaultMutableTupleNode ;
-import org.apache.snickers.ber.primitives.UniversalTag ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-
-import org.apache.commons.codec.stateful.CallbackHistory ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
 
 
 /**
  * Test case used to test the BER Digester with the AbandonRequestRule.
  * 
- * @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 AbandonRequestRuleTest extends TestCase
+public class AbandonRequestRuleTest extends RuleTestCase
 {
     /**
      * Creates an AbandonRequest for testing.
@@ -49,62 +40,16 @@
      * @param abandonedId the id of the request to abandon
      * @return the newly constructed AbandonRequest
      */
-    public AbandonRequest build( int id, int abandonedId )
+    public AbandonRequest build( int id, int abandonedId ) throws Exception
     {
         AbandonRequest req = new AbandonRequestImpl( id ) ;
         req.setAbandoned( abandonedId ) ;
+        System.out.println( "Generated AbandonRequest for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( req ) ) ;
         return req ;
     }
 
 
-    public ByteBuffer snaccEncode( AbandonRequest req )
-    {
-        ByteBuffer buf = null ;
-
-        MessageEncoder encoder = new MessageEncoder( ) ;
-        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-
-        return buf ;
-    }
-
-
-    public AbandonRequest snickersDecode( ByteBuffer buf ) throws Exception
-    {
-        AbandonRequest req = null ;
-
-        // build the digester
-        BERDigester digester = new BERDigester() ;
-        CallbackHistory history = new CallbackHistory() ;
-        digester.setCallback( history ) ;
-
-        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() ) ;
-        digester.decode( buf ) ;
-        req = ( AbandonRequest ) history.getMostRecent() ;
-
-        return req ;
-    }
-
-
-    /** bogus just print out the nesting tree of an AbandonRequest */
-    public void testAbandonRequestOutput() throws Exception
-    {
-        ByteBuffer buf = snaccEncode( build( 44, 11 ) ) ;
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory history = new CallbackHistory() ;
-        decoder.setCallback( history ) ;
-        decoder.decode( buf ) ;
-        DefaultMutableTupleNode node =
-                ( DefaultMutableTupleNode ) history.getMostRecent() ;
-        System.out.println( node.toDepthFirstString() ) ;
-    }
-
-
     /**
      * Tests the ability to decode an AbandonRequest with Snickers'
      * BERDigester.
@@ -112,7 +57,8 @@
     public void testAbandonRequest() throws Exception
     {
         AbandonRequest req = build( 44, 11 ) ;
-        AbandonRequest decoded = snickersDecode( snaccEncode( req ) ) ;
+        AbandonRequest decoded = ( AbandonRequest )
+                snickersDecode( snaccEncode( req ) ) ;
         assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
         assertEquals( req.getAbandoned(), decoded.getAbandoned() ) ;
     }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindRequestTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindRequestTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindRequestTest.java
Sat May 29 23:35:28 2004
@@ -17,64 +17,21 @@
 package org.apache.snickers.ldap ;
 
 
-import junit.framework.TestCase ;
-
-import org.apache.commons.codec.stateful.CallbackHistory ;
-
 import org.apache.ldap.common.message.BindRequest ;
-import org.apache.ldap.common.message.MessageEncoder ;
 import org.apache.ldap.common.message.BindRequestImpl ;
-
-import org.apache.snickers.ber.digester.BERDigester ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-
-import java.nio.ByteBuffer ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+import org.apache.snickers.ldap.testutils.TestUtils;
 
 
 /**
  * Tests the capability to end to end decode a BindRequest.
  * 
- * @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 BindRequestTest extends TestCase
+public class BindRequestTest extends RuleTestCase
 {
-    BERDigester digester ;
-    CallbackHistory history = new CallbackHistory() ;
-
-
-    protected void setUp() throws Exception
-    {
-        super.setUp() ;
-
-        digester = new BERDigester() ;
-        digester.setCallback( history ) ;
-
-        int[] msgIdPat = { 0x10000000, 0x02000000 } ;
-        digester.addRule( msgIdPat, new PrimitiveIntDecodeRule() ) ;
-
-        int[] reqPat = { 0x10000000, 0x40000000 } ;
-        digester.addRule( reqPat, new BindRequestRule() ) ;
-
-        int[] versionPat = { 0x10000000, 0x40000000, 0x02000000 } ;
-        digester.addRule( versionPat, new BindVersionRule() ) ;
-
-        int[] namePat = { 0x10000000, 0x40000000, 0x04000000 } ;
-        digester.addRule( namePat, new BindNameRule() ) ;
-
-        int[] credPat = { 0x10000000, 0x40000000, 0x80000000 } ;
-        digester.addRule( credPat, new BindSimpleCredentialsRule() ) ;
-    }
-
-
-    protected void tearDown() throws Exception
-    {
-        super.tearDown() ;
-        digester = null ;
-        history = null ;
-    }
-
-
     /**
      * Tests a simple bind request decode.
      */
@@ -85,15 +42,16 @@
         req.setName( "uid=akarasulu,dc=example,dc=com" ) ;
         req.setSimple( true ) ;
         req.setVersion3( false ) ;
-        MessageEncoder encoder = new MessageEncoder() ;
-        ByteBuffer buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-        digester.decode( buf ) ;
-        BindRequest decoded = ( BindRequest ) digester.getRoot() ;
+        System.out.println( "Generated BindRequest for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( req ) ) ;
+
+
+        BindRequest decoded = ( BindRequest )
+                snickersDecode( snaccEncode( req ) ) ;
         assertNotNull( decoded ) ;
         assertTrue( "hello".equals( new String( decoded.getCredentials() ) ) ) ;
         assertEquals( "uid=akarasulu,dc=example,dc=com", decoded.getName() ) ;
         assertFalse( decoded.getVersion3() ) ;
         assertTrue( decoded.getSimple() ) ;
-        assertSame( decoded, history.getMostRecent() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
Sat May 29 23:35:28 2004
@@ -28,6 +28,8 @@
 import org.apache.snickers.ber.primitives.UniversalTag;
 import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
 import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule ;
+import org.apache.snickers.ldap.testutils.RuleTestCase;
+import org.apache.snickers.ldap.testutils.TestUtils;
 
 import org.apache.ldap.common.message.* ;
 import org.apache.commons.codec.stateful.CallbackHistory ;
@@ -39,30 +41,9 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindResponseRuleTest extends TestCase
+public class BindResponseRuleTest extends RuleTestCase
 {
-    BERDigester digester ;
-    CallbackHistory history ;
-
-
-    protected void setUp() throws Exception
-    {
-        super.setUp() ;
-        digester = new BERDigester() ;
-        history = new CallbackHistory() ;
-        digester.setCallback( history ) ;
-    }
-
-
-    protected void tearDown() throws Exception
-    {
-        super.tearDown() ;
-        digester = null ;
-        history = null ;
-    }
-
-
-    public void testBindResponseOutput() throws Exception
+    public void testBindResponse() throws Exception
     {
         // build the PDU
         BindResponseImpl resp = new BindResponseImpl( 540 ) ;
@@ -76,91 +57,13 @@
         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() ) ;
-    }
-
-
-    public void testBindResponse() throws Exception
-    {
-        int[] pattern = new int[2] ;
+        System.out.println( "Generated BindResponse for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
 
 
-        // -------------------------------------------
-        // 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[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
-        digester.addRule( pattern, new BindResponseRule() ) ;
-
-
-        // -----------------------------------------------
-        // modify pattern and addRule for the BindResponse
-        // -----------------------------------------------
-        pattern = new int[3] ;
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
-        pattern[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
-
-        // for the resultCode
-        pattern[2] = UniversalTag.ENUMERATED.getPrimitiveTag() ;
-
-        // for matchedDN and errorMessage
-        pattern[2] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
-        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
-        digester.addRule( pattern, new ErrorMessageRule() ) ;
-
-        // for referral
-        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
-        digester.addRule( pattern, new ReferralRule() ) ;
-
-        // for serverSaslCreds
-        pattern[2] = LdapTag.SERVER_SASL_CREDS_TAG.getPrimitiveTag() ;
-        TagEnum tag = new TagEnum( "ServerSaslCreds", 0x87000000, 7 ) {} ;
-        digester.addRule( pattern, new PrimitiveOctetStringRule( tag ) ) ;
-
-        // for LDAPURLs of referral
-        pattern = new int[4] ;
-        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
-        pattern[1] = LdapTag.BIND_RESPONSE.getPrimitiveTag() ;
-        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
-        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
-        digester.addRule( pattern, new ReferralUrlRule() ) ;
-
-        // 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 ) ;
-        digester.decode( buf ) ;
+        BindResponse decoded = ( BindResponse )
+                snickersDecode( snaccEncode( resp ) ) ;
 
-        BindResponse decoded = ( BindResponse ) history.getMostRecent() ;
         assertNotNull( decoded ) ;
         assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
         assertNotNull( decoded.getServerSaslCreds() ) ;

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteRequestRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteRequestRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteRequestRuleTest.java
Sat May 29 23:35:28 2004
@@ -17,19 +17,11 @@
 package org.apache.snickers.ldap ;
 
 
-import java.nio.ByteBuffer ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
 
-import junit.framework.TestCase ;
-
-import org.apache.ldap.common.message.*;
-
-import org.apache.snickers.ber.TupleTreeDecoder ;
-import org.apache.snickers.ber.digester.BERDigester ;
-import org.apache.snickers.ber.DefaultMutableTupleNode ;
-import org.apache.snickers.ber.primitives.UniversalTag ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-
-import org.apache.commons.codec.stateful.CallbackHistory ;
+import org.apache.ldap.common.message.DeleteRequest ;
+import org.apache.ldap.common.message.DeleteRequestImpl ;
 
 
 /**
@@ -38,7 +30,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class DeleteRequestRuleTest extends TestCase
+public class DeleteRequestRuleTest extends RuleTestCase
 {
     /**
      * Creates an DeleteRequest for testing.
@@ -47,63 +39,16 @@
      * @param name the name of the entry to delete
      * @return the newly constructed DelRequest
      */
-    public DeleteRequest build( int id, String name )
+    public DeleteRequest build( int id, String name ) throws Exception
     {
         DeleteRequest req = new DeleteRequestImpl( id ) ;
         req.setName( name ) ;
+        System.out.println( "Generated DeleteRequest for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( req ) ) ;
         return req ;
     }
 
 
-    public ByteBuffer snaccEncode( DeleteRequest req )
-    {
-        ByteBuffer buf = null ;
-
-        MessageEncoder encoder = new MessageEncoder( ) ;
-        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-
-        return buf ;
-    }
-
-
-    public DeleteRequest snickersDecode( ByteBuffer buf ) throws Exception
-    {
-        DeleteRequest req = null ;
-
-        // build the digester
-        BERDigester digester = new BERDigester() ;
-        CallbackHistory history = new CallbackHistory() ;
-        digester.setCallback( history ) ;
-
-        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() ;
-        digester.addRule( pattern, new DeleteRequestRule() ) ;
-        digester.decode( buf ) ;
-        req = ( DeleteRequest ) history.getMostRecent() ;
-
-        return req ;
-    }
-
-
-    /** bogus just print out the nesting tree of an DelRequest */
-    public void testDelRequestOutput() throws Exception
-    {
-        ByteBuffer buf = snaccEncode( build( 44,
-                "uid=akarasulu,dc=example,dc=com" ) ) ;
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory history = new CallbackHistory() ;
-        decoder.setCallback( history ) ;
-        decoder.decode( buf ) ;
-        DefaultMutableTupleNode node =
-                ( DefaultMutableTupleNode ) history.getMostRecent() ;
-        System.out.println( node.toDepthFirstString() ) ;
-    }
-
-
     /**
      * Tests the ability to decode an DelRequest with Snickers'
      * BERDigester.
@@ -111,7 +56,8 @@
     public void testDelRequest() throws Exception
     {
         DeleteRequest req = build( 44, "uid=akarasulu,dc=example,dc=com" ) ;
-        DeleteRequest decoded = snickersDecode( snaccEncode( req ) ) ;
+        DeleteRequest decoded = ( DeleteRequest )
+                snickersDecode( snaccEncode( req ) ) ;
         assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
         assertEquals( req.getName(), decoded.getName() ) ;
     }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
Sat May 29 23:35:28 2004
@@ -17,20 +17,12 @@
 package org.apache.snickers.ldap ;
 
 
-import java.nio.ByteBuffer ;
-import java.util.Iterator;
-
-import junit.framework.TestCase ;
+import java.util.Iterator ;
 
 import org.apache.ldap.common.message.* ;
 
-import org.apache.snickers.ber.TupleTreeDecoder ;
-import org.apache.snickers.ber.digester.BERDigester ;
-import org.apache.snickers.ber.DefaultMutableTupleNode ;
-import org.apache.snickers.ber.primitives.UniversalTag ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-
-import org.apache.commons.codec.stateful.CallbackHistory ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
 
 
 /**
@@ -39,127 +31,33 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev: 10096 $
  */
-public class DeleteResponseRuleTest extends TestCase
+public class DeleteResponseRuleTest extends RuleTestCase
 {
     /**
-     * Creates an DeleteResponse for testing.
-     *
-     * @param id the message Id of the DeleteResponse
-     * @return the newly constructed DeleteResponse
-     */
-    public DeleteResponse build( int id )
-    {
-        DeleteResponse req = new DeleteResponseImpl( id ) ;
-        LdapResult result = new LdapResultImpl( req ) ;
-        req.setLdapResult( result ) ;
-        result.setReferral( new ReferralImpl( result ) ) ;
-        return req ;
-    }
-
-
-    public ByteBuffer snaccEncode( DeleteResponse req )
-    {
-        ByteBuffer buf = null ;
-
-        MessageEncoder encoder = new MessageEncoder( ) ;
-        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-
-        return buf ;
-    }
-
-
-    public DeleteResponse snickersDecode( ByteBuffer buf ) throws Exception
-    {
-        DeleteResponse resp = null ;
-
-        // build the digester
-        BERDigester digester = new BERDigester() ;
-        CallbackHistory history = new CallbackHistory() ;
-        digester.setCallback( history ) ;
-
-        int[] pattern = new int[2] ;
-
-        pattern[0] = 0x10000000 ;
-        pattern[1] = 0x02000000 ;
-        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
-
-        // for the DeleteResponse and the LdapResult
-        pattern[1] = 0x4b000000 ;
-        digester.addRule( pattern, new DeleteResponseRule() ) ;
-
-        pattern = new int[3] ;
-        pattern[0] = 0x10000000 ;
-        pattern[1] = 0x4b000000 ;
-
-        // for the resultCode
-        pattern[2] = 0x0a000000 ;
-        digester.addRule( pattern, new ResultCodeRule() ) ;
-
-        // for matchedDN and errorMessage
-        pattern[2] = 0x04000000 ;
-        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
-        digester.addRule( pattern, new ErrorMessageRule() ) ;
-
-        // for referral
-        pattern[2] = 0x83000000 ;
-        digester.addRule( pattern, new ReferralRule() ) ;
-
-        // for LDAPURLs of referral
-        pattern = new int[4] ;
-        pattern[0] = 0x10000000 ;
-        pattern[1] = 0x4b000000 ;
-        pattern[2] = 0x83000000 ;
-        pattern[3] = 0x04000000 ;
-        digester.addRule( pattern, new ReferralUrlRule() ) ;
-
-        CallbackHistory cb = new CallbackHistory() ;
-        digester.setCallback( cb ) ;
-        digester.decode( buf ) ;
-        resp = ( DeleteResponse ) cb.getMostRecent() ;
-
-        return resp ;
-    }
-
-
-    /** bogus just print out the nesting tree of an DelResponse */
-    public void testDelResponseOutput() throws Exception
-    {
-        DeleteResponse resp = build( 44 ) ;
-        LdapResult result = resp.getLdapResult() ;
-        result.setErrorMessage( "testing123" ) ;
-        result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
-        result.setResultCode( ResultCodeEnum.BUSY ) ;
-        result.getReferral().addLdapUrl( "hello" ) ;
-        result.getReferral().addLdapUrl( "world" ) ;
-        ByteBuffer buf = snaccEncode( resp ) ;
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory history = new CallbackHistory() ;
-        decoder.setCallback( history ) ;
-        decoder.decode( buf ) ;
-        DefaultMutableTupleNode node =
-                ( DefaultMutableTupleNode ) history.getMostRecent() ;
-        System.out.println( node.toDepthFirstString() ) ;
-    }
-
-
-    /**
      * Tests the ability to decode an DelResponse with Snickers'
      * BERDigester.
      */
     public void testDelResponse() throws Exception
     {
-        DeleteResponse resp = build( 44 ) ;
-        LdapResult result = resp.getLdapResult() ;
+        DeleteResponse resp = new DeleteResponseImpl( 44 ) ;
+        LdapResult result = new LdapResultImpl( resp ) ;
+        resp.setLdapResult( result ) ;
+        result.setReferral( new ReferralImpl( result ) ) ;
         result.setErrorMessage( "An Error Message!" ) ;
         result.setMatchedDn( "uid=akarasulu,dc=example,dc=com" ) ;
         result.setResultCode( ResultCodeEnum.BUSY ) ;
         result.getReferral().addLdapUrl( "hello" ) ;
         result.getReferral().addLdapUrl( "world" ) ;
-        DeleteResponse decoded = snickersDecode( snaccEncode( resp ) ) ;
+        System.out.println( "Generated DeleteResponse for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        DeleteResponse decoded = ( DeleteResponse )
+                snickersDecode( snaccEncode( resp ) ) ;
         LdapResult decodedResult = decoded.getLdapResult() ;
 
         assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
-        assertEquals( result.getErrorMessage(), decodedResult.getErrorMessage() ) ;
+        assertEquals( result.getErrorMessage(),
+                decodedResult.getErrorMessage() ) ;
         assertEquals( result.getMatchedDn(), decodedResult.getMatchedDn() ) ;
         assertEquals( result.getResultCode(), decodedResult.getResultCode() ) ;
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/UnbindRequestRuleTest.java
Sat May 29 23:35:28 2004
@@ -17,19 +17,11 @@
 package org.apache.snickers.ldap ;
 
 
-import java.nio.ByteBuffer ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
 
-import junit.framework.TestCase ;
-
-import org.apache.ldap.common.message.*;
-
-import org.apache.snickers.ber.TupleTreeDecoder ;
-import org.apache.snickers.ber.digester.BERDigester ;
-import org.apache.snickers.ber.DefaultMutableTupleNode ;
-import org.apache.snickers.ber.primitives.UniversalTag ;
-import org.apache.snickers.ber.digester.rules.PrimitiveIntDecodeRule ;
-
-import org.apache.commons.codec.stateful.CallbackHistory ;
+import org.apache.ldap.common.message.UnbindRequest ;
+import org.apache.ldap.common.message.UnbindRequestImpl ;
 
 
 /**
@@ -38,69 +30,25 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class UnbindRequestRuleTest extends TestCase
+public class UnbindRequestRuleTest extends RuleTestCase
 {
     /**
-     * Creates an UnbindRequest for testing.
+     * Builds an UnbindRequest for testing.
      *
-     * @param id the message Id of the UnbindRequest
-     * @return the newly constructed UnbindRequest
+     * @param id the messageId of the request
+     * @return the newly built UnbindRequest
+     * @throws Exception if there are failures creating the request
      */
-    public UnbindRequest build( int id )
+    public UnbindRequest build( int id ) throws Exception
     {
         UnbindRequest req = new UnbindRequestImpl( id ) ;
-        return req ;
-    }
-
-
-    public ByteBuffer snaccEncode( UnbindRequest req )
-    {
-        ByteBuffer buf = null ;
-
-        MessageEncoder encoder = new MessageEncoder( ) ;
-        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-
-        return buf ;
-    }
-
-
-    public UnbindRequest snickersDecode( ByteBuffer buf ) throws Exception
-    {
-        UnbindRequest req = null ;
-
-        // build the digester
-        BERDigester digester = new BERDigester() ;
-        CallbackHistory history = new CallbackHistory() ;
-        digester.setCallback( history ) ;
-
-        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() ) ;
-        digester.decode( buf ) ;
-        req = ( UnbindRequest ) history.getMostRecent() ;
 
+        System.out.println( "Generated UnbindRequest for testing:" ) ;
+        System.out.println( TestUtils.printTupleTree( req ) ) ;
         return req ;
     }
 
 
-    /** bogus just print out the nesting tree of an UnbindRequest */
-    public void testUnbindRequestOutput() throws Exception
-    {
-        ByteBuffer buf = snaccEncode( build( 44 ) ) ;
-        TupleTreeDecoder decoder = new TupleTreeDecoder() ;
-        CallbackHistory history = new CallbackHistory() ;
-        decoder.setCallback( history ) ;
-        decoder.decode( buf ) ;
-        DefaultMutableTupleNode node =
-                ( DefaultMutableTupleNode ) history.getMostRecent() ;
-        System.out.println( node.toDepthFirstString() ) ;
-    }
-
-
     /**
      * Tests the ability to decode an UnbindRequest with Snickers'
      * BERDigester.
@@ -108,7 +56,8 @@
     public void testUnbindRequest() throws Exception
     {
         UnbindRequest req = build( 44 ) ;
-        UnbindRequest decoded = snickersDecode( snaccEncode( req ) ) ;
+        UnbindRequest decoded = ( UnbindRequest )
+                snickersDecode( snaccEncode( req ) ) ;
         assertEquals( req.getMessageId(), decoded.getMessageId() ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/testutils/RuleTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/testutils/RuleTestCase.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/testutils/RuleTestCase.java
Sat May 29 23:35:28 2004
@@ -21,6 +21,11 @@
 
 import junit.framework.TestCase ;
 import org.apache.ldap.common.message.Message ;
+import org.apache.ldap.common.message.UnbindRequest;
+import org.apache.ldap.common.message.MessageEncoder;
+import org.apache.snickers.ber.digester.BERDigester;
+import org.apache.snickers.ldap.LdapDigesterFactory;
+import org.apache.commons.codec.stateful.CallbackHistory;
 
 
 /**
@@ -32,5 +37,45 @@
  */
 public abstract class RuleTestCase extends TestCase
 {
-    protected abstract Message getTestMessage( Object[] args ) ;
+    private BERDigester digester ;
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        digester = null ;
+    }
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp() ;
+        digester = LdapDigesterFactory.getSingleton().create() ;
+    }
+
+
+    protected BERDigester getDigester()
+    {
+        return digester ;
+    }
+
+
+    public Message snickersDecode( ByteBuffer buf ) throws Exception
+    {
+        CallbackHistory history = new CallbackHistory() ;
+        getDigester().setCallback( history ) ;
+        getDigester().decode( buf ) ;
+        return ( Message ) history.getMostRecent() ;
+    }
+
+
+    public ByteBuffer snaccEncode( Message req )
+    {
+        ByteBuffer buf = null ;
+
+        MessageEncoder encoder = new MessageEncoder( ) ;
+        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
+
+        return buf ;
+    }
 }

Mime
View raw message