You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2005/07/03 17:01:12 UTC
svn commit: r208929 -
/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
Author: elecharny
Date: Sun Jul 3 08:01:12 2005
New Revision: 208929
URL: http://svn.apache.org/viewcvs?rev=208929&view=rev
Log:
Added the ModifyDNRequest test case
Added:
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
Added: directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java?rev=208929&view=auto
==============================================================================
--- directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java (added)
+++ directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/ModifyDNRequestTest.java Sun Jul 3 08:01:12 2005
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2005 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.asn1.ldap.codec;
+
+import java.nio.ByteBuffer;
+
+import javax.naming.NamingException;
+
+import org.apache.asn1.DecoderException;
+import org.apache.asn1.ber.Asn1Decoder;
+import org.apache.asn1.ber.containers.IAsn1Container;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.asn1.ldap.pojo.ModifyDNRequest;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the ModifyDNRequest codec
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ */
+public class ModifyDNRequestTest extends TestCase {
+ /** Logger */
+ protected static Logger log = Logger.getLogger( ModifyDNRequestTest.class );
+
+ static
+ {
+ PropertyConfigurator.configure( "conf/log4j.conf" );
+ }
+
+ /**
+ * Test the decoding of a full ModifyDNRequest
+ */
+ public void testDecodeModifyDNRequestSuccess() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x4A );
+
+ stream.put(
+ new byte[]
+ {
+
+
+ 0x30, 0x48, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x6C, 0x43, // CHOICE { ..., modifyDNRequest ModifyDNRequest, ...
+ // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x22, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', ' ', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', ' ', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // newrdn RelativeLDAPDN,
+ 0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y',
+ 0x01, 0x01, 0x00, // deleteoldrdn BOOLEAN,
+ // newSuperior [0] LDAPDN OPTIONAL }
+ 0x04, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm'
+ } );
+
+ stream.flip();
+
+ // Allocate a ModifyRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ModifyDNRequest modifyDNRequest = message.getModifyDNRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "cn=testModify, ou=users, ou=system", modifyDNRequest.getEntry() );
+ Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+ Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+ Assert.assertEquals( "ou=system", modifyDNRequest.getNewSuperior() );
+
+ }
+
+ /**
+ * Test the decoding of a ModifyDNRequest without a superior
+ */
+ public void testDecodeModifyDNRequestWithoutSuperior() throws NamingException
+ {
+ Asn1Decoder ldapDecoder = new LdapDecoder();
+
+ ByteBuffer stream = ByteBuffer.allocate( 0x3F );
+
+ stream.put(
+ new byte[]
+ {
+
+
+ 0x30, 0x3D, // LDAPMessage ::= SEQUENCE {
+ 0x02, 0x01, 0x01, // messageID MessageID
+ 0x6C, 0x38, // CHOICE { ..., modifyDNRequest ModifyDNRequest, ...
+ // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE {
+ // entry LDAPDN,
+ 0x04, 0x22, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', ' ', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', ' ', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm',
+ // newrdn RelativeLDAPDN,
+ 0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y',
+ 0x01, 0x01, 0x00 // deleteoldrdn BOOLEAN,
+ // newSuperior [0] LDAPDN OPTIONAL }
+ } );
+
+ stream.flip();
+
+ // Allocate a ModifyRequest Container
+ IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+ try
+ {
+ ldapDecoder.decode( stream, ldapMessageContainer );
+ }
+ catch ( DecoderException de )
+ {
+ de.printStackTrace();
+ Assert.fail( de.getMessage() );
+ }
+
+ LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer ).getLdapMessage();
+ ModifyDNRequest modifyDNRequest = message.getModifyDNRequest();
+
+ Assert.assertEquals( 1, message.getMessageId() );
+ Assert.assertEquals( "cn=testModify, ou=users, ou=system", modifyDNRequest.getEntry() );
+ Assert.assertEquals( false, modifyDNRequest.isDeleteOldRDN() );
+ Assert.assertEquals( "cn=testDNModify", modifyDNRequest.getNewRDN() );
+ }
+}