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/08/26 07:21:32 UTC
svn commit: rev 37058 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder java/org/apache/snickers/ldap/encoder/delete test/org/apache/snickers/ldap/encoder/delete
Author: akarasulu
Date: Wed Aug 25 22:21:32 2004
New Revision: 37058
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoderTest.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 completed DeleteResponse encoder
o added and passed tests for DeleteResponseEncoder test cases
o added the DeleteResponse and DeleteRequest handling hooks to the encoder
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 Wed Aug 25 22:21:32 2004
@@ -30,6 +30,8 @@
import org.apache.snickers.ldap.encoder.search.SearchResponseDoneEncoder;
import org.apache.snickers.ldap.encoder.search.SearchResponseEntryEncoder;
import org.apache.snickers.ldap.encoder.unbind.UnbindRequestEncoder;
+import org.apache.snickers.ldap.encoder.delete.DeleteRequestEncoder;
+import org.apache.snickers.ldap.encoder.delete.DeleteResponseEncoder;
@@ -64,6 +66,16 @@
case( MessageTypeEnum.BINDRESPONSE_VAL ):
root = BindResponseEncoder.INSTANCE
.encode( ( BindResponse ) msg );
+ break;
+
+ case( MessageTypeEnum.DELREQUEST_VAL ):
+ root = DeleteRequestEncoder.INSTANCE
+ .encode( ( DeleteRequest ) msg );
+ break;
+
+ case( MessageTypeEnum.DELRESPONSE_VAL ):
+ root = DeleteResponseEncoder.INSTANCE
+ .encode( ( DeleteResponse ) msg );
break;
case( MessageTypeEnum.SEARCHREQUEST_VAL ):
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoder.java Wed Aug 25 22:21:32 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.delete;
+
+
+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.DeleteResponse;
+
+
+/**
+ * A DeleteResponse stub to tuple tree encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a>
+ */
+public class DeleteResponseEncoder
+{
+ /** An instance of this encoder */
+ public static final DeleteResponseEncoder INSTANCE =
+ new DeleteResponseEncoder();
+
+
+ /**
+ * Encodes a DeleteResponse stub corresponding to a DelResponse
+ * PDU into a TupleTree representing the TLV nesting heirarchy.
+ *
+ * @param response the DeleteResponse to encode
+ * @return the root TLV tuple for the encoded DeleteResponse PDU
+ */
+ public TupleNode encode( DeleteResponse 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 delete response sequence of TLV tuple
+ DefaultMutableTupleNode delResult =
+ new DefaultMutableTupleNode( new Tuple() );
+ delResult.getTuple().setTag( LdapTag.DEL_RESPONSE, false );
+ delResult.getTuple().setLength( Length.INDEFINATE );
+
+ // Stuff sequence of TLV tuple with the Components of the LDAPResult
+ LdapResultEncoder.INSTANCE.encode( delResult, response.getLdapResult() );
+
+ top.addLast( delResult );
+ delResult.setParent( top );
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/delete/DeleteResponseEncoderTest.java Wed Aug 25 22:21:32 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.delete;
+
+
+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 DeleteResponse encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a>
+ */
+public class DeleteResponseEncoderTest extends AbstractEncoderTestCase
+{
+ /**
+ * Tests the encoder's encode() method.
+ */
+ public void testEncode()
+ {
+ // Construct the Delete response to test with results and referrals
+ DeleteResponseImpl response = new DeleteResponseImpl( 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 = DeleteResponseEncoder.INSTANCE.encode( response );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( response.equals( decode() ) );
+ }
+}