directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 10074 - in incubator/directory/snickers/trunk/provider: . src src/java src/java/org src/java/org/apache src/java/org/apache/snickers src/java/org/apache/snickers/ldap src/test src/test/org src/test/org/apache src/test/org/apache/snickers src/test/org/apache/snickers/ldap
Date Sun, 18 Apr 2004 01:45:45 GMT
Author: akarasulu
Date: Sat Apr 17 18:45:44 2004
New Revision: 10074

Added:
   incubator/directory/snickers/trunk/provider/   (props changed)
   incubator/directory/snickers/trunk/provider/src/
   incubator/directory/snickers/trunk/provider/src/java/
   incubator/directory/snickers/trunk/provider/src/java/org/
   incubator/directory/snickers/trunk/provider/src/java/org/apache/
   incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/
   incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/
   incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/BindRequestRule.java
  (contents, props changed)
   incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/LdapTag.java
  (contents, props changed)
   incubator/directory/snickers/trunk/provider/src/test/
   incubator/directory/snickers/trunk/provider/src/test/org/
   incubator/directory/snickers/trunk/provider/src/test/org/apache/
   incubator/directory/snickers/trunk/provider/src/test/org/apache/snickers/
   incubator/directory/snickers/trunk/provider/src/test/org/apache/snickers/ldap/
   incubator/directory/snickers/trunk/provider/src/test/org/apache/snickers/ldap/BindRequestRuleTest.java
  (contents, props changed)
Log:
o created new LDAP Message Provider project
o added a BindRequestRule and test case
o added LdapTag which is the type safe enumeration for LDAPv3 tags and ids 
  from RFC 2251 http://www.faqs.org/rfcs/rfc2251.html

TODO:
====
o need to move this to ldap-provider to be more descriptive
o provide a readme about the project's purpose within snickers
o may need to move a few things around
o add many more rules


Added: incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/BindRequestRule.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/BindRequestRule.java
Sat Apr 17 18:45:44 2004
@@ -0,0 +1,91 @@
+/*
+ *   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.snickers.ber.primitives.UniversalTag ;
+
+import org.apache.ldap.common.message.BindRequestImpl ;
+
+
+/**
+ * Creates an instance of an LDAP BindRequest bean using a message Id stored
+ * on the primitive integer stack.  As a side effect the integer is popped
+ * off of the stack and the BindRequest is pushed onto the Object stack.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindRequestRule extends AbstractRule
+{
+    /** the tag nesting pattern without the constructed bits */
+    private static final int[] NESTING_PATTERN = {
+        UniversalTag.SEQUENCE_SEQUENCE_OF_VAL, LdapTag.BIND_REQUEST_TAG
+    } ;
+
+
+    /**
+     * Gets the PDU Tag for a BindRequest message without the constructed bit.
+     *
+     * @return PDU Tag for a BindRequest message without the constructed bit
+     */
+    public static LdapTag getTag()
+    {
+        return LdapTag.BIND_REQUEST ;
+    }
+
+
+    /**
+     * Gets the nesting pattern for a BindRequest.
+     *
+     * @return the nesting pattern of tags for a bind request
+     */
+    public static int[] getNestingPattern()
+    {
+        return NESTING_PATTERN ;
+    }
+
+
+    /* (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 )
+    {
+        LdapTag tag = LdapTag.getLdapTagById( id ) ;
+
+        if ( LdapTag.BIND_REQUEST != tag )
+        {
+            throw new IllegalArgumentException( "Expected a BIND_REQUEST tag "
+                + "id but got a " + tag ) ;
+        }
+
+        BindRequestImpl req = new BindRequestImpl( getDigester().popInt() ) ;
+        getDigester().push( req ) ;
+    }
+
+
+    /* (non-Javadoc)
+     * @see org.apache.snickers.ber.Rule#finish()
+     */
+    public void finish()
+    {
+        getDigester().pop() ;
+    }
+}

Added: incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/LdapTag.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/provider/src/java/org/apache/snickers/ldap/LdapTag.java
Sat Apr 17 18:45:44 2004
@@ -0,0 +1,437 @@
+/*
+ *   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.commons.lang.enum.EnumUtils ;
+import org.apache.commons.lang.enum.ValuedEnum ;
+
+import java.util.Map ;
+import java.util.List ;
+
+
+/**
+ * Prefabricated LDAP tags encoded as integers.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LdapTag extends ValuedEnum
+{
+    /** the bind request tag encoded as an integer */
+    public static final int BIND_REQUEST_TAG = 0x60000000 ;
+    /** the bind response tag encoded as an integer */
+    public static final int BIND_RESPONSE_TAG = 0x61000000 ;
+
+    /** the unbind request tag encoded as an integer */
+    public static final int UNBIND_REQUEST_TAG = 0x42000000 ;
+
+    /** the search request tag encoded as an integer */
+    public static final int SEARCH_REQUEST_TAG = 0x63000000 ;
+    /** the search result entry response tag encoded as an integer */
+    public static final int SEARCH_RESULT_ENTRY_TAG = 0x64000000 ;
+    /** the search result done tag encoded as an integer */
+    public static final int SEARCH_RESULT_DONE_TAG = 0x65000000 ;
+    /** the search result reference response tag encoded as an integer */
+    public static final int SEARCH_RESULT_REFERENCE_TAG = 0x73000000 ;
+
+    /** the modify request tag encoded as an integer */
+    public static final int MODIFY_REQUEST_TAG = 0x66000000 ;
+    /** the modify response tag encoded as an integer */
+    public static final int MODIFY_RESPONSE_TAG = 0x67000000 ;
+
+    /** the add request tag encoded as an integer */
+    public static final int ADD_REQUEST_TAG = 0x68000000 ;
+    /** the add response tag encoded as an integer */
+    public static final int ADD_RESPONSE_TAG = 0x69000000 ;
+
+    /** the delete request tag encoded as an integer */
+    public static final int DEL_REQUEST_TAG = 0x4a000000 ;
+    /** the delete response tag encoded as an integer */
+    public static final int DEL_RESPONSE_TAG = 0x6b000000 ;
+
+    /** the modify dn request tag encoded as an integer */
+    public static final int MODIFYDN_REQUEST_TAG = 0x6c000000 ;
+    /** the modify dn response tag encoded as an integer */
+    public static final int MODIFYDN_RESPONSE_TAG = 0x6d000000 ;
+
+    /** the compare request tag encoded as an integer */
+    public static final int COMPARE_REQUEST_TAG = 0x6e000000 ;
+    /** the compare response tag encoded as an integer */
+    public static final int COMPARE_RESPONSE_TAG = 0x6f000000 ;
+
+    /** the abandon request tag encoded as an integer */
+    public static final int ABANDON_REQUEST_TAG = 0x50000000 ;
+
+    /** the extended request tag encoded as an integer */
+    public static final int EXTENDED_REQUEST_TAG = 0x77000000 ;
+    /** the extended response tag encoded as an integer */
+    public static final int EXTENDED_RESPONSE_TAG = 0x78000000 ;
+
+
+    // -----------------------------------------------------------------------
+    // Tag Identifiers
+    // -----------------------------------------------------------------------
+
+
+    /** the bind request id as an integer */
+    public static final int BIND_REQUEST_ID =               0 ;
+    /** the bind response id as an integer */
+    public static final int BIND_RESPONSE_ID =              1 ;
+
+    /** the unbind request id as an integer */
+    public static final int UNBIND_REQUEST_ID =             2 ;
+
+    /** the search request id as an integer */
+    public static final int SEARCH_REQUEST_ID =             3 ;
+    /** the search result entry response id as an integer */
+    public static final int SEARCH_RESULT_ENTRY_ID =        4 ;
+    /** the search result done id as an integer */
+    public static final int SEARCH_RESULT_DONE_ID =         5 ;
+    /** the search result reference response id as an integer */
+    public static final int SEARCH_RESULT_REFERENCE_ID =    19 ;
+
+    /** the modify request id as an integer */
+    public static final int MODIFY_REQUEST_ID =             6 ;
+    /** the modify response id as an integer */
+    public static final int MODIFY_RESPONSE_ID =            7 ;
+
+    /** the add request id as an integer */
+    public static final int ADD_REQUEST_ID =                8 ;
+    /** the add response id as an integer */
+    public static final int ADD_RESPONSE_ID =               9 ;
+
+    /** the delete request id as an integer */
+    public static final int DEL_REQUEST_ID =                10 ;
+    /** the delete response id as an integer */
+    public static final int DEL_RESPONSE_ID =               11 ;
+
+    /** the modify dn request id as an integer */
+    public static final int MODIFYDN_REQUEST_ID =           12 ;
+    /** the modify dn response id as an integer */
+    public static final int MODIFYDN_RESPONSE_ID =          13 ;
+
+    /** the compare request id as an integer */
+    public static final int COMPARE_REQUEST_ID =            14 ;
+    /** the compare response id as an integer */
+    public static final int COMPARE_RESPONSE_ID =           15 ;
+
+    /** the abandon request id as an integer */
+    public static final int ABANDON_REQUEST_ID =            16 ;
+
+    /** the extended request id as an integer */
+    public static final int EXTENDED_REQUEST_ID =           23 ;
+    /** the extended response id as an integer */
+    public static final int EXTENDED_RESPONSE_ID =          24 ;
+
+    
+    // -----------------------------------------------------------------------
+    // Enumerations
+    // -----------------------------------------------------------------------
+
+    
+    public static final LdapTag BIND_REQUEST = new LdapTag(
+            "BIND_REQUEST", BIND_REQUEST_TAG, BIND_REQUEST_ID ) ;
+    public static final LdapTag BIND_RESPONSE = new LdapTag(
+            "BIND_RESPONSE", BIND_RESPONSE_TAG, BIND_RESPONSE_ID ) ;
+
+    public static final LdapTag UNBIND_REQUEST = new LdapTag(
+            "UNBIND_REQUEST", UNBIND_REQUEST_TAG, UNBIND_REQUEST_ID ) ;
+
+    public static final LdapTag SEARCH_REQUEST = new LdapTag(
+            "SEARCH_REQUEST", SEARCH_REQUEST_TAG, SEARCH_REQUEST_ID ) ;
+    public static final LdapTag SEARCH_RESULT_DONE = new LdapTag(
+            "SEARCH_RESULT_DONE", SEARCH_RESULT_DONE_TAG,
+            SEARCH_RESULT_DONE_ID ) ;
+    public static final LdapTag SEARCH_RESULT_ENTRY = new LdapTag(
+            "SEARCH_RESULT_ENTRY", SEARCH_RESULT_ENTRY_TAG,
+            SEARCH_RESULT_ENTRY_ID ) ;
+    public static final LdapTag SEARCH_RESULT_REFERENCE = new LdapTag(
+            "SEARCH_RESULT_REFERENCE", SEARCH_RESULT_REFERENCE_TAG,
+            SEARCH_RESULT_REFERENCE_ID ) ;
+
+    public static final LdapTag MODIFY_REQUEST = new LdapTag(
+            "MODIFY_REQUEST", MODIFY_REQUEST_TAG, MODIFY_REQUEST_ID ) ;
+    public static final LdapTag MODIFY_RESPONSE = new LdapTag(
+            "MODIFY_RESPONSE", MODIFY_RESPONSE_TAG, MODIFY_RESPONSE_ID ) ;
+
+    public static final LdapTag ADD_REQUEST = new LdapTag(
+            "ADD_REQUEST", ADD_REQUEST_TAG, ADD_REQUEST_ID ) ;
+    public static final LdapTag ADD_RESPONSE = new LdapTag(
+            "ADD_RESPONSE", ADD_RESPONSE_TAG, ADD_RESPONSE_ID ) ;
+
+    public static final LdapTag DEL_REQUEST = new LdapTag(
+            "DEL_REQUEST", DEL_REQUEST_TAG, DEL_REQUEST_ID ) ;
+    public static final LdapTag DEL_RESPONSE = new LdapTag(
+            "DEL_RESPONSE", DEL_RESPONSE_TAG, DEL_RESPONSE_ID ) ;
+
+    public static final LdapTag MODIFYDN_REQUEST = new LdapTag(
+            "MODIFYDN_REQUEST", MODIFYDN_REQUEST_TAG, MODIFYDN_REQUEST_ID ) ;
+    public static final LdapTag MODIFYDN_RESPONSE = new LdapTag(
+            "MODIFYDN_RESPONSE", MODIFYDN_RESPONSE_TAG,
+            MODIFYDN_RESPONSE_ID ) ;
+
+    public static final LdapTag COMPARE_REQUEST = new LdapTag(
+            "COMPARE_REQUEST", COMPARE_REQUEST_TAG, COMPARE_REQUEST_ID ) ;
+    public static final LdapTag COMPARE_RESPONSE = new LdapTag(
+            "COMPARE_RESPONSE", COMPARE_RESPONSE_TAG, COMPARE_RESPONSE_ID ) ;
+
+    public static final LdapTag ABANDON_REQUEST = new LdapTag(
+            "ABANDON_REQUEST", ABANDON_REQUEST_TAG, ABANDON_REQUEST_ID ) ;
+
+    public static final LdapTag EXTENDED_REQUEST = new LdapTag(
+            "EXTENDED_REQUEST", EXTENDED_REQUEST_TAG, EXTENDED_REQUEST_ID ) ;
+    public static final LdapTag EXTENDED_RESPONSE = new LdapTag(
+            "EXTENDED_RESPONSE", EXTENDED_RESPONSE_TAG,
+            EXTENDED_RESPONSE_ID ) ;
+
+
+    // -----------------------------------------------------------------------
+    // Members
+    // -----------------------------------------------------------------------
+
+    /** the id of the UNIVERSAL tag */
+    private final int id ;
+
+
+    /**
+     * Private constructor so no other instances can be created other than the
+     * public static constants in this class.
+     *
+     * @param name a string name for the enumeration value.
+     * @param value the integer value of the enumeration.
+     */
+    private LdapTag( final String name, final int value, final int id )
+    {
+        super( name, value ) ;
+        this.id = id ;
+    }
+
+
+    /**
+     * Gets the id of the universal tag.
+     *
+     * @return the id of the universal tag
+     */
+    public int getTagId()
+    {
+        return this.id ;
+    }
+
+
+    /**
+     * Gets a List of the enumerations for ASN.1 UNIVERSAL type tags.
+     *
+     * @return the List of enumerations possible for ASN.1 UNIVERSAL type tags
+     */
+    public static List list()
+    {
+        return EnumUtils.getEnumList( LdapTag.class ) ;
+    }
+
+
+    /**
+     * Gets the Map of LdapTag objects by name using the LdapTag class.
+     *
+     * @return the Map by name of LdapTag
+     */
+    public static Map map()
+    {
+        return EnumUtils.getEnumMap( LdapTag.class ) ;
+    }
+
+
+    /**
+     * Gets the ASN.1 LDAPv3 APPLICATION type tag's enum using a tag value.
+     *
+     * @param value the first octet of the TLV
+     * @return the valued enum for the LDAPv3 ASN.1 type tag
+     */
+    public static LdapTag getLdapTag( int value )
+    {
+        LdapTag type = null ;
+
+        switch ( value )
+        {
+            case( BIND_REQUEST_TAG ):
+                type = BIND_REQUEST ;
+                break ;
+            case( BIND_RESPONSE_TAG ):
+                type = BIND_RESPONSE ;
+                break ;
+            case( UNBIND_REQUEST_TAG ):
+                type = UNBIND_REQUEST ;
+                break ;
+            case( SEARCH_REQUEST_TAG ):
+                type = SEARCH_REQUEST ;
+                break ;
+            case( SEARCH_RESULT_ENTRY_TAG ):
+                type = SEARCH_RESULT_ENTRY ;
+                break ;
+            case( SEARCH_RESULT_DONE_TAG ):
+                type = SEARCH_RESULT_DONE ;
+                break ;
+            case( SEARCH_RESULT_REFERENCE_TAG ):
+                type = SEARCH_RESULT_REFERENCE ;
+                break ;
+            case( MODIFY_REQUEST_TAG ):
+                type = MODIFY_REQUEST ;
+                break ;
+            case( MODIFY_RESPONSE_TAG ):
+                type = MODIFY_RESPONSE ;
+                break ;
+            case( ADD_REQUEST_TAG ):
+                type = ADD_REQUEST ;
+                break ;
+            case( ADD_RESPONSE_TAG ):
+                type = ADD_RESPONSE ;
+                break ;
+            case( DEL_REQUEST_TAG ):
+                type = DEL_REQUEST ;
+                break ;
+            case( DEL_RESPONSE_TAG ):
+                type = DEL_RESPONSE ;
+                break ;
+            case( MODIFYDN_REQUEST_TAG ):
+                type = MODIFYDN_REQUEST ;
+                break ;
+            case( MODIFYDN_RESPONSE_TAG ):
+                type = MODIFYDN_RESPONSE ;
+                break ;
+            case( COMPARE_REQUEST_TAG ):
+                type = COMPARE_REQUEST ;
+                break ;
+            case( COMPARE_RESPONSE_TAG ):
+                type = COMPARE_RESPONSE ;
+                break ;
+            case( ABANDON_REQUEST_TAG ):
+                type = ABANDON_REQUEST ;
+                break ;
+            case( EXTENDED_REQUEST_TAG ):
+                type = EXTENDED_REQUEST ;
+                break ;
+            case( EXTENDED_RESPONSE_TAG ):
+                type = EXTENDED_RESPONSE ;
+                break ;
+            default:
+                String msg ;
+                // no reasonable protocol has more than 1K tags defined
+                if ( value < 10000 && value > -1 )
+                {
+                    msg = "Looks like you're using an id instead of a tag" ;
+                }
+                else
+                {
+                    msg = "Tag value of " + value + " not recognized" ;
+                }
+
+                throw new IllegalArgumentException( msg ) ;
+        }
+
+        return type ;
+    }
+
+
+    /**
+     * Gets the ASN.1 LDAP APPLICATION type tag's enum using a tag id.
+     *
+     * @param id the first octet of the TLV
+     * @return the valued enum for the ASN.1 LDAPv3 APPLICATION type tag
+     */
+    public static LdapTag getLdapTagById( int id )
+    {
+        LdapTag type = null ;
+
+        switch ( id )
+        {
+            case( BIND_REQUEST_ID ):
+                type = BIND_REQUEST ;
+                break ;
+            case( BIND_RESPONSE_ID ):
+                type = BIND_RESPONSE ;
+                break ;
+            case( UNBIND_REQUEST_ID ):
+                type = UNBIND_REQUEST ;
+                break ;
+            case( SEARCH_REQUEST_ID ):
+                type = SEARCH_REQUEST ;
+                break ;
+            case( SEARCH_RESULT_ENTRY_ID ):
+                type = SEARCH_RESULT_ENTRY ;
+                break ;
+            case( SEARCH_RESULT_DONE_ID ):
+                type = SEARCH_RESULT_DONE ;
+                break ;
+            case( SEARCH_RESULT_REFERENCE_ID ):
+                type = SEARCH_RESULT_REFERENCE ;
+                break ;
+            case( MODIFY_REQUEST_ID ):
+                type = MODIFY_REQUEST ;
+                break ;
+            case( MODIFY_RESPONSE_ID ):
+                type = MODIFY_RESPONSE ;
+                break ;
+            case( ADD_REQUEST_ID ):
+                type = ADD_REQUEST ;
+                break ;
+            case( ADD_RESPONSE_ID ):
+                type = ADD_RESPONSE ;
+                break ;
+            case( DEL_REQUEST_ID ):
+                type = DEL_REQUEST ;
+                break ;
+            case( DEL_RESPONSE_ID ):
+                type = DEL_RESPONSE ;
+                break ;
+            case( MODIFYDN_REQUEST_ID ):
+                type = MODIFYDN_REQUEST ;
+                break ;
+            case( MODIFYDN_RESPONSE_ID ):
+                type = MODIFYDN_RESPONSE ;
+                break ;
+            case( COMPARE_REQUEST_ID ):
+                type = COMPARE_REQUEST ;
+                break ;
+            case( COMPARE_RESPONSE_ID ):
+                type = COMPARE_RESPONSE ;
+                break ;
+            case( ABANDON_REQUEST_ID ):
+                type = ABANDON_REQUEST ;
+                break ;
+            case( EXTENDED_REQUEST_ID ):
+                type = EXTENDED_REQUEST ;
+                break ;
+            case( EXTENDED_RESPONSE_ID ):
+                type = EXTENDED_RESPONSE ;
+                break ;
+            default:
+                String msg ;
+                if ( id > 10000 || id < 0 )
+                {
+                    msg = "Looks like you're using a tag instead of an id" ;
+                }
+                else
+                {
+                    msg = "Id of " + id + " not recognized as a LDAPv3 id" ;
+                }
+
+                throw new IllegalArgumentException( msg ) ;
+        }
+
+        return type ;
+    }
+}

Added: incubator/directory/snickers/trunk/provider/src/test/org/apache/snickers/ldap/BindRequestRuleTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/trunk/provider/src/test/org/apache/snickers/ldap/BindRequestRuleTest.java
Sat Apr 17 18:45:44 2004
@@ -0,0 +1,109 @@
+/*
+ *   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 junit.framework.TestCase ;
+
+import org.apache.snickers.ber.TypeClass ;
+import org.apache.snickers.ber.digester.BERDigester ;
+import org.apache.snickers.ber.primitives.UniversalTag ;
+
+import org.apache.ldap.common.message.BindRequest ;
+
+
+/**
+ * TestCase used to unit test the BindRequestRule.
+ * 
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class BindRequestRuleTest extends TestCase
+{
+    /** rule used to create a bind request */
+    BindRequestRule bindRequestRule = null ;
+    BERDigester digester = new BERDigester() ;
+
+
+    protected void setUp() throws Exception
+    {
+        super.setUp() ;
+        bindRequestRule = new BindRequestRule() ;
+        bindRequestRule.setDigester( digester ) ;
+    }
+
+
+    protected void tearDown() throws Exception
+    {
+        super.tearDown() ;
+        bindRequestRule.setDigester( null ) ;
+        bindRequestRule = null ;
+    }
+
+
+    public void testTag0() throws Exception
+    {
+        digester.pushInt( 77 ) ;
+        bindRequestRule.tag( 0, true, TypeClass.APPLICATION ) ;
+        assertEquals( 1, digester.getCount() ) ;
+        BindRequest req = ( BindRequest ) digester.peek() ;
+        assertEquals( 77, req.getMessageId() ) ;
+    }
+
+
+    public void testTag1() throws Exception
+    {
+        try
+        {
+            bindRequestRule.tag( 2, true, TypeClass.APPLICATION ) ;
+            fail( "should have caused an exception above to never get here" ) ;
+        }
+        catch ( IllegalArgumentException e )
+        {
+        }
+
+        assertEquals( 0, digester.getCount() ) ;
+    }
+
+
+    public void testFinish() throws Exception
+    {
+        testTag0() ;
+        bindRequestRule.finish() ;
+        assertEquals( 0, digester.getCount() ) ;
+        BindRequest req = ( BindRequest ) digester.getRoot() ;
+        assertEquals( 77, req.getMessageId() ) ;
+    }
+
+
+    public void testGetTag() throws Exception
+    {
+        assertEquals( LdapTag.BIND_REQUEST, BindRequestRule.getTag() ) ;
+    }
+
+
+    public void testGetNestingPattern() throws Exception
+    {
+        int[] pattern = BindRequestRule.getNestingPattern() ;
+        assertNotNull( pattern ) ;
+        assertEquals( 2, pattern.length ) ;
+        assertEquals( UniversalTag.SEQUENCE_SEQUENCE_OF.getValue(),
+                pattern[0] ) ;
+        assertEquals( LdapTag.BIND_REQUEST.getValue(),
+                pattern[1] ) ;
+    }
+}
\ No newline at end of file

Mime
View raw message