directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 37151 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder/abandon test/org/apache/snickers/ldap/encoder/abandon
Date Sat, 28 Aug 2004 03:34:19 GMT
Author: akarasulu
Date: Fri Aug 27 20:34:19 2004
New Revision: 37151

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
Log:
added AbandonRequest stub encoder and its unit test

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoder.java
Fri Aug 27 20:34:19 2004
@@ -0,0 +1,75 @@
+/*
+ *   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.abandon;
+
+
+import org.apache.ldap.common.message.AbandonRequest;
+
+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;
+
+
+/**
+ * Encodes an AbandonRequest stub into a TupleNode tree representing the TLV
+ * nesting pattern of the request.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class AbandonRequestEncoder
+{
+    /** thread safe (flyweight) instance of this encoder */
+    public static final AbandonRequestEncoder INSTANCE =
+            new AbandonRequestEncoder();
+
+
+    /**
+     * Encodes an AbandonRequest stub into a TupleNode tree.
+     *
+     * @param request the AbandonRequest stub to encode
+     * @return the root TupleNode for the tlv tree
+     */
+    public TupleNode encode( AbandonRequest 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 PDU
+        DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+                EncoderUtils.encode( request.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
+
+        // Add the node for the id that is abandoned
+        child = ( DefaultMutableTupleNode ) EncoderUtils.encode(
+                LdapTag.ABANDON_REQUEST, request.getAbandoned() );
+        top.addLast( child );
+        child.setParent( top );
+
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/abandon/AbandonRequestEncoderTest.java
Fri Aug 27 20:34:19 2004
@@ -0,0 +1,51 @@
+/*
+ *   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.abandon;
+
+
+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 AbandonRequestEncoder class.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a> $Rev$
+ */
+public class AbandonRequestEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encode method.
+     */
+    public void testEncode()
+    {
+        AbandonRequestImpl request = new AbandonRequestImpl( 33 );
+        request.setAbandoned( 11 );
+
+        // Encode stub into tuple tree then into the accumulator
+        TupleNode node = AbandonRequestEncoder.INSTANCE.encode( request );
+        encode( ( DefaultMutableTupleNode ) node );
+
+        // Test to see if original stub equals the round trip generated stub
+        assertTrue( request.equals( decode() ) );
+    }
+}

Mime
View raw message