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/28 07:00:26 UTC
svn commit: rev 37157 - in incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src: java/org/apache/snickers/ldap/encoder/modifyDn test/org/apache/snickers/ldap/encoder/modifyDn
Author: akarasulu
Date: Fri Aug 27 22:00:26 2004
New Revision: 37157
Added:
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoder.java
incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoderTest.java
Log:
Commit changes ...
o added ModifyDnRequest stub encoder
o added and passed unit test for encoder
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoder.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/java/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoder.java Fri Aug 27 22:00:26 2004
@@ -0,0 +1,100 @@
+/*
+ * 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.modifyDn;
+
+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.LdapTag;
+import org.apache.ldap.common.message.ModifyDnRequest;
+
+/**
+ * Encoder which generates a TupleNode tree from a ModifyDnRequest PDU stub.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a>
+ * @version $Rev$
+ */
+public class ModifyDnRequestEncoder
+{
+ /** thread safe (flywieght) instance of this encoder */
+ public static final ModifyDnRequestEncoder INSTANCE =
+ new ModifyDnRequestEncoder();
+
+
+ /**
+ * Encodes a ModifyDnRequest into a TupleNode tree.
+ *
+ * @param req the ModifyDnRequest stub to encode
+ * @return the encoded root TupleNode tree
+ */
+ public TupleNode encode( ModifyDnRequest req )
+ {
+ /// 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 req PDU
+ DefaultMutableTupleNode child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( req.getMessageId() );
+ top.addLast( child );
+ child.setParent( top );
+
+ // Create the modify response sequence of TLV tuple
+ DefaultMutableTupleNode modifyDnReq =
+ new DefaultMutableTupleNode( new Tuple() );
+ modifyDnReq.getTuple().setTag( LdapTag.MODIFYDN_REQUEST, false );
+ modifyDnReq.getTuple().setLength( Length.INDEFINATE );
+
+ // add the tuple for the LDAPDN entry name
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( req.getName() );
+ modifyDnReq.addLast( child );
+ child.setParent( modifyDnReq );
+
+ // add the tuple for the RelativeLDAPDN newrdn
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( req.getNewRdn() );
+ modifyDnReq.addLast( child );
+ child.setParent( modifyDnReq );
+
+ // add the tuple for the BOOLEAN deleteOldRdn field
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( req.getDeleteOldRdn() );
+ modifyDnReq.addLast( child );
+ child.setParent( modifyDnReq );
+
+ // add the tuple for the OPTIONAL LDAPDN newSuperior
+ if ( req.getNewSuperior() != null )
+ {
+ child = ( DefaultMutableTupleNode )
+ EncoderUtils.encode( LdapTag.CONTEXT_SPECIFIC_TAG_0,
+ req.getNewSuperior() );
+ modifyDnReq.addLast( child );
+ child.setParent( modifyDnReq );
+ }
+
+ top.addLast( modifyDnReq );
+ modifyDnReq.setParent( top );
+ return top;
+ }
+}
Added: incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoderTest.java
==============================================================================
--- (empty file)
+++ incubator/directory/snickers/branches/encoder-redesign/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/modifyDn/ModifyDnRequestEncoderTest.java Fri Aug 27 22:00:26 2004
@@ -0,0 +1,54 @@
+/*
+ * 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.modifyDn;
+
+
+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 ModifyDnRequest encoder.
+ *
+ * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
+ * Project</a>
+ */
+public class ModifyDnRequestEncoderTest extends AbstractEncoderTestCase
+{
+ /**
+ * Tests the encoder's encode() method.
+ */
+ public void testEncode()
+ {
+ // Construct the ModifyDn request to test
+ ModifyDnRequestImpl request = new ModifyDnRequestImpl( 45 );
+ request.setDeleteOldRdn( true );
+ request.setName( "dc=admins,dc=apache,dc=org" );
+ request.setNewRdn( "dc=administrators" );
+ request.setNewSuperior( "dc=groups,dc=apache,dc=org" );
+
+ // Encode stub into tuple tree then into the accumulator
+ TupleNode node = ModifyDnRequestEncoder.INSTANCE.encode( request );
+ encode( ( DefaultMutableTupleNode ) node );
+
+ // Test to see if original stub equals the round trip generated stub
+ assertTrue( request.equals( decode() ) );
+ }
+}