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/31 02:11:37 UTC
svn commit: rev 20667 - 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 17:11:36 2004
New Revision: 20667
Added:
incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java (contents, props changed)
incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AddResponseRuleTest.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 add response rules
Added: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/AddResponseRule.java Sun May 30 17:11:36 2004
@@ -0,0 +1,52 @@
+/*
+ * 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;
+
+
+/**
+ * A digester rule which fires to build AddResponse containment trees.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+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.
+ */
+ public AddResponseRule()
+ {
+ super( LdapTag.ADD_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 17:11:36 2004
@@ -79,6 +79,7 @@
addMessageIdRules( digester ) ;
addAbandonRequestRules( digester ) ;
+ addAddResponseRules( digester ) ;
addUnbindRequestRules( digester ) ;
addBindRequestRules( digester ) ;
addBindResponseRules( digester ) ;
@@ -92,6 +93,47 @@
addModifyDnResponseRules( digester ) ;
return digester ;
+ }
+
+
+ /**
+ * Adds digester rules for processing LDAPv3 Add responses.
+ *
+ * @param digester the digester to add the rules to
+ */
+ private void addAddResponseRules( BERDigester digester )
+ {
+ int[] pattern = new int[2] ;
+
+ // modify pattern and addRule for the AddResponse
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.ADD_RESPONSE.getPrimitiveTag() ;
+ digester.addRule( pattern, new AddResponseRule() ) ;
+
+ // modify pattern and addRule for the ModifyDnResponse
+ pattern = new int[3] ;
+ pattern[0] = UniversalTag.SEQUENCE_SEQUENCE_OF.getPrimitiveTag() ;
+ pattern[1] = LdapTag.ADD_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.ADD_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/AddResponseRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/AddResponseRuleTest.java Sun May 30 17:11:36 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 AddResponseRuleTest extends RuleTestCase
+{
+ public void testAddResponse() throws Exception
+ {
+ // build the PDU
+ AddResponseImpl resp = new AddResponseImpl( 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 AddResponse for test:" ) ;
+ System.out.println( TestUtils.printTupleTree( resp ) ) ;
+
+ AddResponse decoded = ( AddResponse )
+ 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