directory-commits mailing list archives

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

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java
      - copied, changed from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultCodeRule.java
      - copied, changed from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java
      - copied, changed from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
Removed:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/BindResponseRuleTest.java
Log:
Commit changes ...

o moved a few of the bind specific classes to be result response specific so
  they can be reused for other messages that carry an LDAPResult in the 
  response
o added the delete response rule and a unit test case which is currently broken



Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResponseRule.java
Mon Apr 19 00:02:30 2004
@@ -14,38 +14,24 @@
  *   limitations under the License.
  *
  */
-package org.apache.snickers.ldap ;
+package org.apache.snickers.ldap;
 
+import org.apache.ldap.common.message.BindResponse;
 
-import java.nio.ByteBuffer ;
-
-import org.apache.snickers.ber.TypeClass ;
-import org.apache.snickers.ber.digester.AbstractRule ;
-
-import org.apache.ldap.common.message.BindResponse ;
-import org.apache.ldap.common.message.BindResponseImpl ;
-import org.apache.ldap.common.message.LdapResultImpl;
+import java.nio.ByteBuffer;
 
 
 /**
- * A rule that creates, pushes and pops a BindRequest.
+ * Put some documentation here.
  * 
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindResponseRule extends AbstractRule
+public class BindResponseRule extends ResultResponseRule
 {
-    /* (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 )
+    public BindResponseRule()
     {
-        super.tag( id, isPrimitive, typeClass ) ;
-        BindResponse resp = new BindResponseImpl( getDigester().popInt() ) ;
-        LdapResultImpl result = new LdapResultImpl( resp ) ;
-        resp.setLdapResult( result ) ;
-        getDigester().push( resp ) ;
+        super( LdapTag.BIND_RESPONSE ) ;
     }
 
 
@@ -54,16 +40,12 @@
      */
     public void finish()
     {
-        BindResponse resp = null ;
+        super.finish() ;
 
-        if ( getDigester().peek() instanceof BindResponse )
-        {
-            resp = ( BindResponse ) getDigester().pop() ;
-        }
-        else
+        if ( getDigester().peek() instanceof ByteBuffer )
         {
             ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
-            resp = ( BindResponse ) getDigester().pop() ;
+            BindResponse resp = ( BindResponse ) getDigester().pop() ;
             resp.setServerSaslCreds( BufferUtils.getArray( buf ) ) ;
         }
     }

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/DeleteResponseRule.java
Mon Apr 19 00:02:30 2004
@@ -0,0 +1,37 @@
+/*
+ *   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 org.apache.ldap.common.message.DeleteResponse ;
+import org.apache.snickers.ber.TypeClass;
+
+import java.nio.ByteBuffer;
+
+
+/**
+ * Put some documentation here.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class DeleteResponseRule extends ResultResponseRule
+{
+    public DeleteResponseRule()
+    {
+        super( LdapTag.DEL_RESPONSE ) ;
+    }
+}

Copied: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java
(from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java)
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindErrorMessageRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ErrorMessageRule.java
Mon Apr 19 00:02:30 2004
@@ -18,6 +18,7 @@
 
 import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
 import org.apache.ldap.common.message.BindResponse;
+import org.apache.ldap.common.message.ResultResponse;
 
 import java.nio.ByteBuffer;
 
@@ -28,7 +29,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindErrorMessageRule extends PrimitiveOctetStringRule
+public class ErrorMessageRule extends PrimitiveOctetStringRule
 {
     /* (non-Javadoc)
     * @see org.apache.snickers.ber.Rule#finish()
@@ -39,7 +40,7 @@
 
         ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
         String errorMsg = new String( BufferUtils.getArray( buf ) ) ;
-        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
         resp.getLdapResult().setErrorMessage( errorMsg ) ;
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapTag.java
Mon Apr 19 00:02:30 2004
@@ -23,6 +23,7 @@
 import java.util.List ;
 
 import org.apache.snickers.ber.TagEnum ;
+import org.apache.ldap.common.message.*;
 
 
 /**
@@ -415,6 +416,87 @@
                 }
 
                 throw new IllegalArgumentException( msg ) ;
+        }
+
+        return type ;
+    }
+
+
+    /**
+     * Factory method used to create a skeletal message instance.
+     *
+     * @param messageId the message id to use for the message
+     * @return the newly created skeletal mesage instance
+     */
+    public Message create( int messageId )
+    {
+        Message type = null ;
+
+        switch ( this.getTagId() )
+        {
+            case( BIND_REQUEST_ID ):
+                type = new BindRequestImpl( messageId ) ;
+                break ;
+            case( BIND_RESPONSE_ID ):
+                type = new BindResponseImpl( messageId ) ;
+                break ;
+            case( UNBIND_REQUEST_ID ):
+                type = new UnbindRequestImpl( messageId ) ;
+                break ;
+            case( SEARCH_REQUEST_ID ):
+                type = new SearchRequestImpl( messageId ) ;
+                break ;
+            case( SEARCH_RESULT_ENTRY_ID ):
+                type = new SearchResponseEntryImpl( messageId ) ;
+                break ;
+            case( SEARCH_RESULT_DONE_ID ):
+                type = new SearchResponseDoneImpl( messageId ) ;
+                break ;
+            case( SEARCH_RESULT_REFERENCE_ID ):
+                type = new SearchResponseReferenceImpl( messageId ) ;
+                break ;
+            case( MODIFY_REQUEST_ID ):
+                type = new ModifyRequestImpl( messageId ) ;
+                break ;
+            case( MODIFY_RESPONSE_ID ):
+                type = new ModifyResponseImpl( messageId ) ;
+                break ;
+            case( ADD_REQUEST_ID ):
+                type = new AddRequestImpl( messageId ) ;
+                break ;
+            case( ADD_RESPONSE_ID ):
+                type = new AddResponseImpl( messageId ) ;
+                break ;
+            case( DEL_REQUEST_ID ):
+                type = new DeleteRequestImpl( messageId ) ;
+                break ;
+            case( DEL_RESPONSE_ID ):
+                type = new DeleteResponseImpl( messageId ) ;
+                break ;
+            case( MODIFYDN_REQUEST_ID ):
+                type = new ModifyDnRequestImpl( messageId ) ;
+                break ;
+            case( MODIFYDN_RESPONSE_ID ):
+                type = new ModifyDnResponseImpl( messageId ) ;
+                break ;
+            case( COMPARE_REQUEST_ID ):
+                type = new CompareRequestImpl( messageId ) ;
+                break ;
+            case( COMPARE_RESPONSE_ID ):
+                type = new CompareResponseImpl( messageId ) ;
+                break ;
+            case( ABANDON_REQUEST_ID ):
+                type = new AbandonRequestImpl( messageId ) ;
+                break ;
+            case( EXTENDED_REQUEST_ID ):
+                type = new ExtendedRequestImpl( messageId ) ;
+                break ;
+            case( EXTENDED_RESPONSE_ID ):
+                type = new ExtendedResponseImpl( messageId ) ;
+                break ;
+            default:
+                throw new IllegalStateException(
+                        "should not happen - if it does we have issues" ) ;
         }
 
         return type ;

Copied: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultCodeRule.java
(from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java)
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindResultCodeRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultCodeRule.java
Mon Apr 19 00:02:30 2004
@@ -19,6 +19,7 @@
 
 import org.apache.ldap.common.message.BindResponse ;
 import org.apache.ldap.common.message.ResultCodeEnum;
+import org.apache.ldap.common.message.ResultResponse;
 
 import org.apache.snickers.ber.digester.rules.PrimitiveEnumDecodeRule ;
 
@@ -29,7 +30,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindResultCodeRule extends PrimitiveEnumDecodeRule
+public class ResultCodeRule extends PrimitiveEnumDecodeRule
 {
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.digester.Rule#finish()
@@ -40,7 +41,7 @@
 
         int val = getDigester().popInt() ;
         ResultCodeEnum resultCode = ResultCodeEnum.getResultCodeEnum( val ) ;
-        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
         resp.getLdapResult().setResultCode( resultCode ) ;
     }
 }

Copied: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java
(from rev 10091, incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java)
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/BindMatchedDNRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultMatchedDNRule.java
Mon Apr 19 00:02:30 2004
@@ -18,6 +18,7 @@
 
 import org.apache.snickers.ber.digester.rules.PrimitiveOctetStringRule;
 import org.apache.ldap.common.message.BindResponse;
+import org.apache.ldap.common.message.ResultResponse;
 
 import java.nio.ByteBuffer;
 
@@ -28,7 +29,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class BindMatchedDNRule extends PrimitiveOctetStringRule
+public class ResultMatchedDNRule extends PrimitiveOctetStringRule
 {
     /* (non-Javadoc)
      * @see org.apache.snickers.ber.Rule#finish()
@@ -39,7 +40,7 @@
 
         ByteBuffer buf = ( ByteBuffer ) getDigester().pop() ;
         String dn = new String( BufferUtils.getArray( buf ) ) ;
-        BindResponse resp = ( BindResponse ) getDigester().peek() ;
+        ResultResponse resp = ( ResultResponse ) getDigester().peek() ;
         resp.getLdapResult().setMatchedDn( dn ) ;
     }
 }

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ResultResponseRule.java
Mon Apr 19 00:02:30 2004
@@ -0,0 +1,69 @@
+/*
+ *   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 org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.AbstractRule ;
+
+import org.apache.ldap.common.message.LdapResultImpl ;
+import org.apache.ldap.common.message.ResultResponse ;
+
+
+/**
+ * A rule that creates, pushes and pops a ResultRequest.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev: 10091 $
+ */
+public class ResultResponseRule extends AbstractRule
+{
+    private final LdapTag tag ;
+
+
+    ResultResponseRule( LdapTag tag )
+    {
+        this.tag = tag ;
+    }
+
+
+    /* (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 )
+    {
+        super.tag( id, isPrimitive, typeClass ) ;
+        ResultResponse resp = ( ResultResponse ) tag.create(
+                getDigester().popInt() ) ;
+        LdapResultImpl result = new LdapResultImpl( resp ) ;
+        resp.setLdapResult( result ) ;
+        getDigester().push( resp ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        if ( getDigester().peek() instanceof ResultResponse )
+        {
+            getDigester().pop() ;
+        }
+    }
+}

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
Mon Apr 19 00:02:30 2004
@@ -108,12 +108,12 @@
 
         // for the resultCode
         pattern[2] = 0x0a000000 ;
-        digester.addRule( pattern, new BindResultCodeRule() ) ;
+        digester.addRule( pattern, new ResultCodeRule() ) ;
 
         // for matchedDN and errorMessage
         pattern[2] = 0x04000000 ;
-        digester.addRule( pattern, new BindMatchedDNRule() ) ;
-        digester.addRule( pattern, new BindErrorMessageRule() ) ;
+        digester.addRule( pattern, new ResultMatchedDNRule() ) ;
+        digester.addRule( pattern, new ErrorMessageRule() ) ;
 
         // for referral
         pattern[2] = 0x83000000 ;

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/DeleteResponseRuleTest.java
Mon Apr 19 00:02:30 2004
@@ -0,0 +1,179 @@
+/*
+ *   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 java.util.Iterator;
+
+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 ;
+
+
+/**
+ * Test case used to test the BER Digester with the DeleteResponseRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev: 10096 $
+ */
+public class DeleteResponseRuleTest extends TestCase
+{
+    /**
+     * 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] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
+        pattern[1] = UniversalTag.INTEGER.getValue() ;
+        digester.addRule( pattern, new PrimitiveIntDecodeRule() ) ;
+
+        // for the DeleteResponse and the LdapResult
+        pattern[1] = LdapTag.DEL_RESPONSE.getValue() ;
+        digester.addRule( pattern, new DeleteResponseRule() ) ;
+
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getValue() ;
+        pattern[1] = LdapTag.DEL_RESPONSE.getValue() ;
+
+        // 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] = LdapTag.DEL_RESPONSE.getValue() ;
+        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() ;
+        result.setErrorMessage( "testing123" ) ;
+        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 ) ) ;
+        LdapResult decodedResult = decoded.getLdapResult() ;
+
+        assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
+        assertEquals( result.getErrorMessage(), decodedResult.getErrorMessage() ) ;
+        assertEquals( result.getMatchedDn(), decodedResult.getMatchedDn() ) ;
+        assertEquals( result.getResultCode(), decodedResult.getResultCode() ) ;
+
+        Referral decodedRef = decodedResult.getReferral() ;
+        Referral referral = result.getReferral() ;
+        Iterator urls = referral.getLdapUrls().iterator() ;
+        Iterator decodedUrls = decodedRef.getLdapUrls().iterator() ;
+
+        while( urls.hasNext() && decodedUrls.hasNext() )
+        {
+            assertEquals( urls.next(), decodedUrls.next() ) ;
+        }
+
+        assertFalse( urls.hasNext() ) ;
+        assertFalse( decodedUrls.hasNext() ) ;
+    }
+}

Mime
View raw message