directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 30898 - in incubator/directory/snickers/trunk/ber-codec: . src/java/org/apache/snickers/ber src/test/org/apache/snickers/ber src/test/org/apache/snickers/ber/digester
Date Thu, 29 Jul 2004 05:03:26 GMT
Author: akarasulu
Date: Wed Jul 28 22:03:26 2004
New Revision: 30898

Modified:
   incubator/directory/snickers/trunk/ber-codec/   (props changed)
   incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LdapMessageTests.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
   incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
Log:
corrected tests which still depend on Snacc4J based provider

Modified: incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/java/org/apache/snickers/ber/AbstractDecoderTestCase.java
Wed Jul 28 22:03:26 2004
@@ -20,6 +20,9 @@
 import java.util.Stack ;
 import java.nio.ByteBuffer ;
 import java.util.ArrayList ;
+import java.util.Properties;
+import java.io.FileOutputStream;
+import java.io.IOException;
 
 import org.apache.commons.codec.binary.Binary ;
 import org.apache.commons.codec.DecoderException ;
@@ -30,7 +33,8 @@
 import org.apache.commons.lang.exception.ExceptionUtils ;
 
 import org.apache.ldap.common.message.Message ;
-import org.apache.ldap.common.message.MessageEncoder ;
+import org.apache.ldap.common.message.MessageEncoder;
+import org.apache.ldap.common.message.spi.Provider;
 
 import junit.framework.TestCase ;
 
@@ -249,6 +253,16 @@
      */
     public Tuple decode( byte[] bites ) throws DecoderException
     {
+        try
+        {
+            FileOutputStream out = new FileOutputStream( "./SearchRequest.ber" );
+            out.write( bites );
+        }
+        catch ( IOException e )
+        {
+            e.printStackTrace();
+        }
+
         ByteBuffer buf = ByteBuffer.wrap( bites ) ;
         int lastSize = tlvList.size() ;
         decoder.decode( buf ) ;
@@ -353,7 +367,12 @@
      */
     public Tuple decode( Message msg ) throws DecoderException
     {
-        MessageEncoder encoder = new MessageEncoder() ;
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         decode( encoder.encode( msg ) ) ;
         
         return ( Tuple ) tlvList.get( tlvList.size() - 1 ) ;
@@ -369,7 +388,12 @@
      */
     public ByteBuffer encode( Message msg )
     {
-        MessageEncoder encoder = new MessageEncoder() ;
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         return ByteBuffer.wrap( encoder.encode( msg ) ) ;
     }
 

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/EncodeDecodeTests.java
Wed Jul 28 22:03:26 2004
@@ -19,9 +19,11 @@
 
 import java.nio.ByteBuffer ;
 import java.io.ByteArrayInputStream ;
+import java.util.Properties;
 
 import org.apache.commons.codec.binary.Hex ;
 import org.apache.ldap.common.message.*;
+import org.apache.ldap.common.message.spi.Provider;
 
 import junit.framework.TestCase ;
 
@@ -42,15 +44,23 @@
         AbandonRequestImpl request = new AbandonRequestImpl( 1 ) ;
         request.setAbandoned( 3 ) ;
         
-        MessageEncoder encoder = new MessageEncoder() ;
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
         byte[] snaccBytes = encoder.encode( request ) ;
         
         String snaccEncoded = new String( Hex.encodeHex( snaccBytes ) ) ;
         System.out.println( "snacc encoded = [" + snaccEncoded + "][" 
                 + snaccBytes.length + "]" ) ;
-        
-        MessageDecoder decoder = new MessageDecoder() ;
-        AbandonRequest msg = ( AbandonRequest ) decoder.decode( null, 
+
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        MessageDecoder decoder = new MessageDecoder( env ) ;
+
+        AbandonRequest msg = ( AbandonRequest ) decoder.decode( null,
                 new ByteArrayInputStream( snaccBytes ) ) ;
         assertTrue( msg.getMessageId() == request.getMessageId() ) ;
         
@@ -70,7 +80,6 @@
         buf.flip() ;
         byte[] snickersBytes = new byte[buf.remaining()] ;
         buf.get( snickersBytes ) ;
-        String snickersEncoded = new String( Hex.encodeHex( snickersBytes ) ) ;
     }
 
 
@@ -84,14 +93,20 @@
         request.setSimple( true ) ;
         request.setVersion3( true ) ;
 
-        MessageEncoder encoder = new MessageEncoder() ;
+        // @todo replace this with the Snickers encoder or use serialized
+        // PDUs stubs for test cases rather than decoding live.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
+
         byte[] snaccBytes = encoder.encode( request ) ;
 
         String snaccEncoded = new String( Hex.encodeHex( snaccBytes ) ) ;
         System.out.println( "snacc encoded = [" + snaccEncoded + "]["
                 + snaccBytes.length + "]" ) ;
 
-        MessageDecoder decoder = new MessageDecoder() ;
+        MessageDecoder decoder = new MessageDecoder( env ) ;
         BindRequest msg = ( BindRequest ) decoder.decode( null,
                 new ByteArrayInputStream( snaccBytes ) ) ;
         assertTrue( msg.getMessageId() == request.getMessageId() ) ;
@@ -112,7 +127,6 @@
         buf.flip() ;
         byte[] snickersBytes = new byte[buf.remaining()] ;
         buf.get( snickersBytes ) ;
-        String snickersEncoded = new String( Hex.encodeHex( snickersBytes ) ) ;
 
         StringBuffer sb = new StringBuffer() ;
         root.printDepthFirst( sb, 0 ) ;

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LdapMessageTests.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LdapMessageTests.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/LdapMessageTests.java
Wed Jul 28 22:03:26 2004
@@ -88,7 +88,7 @@
      * 
      * @param msg the message to encode and decode
      * @return
-     * @throws DecoderException
+     * @throws Exception
      */
     public DefaultMutableTupleNode roundTripTest( Message msg ) throws Exception
     {
@@ -299,7 +299,7 @@
     public void testSearchMessage() throws Exception
     {
         SearchRequestImpl request = new SearchRequestImpl( 1 ) ;
-        request.setBase( "uid=akarasulu,dc=example,dc=com" ) ;
+        request.setBase( "dc=com" ) ;
         request.setDerefAliases( DerefAliasesEnum.DEREFALWAYS ) ;
         PresenceNode node = new PresenceNode( "attrib0" ) ;
         request.setFilter( node ) ;

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/TupleTreeDecoderTest.java
Wed Jul 28 22:03:26 2004
@@ -21,16 +21,17 @@
 
 import java.nio.ByteBuffer ;
 import java.util.Collections ;
+import java.util.Properties;
 
 import org.apache.commons.codec.stateful.DecoderCallback ;
 import org.apache.commons.codec.stateful.StatefulDecoder ;
 import org.apache.commons.codec.stateful.DecoderMonitorAdapter ;
 
-import org.apache.commons.lang.ArrayUtils ;
 import org.apache.commons.lang.time.StopWatch ;
 
 import org.apache.ldap.common.message.MessageEncoder ;
 import org.apache.ldap.common.message.ModifyRequestImpl ;
+import org.apache.ldap.common.message.spi.Provider;
 
 import junit.framework.TestCase ;
 
@@ -61,10 +62,7 @@
     }
     
 
-    /** empty byte buffer used for convenience */
-    private static final ByteBuffer EMPTY_BUFFER = 
-        ByteBuffer.wrap( ArrayUtils.EMPTY_BYTE_ARRAY ) ;
-    
+
     public void testTTD2() throws Exception
     {
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
@@ -92,26 +90,31 @@
     public void testTTD() throws Exception
     {
         ByteArrayOutputStream out = new ByteArrayOutputStream() ;
-        
+
         // Setup the bind request
         ModifyRequestImpl request = new ModifyRequestImpl( 17 ) ;
         request.setName( "uid=akarasulu,dc=example,dc=com" ) ;
-        
-        // Setup the ASN1 Enoder
-        MessageEncoder encoder = new MessageEncoder();
- 
+
+        // Setup the ASN1 Enoder (Snacc4J for now)
+        // @todo switch once snickers is ready or use pre-existing ber files
+        // for the test cases.
+        Properties env = new Properties();
+        env.setProperty( Provider.BERLIB_PROVIDER,
+                "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
+        MessageEncoder encoder = new MessageEncoder( env );
+
         // Send encoded request to server
         encoder.encode( null, out, request );
-        
+
         StopWatch watch = new StopWatch() ;
         watch.start() ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         decoder.setCallback( this ) ;
         decoder.decode( ByteBuffer.wrap( out.toByteArray() ) ) ;
         watch.stop() ;
-        
+
         System.out.println( "time for decode = " + watch.getTime() ) ;
-        
+
         StringBuffer buf = new StringBuffer() ;
         root.printDepthFirst( buf, 0 ) ;
         System.out.println( "tuple tlv tree =\n" + buf.toString() ) ;

Modified: incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
(original)
+++ incubator/directory/snickers/trunk/ber-codec/src/test/org/apache/snickers/ber/digester/BERDigesterTest.java
Wed Jul 28 22:03:26 2004
@@ -290,8 +290,8 @@
     public void testGetTopTag() throws Exception
     {
         assertEquals( BERDigester.NO_TOP_TAG, digester.getTopTag() ) ;
-        digester.decode( ByteBuffer.allocate( 1 ) ) ;
-        assertEquals( 0, digester.getTopTag() ) ;
+        digester.decode( ByteBuffer.wrap( new byte[] { (byte) 3} ) ) ;
+        assertFalse( BERDigester.NO_TOP_TAG == digester.getTopTag() ); ;
     }
 
 

Mime
View raw message