directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20669 - 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:30:07 GMT
Author: akarasulu
Date: Sun May 30 17:30:06 2004
New Revision: 20669

Added:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseDoneRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseDoneRuleTest.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 search result done pdu rules

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:30:06 2004
@@ -92,8 +92,45 @@
         addModifyDnRequestRules( digester ) ;
         addModifyDnResponseRules( digester ) ;
         addModifyResponseRules( digester ) ;
+        addSearchResponseDoneRules( digester ) ;
 
         return digester ;
+    }
+
+
+    private void addSearchResponseDoneRules( BERDigester digester )
+    {
+        int[] pattern = new int[2] ;
+
+        // modify pattern and addRule for the SearchResponseDone
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_RESULT_DONE.getPrimitiveTag() ;
+        digester.addRule( pattern, new SearchResponseDoneRule() ) ;
+
+        // modify pattern and addRule for the SearchResponseDone
+        pattern = new int[3] ;
+        pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+        pattern[1] = LdapTag.SEARCH_RESULT_DONE.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.SEARCH_RESULT_DONE.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/java/org/apache/snickers/ldap/SearchResponseDoneRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SearchResponseDoneRule.java
Sun May 30 17:30:06 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 SearchResponseDone containment trees.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class SearchResponseDoneRule extends ResultResponseRule
+{
+    /**
+     * Creates a digester rule which fires to build SearchResponseDone
+     * containment trees.
+     */
+    public SearchResponseDoneRule()
+    {
+        super( LdapTag.SEARCH_RESULT_DONE ) ;
+    }
+}

Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseDoneRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SearchResponseDoneRuleTest.java
Sun May 30 17:30:06 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 SearchResponseDoneRuleTest extends RuleTestCase
+{
+    public void testAddResponse() throws Exception
+    {
+        // build the PDU
+        SearchResponseDone resp = new SearchResponseDoneImpl( 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 SearchResultDone for test:" ) ;
+        System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+        SearchResponseDone decoded = ( SearchResponseDone )
+                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