commits@directory.apache.org
[Top] [All Lists]

svn commit: r208938 - /directory/sandbox/trunk/asn1-new-codec/src/test/o

Subject: svn commit: r208938 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
From:
Date: Sun, 03 Jul 2005 16:06:57 -0000
Author: elecharny
Date: Sun Jul  3 09:06:56 2005
New Revision: 208938

URL: http://svn.apache.org/viewcvs?rev=208938&view=rev
Log:
Added the DelRequest unit test

Added:
    
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java

Added: 
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
URL: 
http://svn.apache.org/viewcvs/directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java?rev=208938&view=auto
==============================================================================
--- 
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
 (added)
+++ 
directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java
 Sun Jul  3 09:06:56 2005
@@ -0,0 +1,128 @@
+/*
+ *   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.DelRequest;
+import org.apache.asn1.ldap.pojo.LdapMessage;
+import org.apache.log4j.Logger;
+import org.apache.log4j.PropertyConfigurator;
+
+import junit.framework.Assert;
+import junit.framework.TestCase;
+
+/**
+ * Test the DelRequest codec
+ * 
+ * @author <a href="mailto:dev@xxxxxxxxxxxxxxxxxxxx";>Apache Directory 
Project</a>
+ */
+public class DelRequestTest extends TestCase {
+    /** Logger */
+    protected static Logger log = Logger.getLogger( DelRequestTest.class );
+
+    static
+    {
+        PropertyConfigurator.configure( "conf/log4j.conf" );
+    }
+
+    /**
+     * Test the decoding of a full DelRequest
+     */
+    public void testDecodeDelRequestSuccess() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x29 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x27,            // LDAPMessage ::= SEQUENCE {
+                               0x02, 0x01, 0x01,       //     messageID 
MessageID
+                                                       //     CHOICE { ..., 
delRequest   DelRequest, ...
+                                               // DelRequest ::= [APPLICATION 
10] LDAPDN;
+                               0x4A, 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'
+            } );
+
+        stream.flip();
+
+        // Allocate a DelRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+       
+        LdapMessage message = ( ( LdapMessageContainer ) ldapMessageContainer 
).getLdapMessage();
+        DelRequest delNRequest      = message.getDelRequest();
+
+        Assert.assertEquals( 1, message.getMessageId() );
+        Assert.assertEquals( "cn=testModify, ou=users, ou=system", 
delNRequest.getEntry() );
+    }
+
+    /**
+     * Test the decoding of aempty DelRequest
+     */
+    public void testDecodeDelRequestEmpty() throws NamingException
+    {
+        Asn1Decoder ldapDecoder = new LdapDecoder();
+
+        ByteBuffer  stream      = ByteBuffer.allocate( 0x07 );
+        
+        stream.put(
+            new byte[]
+            {
+                 
+                
+                0x30, 0x05,            // LDAPMessage ::= SEQUENCE {
+                               0x02, 0x01, 0x01,       //     messageID 
MessageID
+                                                       //     CHOICE { ..., 
delRequest   DelRequest, ...
+                                               // DelRequest ::= [APPLICATION 
10] LDAPDN;
+                               0x4A, 0x00          // Empty DN
+            } );
+
+        stream.flip();
+
+        // Allocate a DelRequest Container
+        IAsn1Container ldapMessageContainer = new LdapMessageContainer();
+
+        try
+        {
+            ldapDecoder.decode( stream, ldapMessageContainer );
+            Assert.fail("We should never reach this point !!!");
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.assertTrue( true );
+        }
+    }
+}


<Prev in Thread] Current Thread [Next in Thread>
  • svn commit: r208938 - /directory/sandbox/trunk/asn1-new-codec/src/test/org/apache/asn1/ldap/codec/DelRequestTest.java, elecharny <=