directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 56426 - in incubator/directory/snickers/trunk/ldap-ber-provider/src: java/org/apache/snickers/ldap test/org/apache/snickers/ldap test/org/apache/snickers/ldap/decoder/testutils test/org/apache/snickers/ldap/encoder test/org/apache/snickers/ldap/encoder/add
Date Tue, 02 Nov 2004 22:00:19 GMT
Author: akarasulu
Date: Tue Nov  2 14:00:18 2004
New Revision: 56426

Modified:
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersEncoder.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTestCase.java
   incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
Log:
fixed bugs and changed out interfaces on encoder

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersEncoder.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersEncoder.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersEncoder.java
Tue Nov  2 14:00:18 2004
@@ -16,11 +16,12 @@
  */
 package org.apache.snickers.ldap;
 
-import org.apache.ldap.common.message.spi.EncoderSpi;
 import org.apache.ldap.common.message.spi.ProviderException;
 import org.apache.ldap.common.message.spi.Provider;
+import org.apache.ldap.common.message.spi.ProviderEncoder;
 import org.apache.commons.codec.stateful.EncoderCallback;
 import org.apache.commons.codec.stateful.StatefulEncoder;
+import org.apache.commons.codec.stateful.EncoderMonitor;
 import org.apache.commons.codec.EncoderException;
 import org.apache.snickers.ldap.encoder.SnickersLdapEncoder;
 import org.apache.snickers.ber.digester.rules.ByteAccumulator;
@@ -35,10 +36,10 @@
 /**
  * Snickers LDAP BER provider's encoder.
  *
- * @author <a href="mailto:directory-dev@incubator.apache.org"> Apache Directory
- *         Project</a> $Rev$
+ * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
+ * @version $Rev$
  */
-public class SnickersEncoder implements EncoderSpi
+public class SnickersEncoder implements ProviderEncoder
 {
     private final Provider provider;
     private final OutputCallback outCb;
@@ -56,7 +57,7 @@
     }
 
 
-    public void encode( Object lock, OutputStream out, Object obj )
+    public void encodeBlocking( Object lock, OutputStream out, Object obj )
             throws ProviderException
     {
         synchronized( encoder )
@@ -78,7 +79,29 @@
     }
 
 
-    public byte[] encode( Object obj ) throws ProviderException
+    public ByteBuffer encodeBlocking( Object obj ) throws ProviderException
+    {
+        synchronized( encoder )
+        {
+            encoder.setCallback( accCb );
+
+            try
+            {
+                encoder.encode( obj );
+            }
+            catch ( EncoderException e )
+            {
+                ProviderException pe = new ProviderException( provider,
+                        "Snickers encoder failed to encode object: " + obj );
+                throw pe;
+            }
+
+            return accCb.getEncoded() ;
+        }
+    }
+
+
+    public byte[] encodeToArray( Object obj ) throws ProviderException
     {
         synchronized( encoder )
         {
@@ -108,6 +131,24 @@
     public Provider getProvider()
     {
         return provider;
+    }
+
+
+    public void encode( Object obj ) throws EncoderException
+    {
+        this.encoder.encode( obj );
+    }
+
+
+    public void setCallback( EncoderCallback cb )
+    {
+        this.encoder.setCallback( cb );
+    }
+
+
+    public void setEncoderMonitor( EncoderMonitor monitor )
+    {
+        encoder.setEncoderMonitor( monitor );
     }
 
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/java/org/apache/snickers/ldap/SnickersProvider.java
Tue Nov  2 14:00:18 2004
@@ -74,7 +74,7 @@
      * @throws org.apache.ldap.common.message.spi.ProviderException
      *          if the provider or its encoder cannot be found
      */
-    public EncoderSpi getEncoder() throws ProviderException
+    public ProviderEncoder getEncoder() throws ProviderException
     {
         return encoder;
     }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/SnickersDecoderTest.java
Tue Nov  2 14:00:18 2004
@@ -21,6 +21,7 @@
 import java.io.InputStream;
 import java.io.ByteArrayInputStream;
 import java.util.Properties;
+import java.nio.ByteBuffer;
 
 import org.apache.ldap.common.message.Message;
 import org.apache.ldap.common.message.MessageEncoder;
@@ -86,6 +87,9 @@
         env.setProperty( Provider.BERLIB_PROVIDER,
                 "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
         MessageEncoder encoder = new MessageEncoder( env );
-        return new ByteArrayInputStream( encoder.encode( msg ) );
+        ByteBuffer buf = encoder.encodeBlocking( msg );
+        byte[] bites = new byte[buf.remaining()];
+        buf.get( bites );
+        return new ByteArrayInputStream( bites );
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/RuleTestCase.java
Tue Nov  2 14:00:18 2004
@@ -72,16 +72,12 @@
 
     public ByteBuffer snaccEncode( Message req )
     {
-        ByteBuffer buf = null ;
-
         // @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 );
-        buf = ByteBuffer.wrap( encoder.encode( req ) ) ;
-
-        return buf ;
+        return encoder.encodeBlocking( req );
     }
 }

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/decoder/testutils/TestUtils.java
Tue Nov  2 14:00:18 2004
@@ -57,7 +57,7 @@
         env.setProperty( Provider.BERLIB_PROVIDER,
                 "org.apache.ldap.common.berlib.snacc.SnaccProvider" );
         MessageEncoder encoder = new MessageEncoder( env );
-        ByteBuffer buf = ByteBuffer.wrap( encoder.encode( pdu ) ) ;
+        ByteBuffer buf = encoder.encodeBlocking( pdu ) ;
         TupleTreeDecoder decoder = new TupleTreeDecoder() ;
         CallbackHistory cb = new CallbackHistory() ;
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTestCase.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTestCase.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/AbstractEncoderTestCase.java
Tue Nov  2 14:00:18 2004
@@ -137,7 +137,7 @@
         MessageDecoder decoder = new MessageDecoder( env );
         ByteArrayInputStream in = new ByteArrayInputStream( accumulator.array(),
                 0, accumulator.position() );
-        return decoder.decode( null, in );
+        return ( Message ) decoder.decode( null, in );
     }
 
 

Modified: incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
==============================================================================
--- incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
(original)
+++ incubator/directory/snickers/trunk/ldap-ber-provider/src/test/org/apache/snickers/ldap/encoder/add/AddRequestEncoderTest.java
Tue Nov  2 14:00:18 2004
@@ -17,6 +17,9 @@
 package org.apache.snickers.ldap.encoder.add;
 
 
+import javax.naming.directory.Attribute;
+import javax.naming.NamingException;
+
 import org.apache.snickers.ldap.encoder.AbstractEncoderTestCase;
 
 import org.apache.snickers.ber.TupleNode;
@@ -36,7 +39,7 @@
     /**
      * Tests the encode method.
      */
-    public void testEncode()
+    public void testEncode() throws NamingException
     {
         AddRequestImpl request = new AddRequestImpl( 33 );
         request.setName( "dc=apache,dc=org" );
@@ -51,6 +54,25 @@
         encode( ( DefaultMutableTupleNode ) node );
 
         // Test to see if original stub equals the round trip generated stub
-        assertTrue( request.equals( decode() ) );
+        AddRequest decoded = ( AddRequest ) super.decode();
+
+        /*
+         * Snacc is not preserving attribute order for some reason when building
+         * attributes so we are going to manually test things instead.
+         */
+        assertEquals( request.getName(), decoded.getName() );
+        assertEquals( request.getResponseType(), decoded.getResponseType() );
+        assertEquals( request.getType(), decoded.getType() );
+
+        // when there is one attribute we do not see the bug in snacc4j
+        assertEquals( request.getEntry().get( "dc" ), decoded.getEntry().get( "dc" ) );
+        Attribute objectClass = request.getEntry().get( "objectClass" );
+        Attribute decodedObjectClass = decoded.getEntry().get( "objectClass" );
+
+        assertEquals( objectClass.size(), decodedObjectClass.size() );
+        for ( int ii = 0; ii < objectClass.size(); ii++ )
+        {
+            assertTrue( decodedObjectClass.contains( objectClass.get( ii ) ) );
+        }
     }
 }

Mime
View raw message