directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 36762 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder/search test/org/apache/snickers/ldap/encoder/search
Date Mon, 23 Aug 2004 06:57:00 GMT
Author: akarasulu
Date: Sun Aug 22 23:56:59 2004
New Revision: 36762

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoderTest.java
Log:
Completed the search response done encoder and tested it.


Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoder.java
Sun Aug 22 23:56:59 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.search;
+
+
+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.SearchResponseDone;
+
+
+/**
+ * An SearchResponseDone stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class SearchResponseDoneEncoder
+{
+    /** An instance of this encoder */
+    public static final SearchResponseDoneEncoder INSTANCE =
+            new SearchResponseDoneEncoder();
+
+
+    /**
+     * Encodes a SearchResponseDone stub corresponding to a SearchResultDone
+     * PDU into a TupleTree representing the TLV nesting heirarchy.
+     *
+     * @param response the SearchResponseDone to encode
+     * @return the root TLV tuple for the encoded SearchResultDone PDU
+     */
+    public TupleNode encode( SearchResponseDone response )
+    {
+        /// Create the top level BindResponse 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( response.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
+
+        // Create the bind response sequence of TLV tuple
+        DefaultMutableTupleNode doneResp =
+                new DefaultMutableTupleNode( new Tuple() );
+        doneResp.getTuple().setTag( LdapTag.SEARCH_RESULT_DONE, false );
+        doneResp.getTuple().setLength( Length.INDEFINATE );
+
+        // Stuff sequence of TLV tuple with the Components of the LDAPResult
+        LdapResultEncoder.INSTANCE.encode( doneResp, response.getLdapResult() );
+
+        top.addLast( doneResp );
+        doneResp.setParent( top );
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/search/SearchResponseDoneEncoderTest.java
Sun Aug 22 23:56:59 2004
@@ -0,0 +1,60 @@
+/*
+ *   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.search;
+
+
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
+import org.apache.snickers.ldap.encoder.search.SearchResponseDoneEncoder;
+
+import org.apache.ldap.common.message.*;
+
+
+/**
+ * Tests the SearchResponse encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class SearchResponseDoneEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encoder's encode() method.
+     */
+    public void testEncode()
+    {
+        // Construct the Search response to test with results and referrals
+        SearchResponseDoneImpl response = new SearchResponseDoneImpl( 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 = SearchResponseDoneEncoder.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