directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r395943 - /directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java
Date Fri, 21 Apr 2006 16:36:09 GMT
Author: elecharny
Date: Fri Apr 21 09:36:07 2006
New Revision: 395943

URL: http://svn.apache.org/viewcvs?rev=395943&view=rev
Log:
Added two tests and added the encode tests

Modified:
    directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java

Modified: directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java
URL: http://svn.apache.org/viewcvs/directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java?rev=395943&r1=395942&r2=395943&view=diff
==============================================================================
--- directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java
(original)
+++ directory/trunks/shared/ldap/src/test/java/org/apache/directory/shared/ldap/codec/extended/operations/StoredProcedureTest.java
Fri Apr 21 09:36:07 2006
@@ -28,6 +28,7 @@
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
 import org.apache.directory.shared.asn1.ber.IAsn1Container;
 import org.apache.directory.shared.asn1.codec.DecoderException;
+import org.apache.directory.shared.asn1.codec.EncoderException;
 import org.apache.directory.shared.ldap.codec.extended.operations.StoredProcedure.StoredProcedureParameter;
 import org.apache.directory.shared.ldap.util.StringTools;
 
@@ -39,24 +40,30 @@
  */
 public class StoredProcedureTest extends TestCase
 {
-    public void testDecodeStoredProcedure() throws NamingException
+    public void testDecodeStoredProcedureNParams() throws NamingException
     {
         Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
 
-        ByteBuffer stream = ByteBuffer.allocate( 0x3E );
+        ByteBuffer stream = ByteBuffer.allocate( 0x44 );
 
         stream.put( new byte[]
             {
-                0x30, 0x3C,
+                0x30, 0x42,
                     0x04, 0x04, 'J', 'a', 'v', 'a',
                     0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e',
-                    0x30, 0x2B,
-                        0x04, 0x03, 'i', 'n', 't', 0x04, 0x01, 0x01,
-                        0x04, 0x07, 'b', 'o', 'o', 'l', 'e', 'a', 'n', 0x04, 0x04, 't', 'r',
'u', 'e',
-                        0x04, 0x06, 'S', 't', 'r', 'i', 'n', 'g', 0x04, 0x0A, 'p', 'a', 'r',
'a', 'm', 'e', 't', 'e', 'r', '3' 
+                    0x30, 0x31,
+                      0x30, 0x08,
+                        0x04, 0x03, 'i', 'n', 't', 
+                        0x04, 0x01, 0x01,
+                      0x30, 0x0F,
+                        0x04, 0x07, 'b', 'o', 'o', 'l', 'e', 'a', 'n', 
+                        0x04, 0x04, 't', 'r', 'u', 'e',
+                      0x30, 0x14,
+                        0x04, 0x06, 'S', 't', 'r', 'i', 'n', 'g', 
+                        0x04, 0x0A, 'p', 'a', 'r', 'a', 'm', 'e', 't', 'e', 'r', '3' 
             } );
 
-        //String decodedPdu = StringTools.dumpBytes( stream.array() );
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
         stream.flip();
 
         // Allocate a StoredProcedure Container
@@ -97,5 +104,138 @@
         Assert.assertEquals( "String", StringTools.utf8ToString( param.getType() ) );
         Assert.assertEquals( "parameter3", StringTools.utf8ToString( param.getValue() ) );
 
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = storedProcedure.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    public void testDecodeStoredProcedureNoParam() throws NamingException
+    {
+        Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x13 );
+
+        stream.put( new byte[]
+            {
+                0x30, 0x11,
+                    0x04, 0x04, 'J', 'a', 'v', 'a',
+                    0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e',
+                    0x30, 0x00
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a StoredProcedure Container
+        IAsn1Container storedProcedureContainer = new StoredProcedureContainer();
+
+        // Decode a StoredProcedure message
+        try
+        {
+            storedProcedureDecoder.decode( stream, storedProcedureContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        StoredProcedure storedProcedure = ( ( StoredProcedureContainer ) storedProcedureContainer
).getStoredProcedure();
+
+        Assert.assertEquals("Java", storedProcedure.getLanguage());
+        
+        Assert.assertEquals( "execute", StringTools.utf8ToString( storedProcedure.getProcedure()
) );
+
+        Assert.assertNull( storedProcedure.getParameters() );
+        
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = storedProcedure.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
+    }
+
+    public void testDecodeStoredProcedureOneParam() throws NamingException
+    {
+        Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
+
+        ByteBuffer stream = ByteBuffer.allocate( 0x1D );
+
+        stream.put( new byte[]
+            {
+                0x30, 0x1B,
+                  0x04, 0x04, 'J', 'a', 'v', 'a',
+                  0x04, 0x07, 'e', 'x', 'e', 'c', 'u', 't', 'e',
+                  0x30, 0x0A,
+                      0x30, 0x08,
+                        0x04, 0x03, 'i', 'n', 't', 
+                        0x04, 0x01, 0x01,
+            } );
+
+        String decodedPdu = StringTools.dumpBytes( stream.array() );
+        stream.flip();
+
+        // Allocate a StoredProcedure Container
+        IAsn1Container storedProcedureContainer = new StoredProcedureContainer();
+
+        // Decode a StoredProcedure message
+        try
+        {
+            storedProcedureDecoder.decode( stream, storedProcedureContainer );
+        }
+        catch ( DecoderException de )
+        {
+            de.printStackTrace();
+            Assert.fail( de.getMessage() );
+        }
+
+        StoredProcedure storedProcedure = ( ( StoredProcedureContainer ) storedProcedureContainer
).getStoredProcedure();
+
+        Assert.assertEquals("Java", storedProcedure.getLanguage());
+        
+        Assert.assertEquals( "execute", StringTools.utf8ToString( storedProcedure.getProcedure()
) );
+
+        Assert.assertNotNull( storedProcedure.getParameters() );
+        Assert.assertEquals( 1, storedProcedure.getParameters().size() );
+
+        StoredProcedureParameter param = ( StoredProcedureParameter ) storedProcedure.getParameters().get(
0 );
+
+        Assert.assertEquals( "int", StringTools.utf8ToString( param.getType() ) );
+        Assert.assertEquals( 1, param.getValue()[0] );
+
+        // Check the encoding
+        try
+        {
+            ByteBuffer bb = storedProcedure.encode( null );
+
+            String encodedPdu = StringTools.dumpBytes( bb.array() );
+
+            assertEquals( encodedPdu, decodedPdu );
+        }
+        catch ( EncoderException ee )
+        {
+            ee.printStackTrace();
+            fail( ee.getMessage() );
+        }
     }
 }



Mime
View raw message