directory-commits mailing list archives

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

Added:
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modify/
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoder.java
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modify/
   incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoderTest.java
Log:
added ModifyResponse encoder and its unit test

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoder.java
Fri Aug 27 18:33:06 2004
@@ -0,0 +1,70 @@
+/*
+ *   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.modify;
+
+import org.apache.ldap.common.message.ModifyResponse;
+import org.apache.snickers.ber.TupleNode;
+import org.apache.snickers.ber.DefaultMutableTupleNode;
+import org.apache.snickers.ber.Tuple;
+import org.apache.snickers.ber.Length;
+import org.apache.snickers.ber.primitives.UniversalTag;
+import org.apache.snickers.ldap.encoder.EncoderUtils;
+import org.apache.snickers.ldap.encoder.LdapResultEncoder;
+import org.apache.snickers.ldap.LdapTag;
+
+/**
+ * Encoder which generates a TupleNode tree from a ModifyResponse PDU stub.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ * @version $Rev$
+ */
+public class ModifyResponseEncoder
+{
+    /** thread safe (flywieght) instance of this encoder */
+    public static final ModifyResponseEncoder INSTANCE =
+            new ModifyResponseEncoder();
+
+    public TupleNode encode( ModifyResponse resp )
+    {
+        /// 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( resp.getMessageId() );
+        top.addLast( child );
+        child.setParent( top );
+
+        // Create the modify response sequence of TLV tuple
+        DefaultMutableTupleNode modifyResult =
+                new DefaultMutableTupleNode( new Tuple() );
+        modifyResult.getTuple().setTag( LdapTag.MODIFY_RESPONSE, false );
+        modifyResult.getTuple().setLength( Length.INDEFINATE );
+
+        // Stuff sequence of TLV tuple with the Components of the LDAPResult
+        LdapResultEncoder.INSTANCE.encode( modifyResult,
+                resp.getLdapResult() );
+
+        top.addLast( modifyResult );
+        modifyResult.setParent( top );
+        return top;
+    }
+}

Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modify/ModifyResponseEncoderTest.java
Fri Aug 27 18:33:06 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.modify;
+
+
+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 ModifyResponse encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ *         Project</a>
+ */
+public class ModifyResponseEncoderTest extends AbstractEncoderTestCase
+{
+    /**
+     * Tests the encoder's encode() method.
+     */
+    public void testEncode()
+    {
+        // Construct the Modify response to test with results and referrals
+        ModifyResponseImpl response = new ModifyResponseImpl( 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 = ModifyResponseEncoder.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