You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2004/05/30 10:13:04 UTC

svn commit: rev 20645 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap

Author: akarasulu
Date: Sun May 30 01:13:03 2004
New Revision: 20645

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareResponseRule.java   (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareResponseRuleTest.java   (contents, props changed)
Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/LdapDigesterFactory.java
Log:
finished and tested the compare response rules

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/CompareResponseRule.java	Sun May 30 01:13:03 2004
@@ -0,0 +1,41 @@
+/*
+ *   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;
+
+
+/**
+ * A digester rule used to build a CompareResponse PDU.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class CompareResponseRule extends ResultResponseRule
+{
+    /**
+     * Creates digester rule used to build a CompareResponse PDU.
+     */
+    public CompareResponseRule()
+    {
+        super( LdapTag.COMPARE_RESPONSE ) ;
+    }
+}

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 01:13:03 2004
@@ -133,14 +133,14 @@
         digester.addRule( pattern, new ErrorMessageRule() ) ;
 
         // for referral
-        pattern[2] = 0x83000000 ;
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
         digester.addRule( pattern, new ReferralRule() ) ;
 
         // for LDAPURLs of referral
         pattern = new int[4] ;
         pattern[0] = 0x10000000 ;
         pattern[1] = 0x4b000000 ;
-        pattern[2] = 0x83000000 ;
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
         pattern[3] = 0x04000000 ;
         digester.addRule( pattern, new ReferralUrlRule() ) ;
     }
@@ -201,7 +201,32 @@
         // 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() ) ;
+        digester.addRule( pattern, new CompareResponseRule() ) ;
+
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_RESPONSE.getPrimitiveTag() ;
+
+        // for the resultCode
+        pattern[2] = 0x0a000000 ;
+        digester.addRule( pattern, new ResultCodeRule() ) ;
+
+        // 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 LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.COMPARE_RESPONSE.getPrimitiveTag() ;
+        pattern[2] = LdapTag.REFERRAL_TAG.getPrimitiveTag() ;
+        pattern[3] = UniversalTag.OCTET_STRING.getPrimitiveTag() ;
+        digester.addRule( pattern, new ReferralUrlRule() ) ;
     }
 
 

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/CompareResponseRuleTest.java	Sun May 30 01:13:03 2004
@@ -0,0 +1,74 @@
+/*
+ *   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.util.Iterator;
+
+import org.apache.ldap.common.message.* ;
+import org.apache.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+
+
+/**
+ * Document this class.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class CompareResponseRuleTest extends RuleTestCase
+{
+    public void testCompareRequest() throws Exception
+    {
+        // build the PDU
+        CompareResponseImpl resp = new CompareResponseImpl( 7 ) ;
+        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" ) ;
+        System.out.println( "Generated CompareResponse for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        CompareResponse decoded = ( CompareResponse )
+                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() ) ;
+    }
+}