directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 37063 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder java/org/apache/snickers/ldap/encoder/add test/org/apache/snickers/ldap/encoder/add
Date Thu, 26 Aug 2004 07:35:21 GMT
Author: akarasulu
Date: Thu Aug 26 00:35:20 2004
New Revision: 37063

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddRequestEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddResponseEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddResponseEncoderTest.java
Modified:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Log:
Commit changes ...

 o added the Add req/resp encoders
 o created and passed Add req/resp encoder test cases
 o code conv: removed m_, a_ and space before ;


Modified: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
==============================================================================
--- incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
(original)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/SnickersLdapEncoder.java
Thu Aug 26 00:35:20 2004
@@ -32,6 +32,8 @@
 import org.apache.snickers.ldap.encoder.unbind.UnbindRequestEncoder;
 import org.apache.snickers.ldap.encoder.delete.DeleteRequestEncoder;
 import org.apache.snickers.ldap.encoder.delete.DeleteResponseEncoder;
+import org.apache.snickers.ldap.encoder.add.AddRequestEncoder;
+import org.apache.snickers.ldap.encoder.add.AddResponseEncoder;
 
 
 
@@ -56,6 +58,16 @@
         switch( msg.getType().getValue() )
         {
             case( MessageTypeEnum.ABANDONREQUEST_VAL ):
+                break;
+
+            case( MessageTypeEnum.ADDREQUEST_VAL ):
+                root = AddRequestEncoder.INSTANCE
+                        .encode( ( AddRequest ) msg );
+                break;
+
+            case( MessageTypeEnum.ADDRESPONSE_VAL ):
+                root = AddResponseEncoder.INSTANCE
+                        .encode( ( AddResponse ) msg );
                 break;
 
             case( MessageTypeEnum.BINDREQUEST_VAL ):

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddRequestEncoder.java
Thu Aug 26 00:35:20 2004
@@ -0,0 +1,86 @@
+/*
+ *   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.encoder.add;
+
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.AttributesEncoder;
+import org.apache.snickers.ldap.LdapTag;
+
+import org.apache.ldap.common.message.AddRequest;
+
+
+/**
+ * AddRequest Encoder for transforming AddRequest stubs into a TupleNode
+ * representing the root of a tlv tuple tree.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AddRequestEncoder
+{
+    /** thread safe (flyweight) instance for this encoder */
+    public static final AddRequestEncoder INSTANCE = new AddRequestEncoder();
+
+
+    public TupleNode encode( AddRequest request )
+    {
+        /// Create the top level PDU node
+        DefaultMutableTupleNode top =
+                new DefaultMutableTupleNode( new Tuple() );
+        top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+        top.getTuple().setLength( Length.INDEFINATE );
+
+        // Create and add the message id to response PDU
+        DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
+
+        // Create the addReq nodes
+        DefaultMutableTupleNode addReq =
+                new DefaultMutableTupleNode( new Tuple() );
+        addReq.getTuple().setTag( LdapTag.ADD_REQUEST, false );
+        addReq.getTuple().setLength( Length.INDEFINATE );
+
+        // Add the LDAPDN entry name to the addReq node
+        child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getName() );
+        addReq.addLast( child );
+        child.setParent( addReq );
+
+        // Add the AttributeList to the addReq node delegating generation
+        // to the AttributesEncoder which is also used by the SearchRequest
+        // for generating the PartialAttributesList with the same ASN.1 syntax
+        child = ( DefaultMutableTupleNode )
+                AttributesEncoder.INSTANCE.encode( request.getEntry() );
+        addReq.addLast( child );
+        child.setParent( addReq );
+
+        // Attach the addReq node to the top and return the top
+        top.addLast( addReq );
+        addReq.setParent( top );
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddResponseEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/add/AddResponseEncoder.java
Thu Aug 26 00:35:20 2004
@@ -0,0 +1,80 @@
+/*
+ *   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.encoder.add;
+
+
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.primitives.UniversalTag;
+
+import org.apache.snickers.ldap.LdapTag;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.LdapResultEncoder;
+
+import org.apache.ldap.common.message.AddResponse;
+
+
+/**
+ * A AddResponse stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ */
+public class AddResponseEncoder
+{
+    /** An instance of this encoder */
+    public static final AddResponseEncoder INSTANCE =
+            new AddResponseEncoder();
+
+
+    /**
+     * Encodes a AddResponse stub corresponding to a AddResponse
+     * PDU into a TupleTree representing the TLV nesting heirarchy.
+     *
+     * @param response the AddResponse to encode
+     * @return the root TLV tuple for the encoded AddResponse PDU
+     */
+    public TupleNode encode( AddResponse response )
+    {
+        /// Create the top level TupleNode of the PDU
+        DefaultMutableTupleNode top =
+                new DefaultMutableTupleNode( new Tuple() );
+        top.getTuple().setTag( UniversalTag.SEQUENCE_SEQUENCE_OF, false );
+        top.getTuple().setLength( Length.INDEFINATE );
+
+        // Create and add the message id to response PDU
+        DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( response.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
+
+        // Create the Add response sequence of TLV tuple
+        DefaultMutableTupleNode addResult =
+                new DefaultMutableTupleNode( new Tuple() );
+        addResult.getTuple().setTag( LdapTag.ADD_RESPONSE, false );
+        addResult.getTuple().setLength( Length.INDEFINATE );
+
+        // Stuff sequence of TLV tuple with the Components of the LDAPResult
+        LdapResultEncoder.INSTANCE.encode( addResult, response.getLdapResult() );
+
+        top.addLast( addResult );
+        addResult.setParent( top );
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
Thu Aug 26 00:35:20 2004
@@ -0,0 +1,56 @@
+/*
+ *   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.encoder.add;
+
+
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+
+import org.apache.ldap.common.message.*;
+
+
+/**
+ * TestCase for the AddRequestEncoder class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class AddRequestEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encode method.
+     */
+    public void testEncode()
+    {
+        AddRequestImpl request = new AddRequestImpl( 33 );
+        request.setName( "dc=apache,dc=org" );
+        LockableAttributesImpl attrs = new LockableAttributesImpl( request );
+        attrs.put( "objectClass", "top" );
+        attrs.put( "objectClass", "dcObject" );
+        attrs.put( "dc", "example.com" );
+        request.setEntry( attrs );
+
+        // Encode stub into tuple tree then into the accumulator
+        TupleNode node = AddRequestEncoder.INSTANCE.encode( request );
+        encode( ( DefaultMutableTupleNode ) node );
+
+        // Test to see if original stub equals the round trip generated stub
+        assertTrue( request.equals( decode() ) );
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddResponseEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddResponseEncoderTest.java
Thu Aug 26 00:35:20 2004
@@ -0,0 +1,59 @@
+/*
+ *   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.encoder.add;
+
+
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+
+import org.apache.ldap.common.message.*;
+
+
+/**
+ * Tests the AddResponse encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ */
+public class AddResponseEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encoder's encode() method.
+     */
+    public void testEncode()
+    {
+        // Construct the Add response to test with results and referrals
+        AddResponseImpl response = new AddResponseImpl( 45 );
+        LdapResultImpl result = new LdapResultImpl( response );
+        response.setLdapResult( result );
+        result.setMatchedDn( "dc=example,dc=com" );
+        result.setResultCode( ResultCodeEnum.SUCCESS );
+        ReferralImpl refs = new ReferralImpl( result );
+        refs.addLdapUrl( "ldap://someserver.com" );
+        refs.addLdapUrl( "ldap://apache.org" );
+        refs.addLdapUrl( "ldap://another.net" );
+        result.setReferral( refs );
+
+        // Encode stub into tuple tree then into the accumulator
+        TupleNode node = AddResponseEncoder.INSTANCE.encode( response );
+        encode( ( DefaultMutableTupleNode ) node );
+
+        // Test to see if original stub equals the round trip generated stub
+        assertTrue( response.equals( decode() ) );
+    }
+}

Mime
View raw message