directory-commits mailing list archives

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

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoder.java
  (contents, props changed)
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoderTest.java
  (contents, props changed)
Log:
Commit changes ...

 o added complete compare response encoder 
 o added test case for compare response 
 o passed test case



Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoder.java
Thu Aug 26 06:21:26 2004
@@ -0,0 +1,83 @@
+/*
+ *   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.compare;
+
+
+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.snickers.ldap.encoder.delete.DeleteResponseEncoder;
+
+import org.apache.ldap.common.message.DeleteResponse;
+import org.apache.ldap.common.message.CompareResponse;
+
+
+/**
+ * A CompareResponse stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ */
+public class CompareResponseEncoder
+{
+    /** An instance of this encoder */
+    public static final CompareResponseEncoder INSTANCE =
+            new CompareResponseEncoder();
+
+
+    /**
+     * Encodes a CompareResponse stub corresponding to a CompareResponse
+     * PDU into a TupleTree representing the TLV nesting heirarchy.
+     *
+     * @param response the CompareResponse to encode
+     * @return the root TLV tuple for the encoded CompareResponse PDU
+     */
+    public TupleNode encode( CompareResponse 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 compare response sequence of TLV tuple
+        DefaultMutableTupleNode compareResult =
+                new DefaultMutableTupleNode( new Tuple() );
+        compareResult.getTuple().setTag( LdapTag.COMPARE_RESPONSE, false );
+        compareResult.getTuple().setLength( Length.INDEFINATE );
+
+        // Stuff sequence of TLV tuple with the Components of the LDAPResult
+        LdapResultEncoder.INSTANCE.encode( compareResult,
+                response.getLdapResult() );
+
+        top.addLast( compareResult );
+        compareResult.setParent( top );
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/compare/CompareResponseEncoderTest.java
Thu Aug 26 06:21:26 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.compare;
+
+
+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 CompareResponse encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ */
+public class CompareResponseEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encoder's encode() method.
+     */
+    public void testEncode()
+    {
+        // Construct the Compare response to test with results and referrals
+        CompareResponseImpl response = new CompareResponseImpl( 45 );
+        LdapResultImpl result = new LdapResultImpl( response );
+        response.setLdapResult( result );
+        result.setMatchedDn( "dc=example,dc=com" );
+        result.setResultCode( ResultCodeEnum.COMPARETRUE );
+        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 = CompareResponseEncoder.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