directory-commits mailing list archives

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

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

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java
Sun May 30 17:20:46 2004
@@ -17,9 +17,6 @@
 package org.apache.snickers.ldap ;
 
 
-import org.apache.snickers.ber.TypeClass;
-
-
 /**
  * A digester rule which fires to build AddResponse containment trees.
  * 
@@ -29,18 +26,6 @@
  */
 public class AddResponseRule extends ResultResponseRule
 {
-    public void tag( int id, boolean isPrimitive, TypeClass typeClass )
-    {
-        super.tag( id, isPrimitive, typeClass );    //To change body of overridden methods
use File | Settings | File Templates.
-    }
-
-
-    public void finish()
-    {
-        super.finish();    //To change body of overridden methods use File | Settings | File
Templates.
-    }
-
-
     /**
      * Creates a digester rule which fires to build AddResponse containment
      * trees.

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 17:20:46 2004
@@ -91,11 +91,48 @@
         addExtendedResponseRules( digester ) ;
         addModifyDnRequestRules( digester ) ;
         addModifyDnResponseRules( digester ) ;
+        addModifyResponseRules( digester ) ;
 
         return digester ;
     }
 
 
+    private void addModifyResponseRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        // modify pattern and addRule for the ModifyResponse
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.MODIFY_RESPONSE.getPrimitiveTag() ;
+        digester.addRule( pattern, new ModifyResponseRule() ) ;
+
+        // modify pattern and addRule for the ModifyResponse
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.MODIFY_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 LDAPURLs of referral
+        pattern = new int[4] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.MODIFY_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 Add responses.
      *
@@ -110,7 +147,7 @@
         pattern[1] = LdapTag.ADD_RESPONSE.getPrimitiveTag() ;
         digester.addRule( pattern, new AddResponseRule() ) ;
 
-        // modify pattern and addRule for the ModifyDnResponse
+        // modify pattern and addRule for the AddResponse
         pattern = new int[3] ;
         pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
         pattern[1] = LdapTag.ADD_RESPONSE.getPrimitiveTag() ;

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ModifyResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/ModifyResponseRule.java
Sun May 30 17:20:46 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 ;
+
+
+/**
+ * A digester rule which fires to build ModifyResponse containment trees.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ModifyResponseRule extends ResultResponseRule
+{
+    /**
+     * Creates a digester rule which fires to build AddResponse containment
+     * trees.
+     */
+    public ModifyResponseRule()
+    {
+        super( LdapTag.MODIFY_RESPONSE ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ModifyResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/ModifyResponseRuleTest.java
Sun May 30 17:20:46 2004
@@ -0,0 +1,77 @@
+/*
+ *   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.snickers.ldap.testutils.TestUtils ;
+import org.apache.snickers.ldap.testutils.RuleTestCase ;
+
+import org.apache.ldap.common.message.* ;
+import org.apache.commons.lang.ArrayUtils ;
+
+
+/**
+ * Tests the population of an LdapResult using a ResultRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ModifyResponseRuleTest extends RuleTestCase
+{
+    public void testModifyResponse() throws Exception
+    {
+        // build the PDU
+        ModifyResponseImpl resp = new ModifyResponseImpl( 8 ) ;
+        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 ) ;
+        System.out.println( "Generated ModifyResponse for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        ModifyResponse decoded = ( ModifyResponse )
+                snickersDecode( snaccEncode( resp ) ) ;
+
+        assertNotNull( decoded ) ;
+        assertEquals( resp.getMessageId(), decoded.getMessageId() ) ;
+        LdapResult decodedResult = resp.getLdapResult() ;
+        assertEquals( result.getResultCode(), decodedResult.getResultCode() ) ;
+        assertEquals( result.getErrorMessage(),
+                decodedResult.getErrorMessage() ) ;
+        assertEquals( result.getMatchedDn(),
+                decodedResult.getMatchedDn() ) ;
+        Referral decodedRef = 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() ) ;
+    }
+}
\ No newline at end of file

Mime
View raw message