directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r1075088 - in /directory/shared/branches/akarasulu: integ/src/test/java/org/apache/directory/shared/ldap/codec/api/ ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/ ldap-extras/codec/src/main/java/org/ap...
Date Sun, 27 Feb 2011 17:03:36 GMT
Author: akarasulu
Date: Sun Feb 27 17:03:35 2011
New Revision: 1075088

URL: http://svn.apache.org/viewvc?rev=1075088&view=rev
Log:
removed the use of this dumb StoredProcedure bean - still shabby code but hopefully this gets
us working

Removed:
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedure.java
Modified:
    directory/shared/branches/akarasulu/integ/src/test/java/org/apache/directory/shared/ldap/codec/api/StandaloneLdapCodecServiceTest.java
    directory/shared/branches/akarasulu/ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/StoredProcedureRequest.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureContainer.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureGrammar.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureRequestDecorator.java
    directory/shared/branches/akarasulu/ldap-extras/codec/src/test/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureTest.java

Modified: directory/shared/branches/akarasulu/integ/src/test/java/org/apache/directory/shared/ldap/codec/api/StandaloneLdapCodecServiceTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/integ/src/test/java/org/apache/directory/shared/ldap/codec/api/StandaloneLdapCodecServiceTest.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/integ/src/test/java/org/apache/directory/shared/ldap/codec/api/StandaloneLdapCodecServiceTest.java
(original)
+++ directory/shared/branches/akarasulu/integ/src/test/java/org/apache/directory/shared/ldap/codec/api/StandaloneLdapCodecServiceTest.java
Sun Feb 27 17:03:35 2011
@@ -28,6 +28,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequest;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequestImpl;
 import org.apache.directory.shared.ldap.model.message.Control;
+import org.apache.directory.shared.util.Strings;
 import org.junit.Test;
 
 
@@ -64,7 +65,7 @@ public class StandaloneLdapCodecServiceT
         StandaloneLdapCodecService codec = new StandaloneLdapCodecService();
         StoredProcedureRequest req = new StoredProcedureRequestImpl();
         req.setLanguage( "Java" );
-        req.setProcedure( "bogusProc" );
+        req.setProcedure( Strings.getBytesUtf8( "bogusProc" ) );
         
         assertNotNull( req );
         assertNotNull( codec );

Modified: directory/shared/branches/akarasulu/ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/StoredProcedureRequest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/StoredProcedureRequest.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/StoredProcedureRequest.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec-api/src/main/java/org/apache/directory/shared/ldap/extras/extended/StoredProcedureRequest.java
Sun Feb 27 17:03:35 2011
@@ -20,6 +20,8 @@
 package org.apache.directory.shared.ldap.extras.extended;
 
 
+import java.util.List;
+
 import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 
 
@@ -51,14 +53,12 @@ public interface StoredProcedureRequest 
     void setLanguage( String language );
 
 
-    /**
-     * Sets the procedure.
-     *
-     * @param procedure the new procedure
-     */
-    void setProcedure( String procedure );
-
+    byte[] getProcedure();
+    
+    
+    void setProcedure( byte[] procedure );
 
+    
     /**
      * Gets the procedure specification.
      *
@@ -119,4 +119,8 @@ public interface StoredProcedureRequest 
      */
     void addParameter( Object type, Object value );
 
+    
+    void addParameter( StoredProcedureParameter parameter );
+
+    List<StoredProcedureParameter> getParameters();
 }
\ No newline at end of file

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureContainer.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureContainer.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureContainer.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureContainer.java
Sun Feb 27 17:03:35 2011
@@ -35,7 +35,7 @@ public class StoredProcedureContainer ex
     // ----------------------------------------------------------------------------
 
     /** StoredProcedure */
-    private StoredProcedure storedProcedure;
+    private StoredProcedureRequestDecorator storedProcedure;
 
 
     // ~ Constructors
@@ -55,7 +55,7 @@ public class StoredProcedureContainer ex
     /**
      * @return Returns the ldapMessage.
      */
-    public StoredProcedure getStoredProcedure()
+    public StoredProcedureRequestDecorator getStoredProcedure()
     {
         return storedProcedure;
     }
@@ -68,7 +68,7 @@ public class StoredProcedureContainer ex
      * @param ldapMessage
      *            The ldapMessage to set.
      */
-    public void setStoredProcedure( StoredProcedure storedProcedure )
+    public void setStoredProcedure( StoredProcedureRequestDecorator storedProcedure )
     {
         this.storedProcedure = storedProcedure;
     }

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureFactory.java
Sun Feb 27 17:03:35 2011
@@ -27,7 +27,6 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequest;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureResponse;
-import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureResponseImpl;
 import org.apache.directory.shared.ldap.model.message.ExtendedRequest;
 import org.apache.directory.shared.ldap.model.message.ExtendedResponse;
@@ -69,7 +68,7 @@ public class StoredProcedureFactory impl
      */
     public StoredProcedureRequest newRequest()
     {
-        return new StoredProcedureRequestDecorator( codec, new StoredProcedureRequestImpl()
);
+        return new StoredProcedureRequestDecorator( codec );
     }
 
 
@@ -89,8 +88,12 @@ public class StoredProcedureFactory impl
      */
     public StoredProcedureRequest newRequest( byte[] value )
     {
-        StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec,
new StoredProcedureRequestImpl() );
-        req.setRequestValue( value );
+        StoredProcedureRequestDecorator req = new StoredProcedureRequestDecorator( codec
);
+        
+        if ( value != null )
+        {
+            req.setRequestValue( value );
+        }
         return req;
     }
 

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureGrammar.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureGrammar.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureGrammar.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureGrammar.java
Sun Feb 27 17:03:35 2011
@@ -28,6 +28,7 @@ import org.apache.directory.shared.asn1.
 import org.apache.directory.shared.asn1.ber.tlv.TLV;
 import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
 import org.apache.directory.shared.i18n.I18n;
+import org.apache.directory.shared.ldap.codec.api.LdapCodecServiceFactory;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureParameter;
 import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
@@ -90,7 +91,7 @@ public final class StoredProcedureGramma
                 {
                     TLV tlv = container.getCurrentTLV();
 
-                    StoredProcedure storedProcedure = null;
+                    StoredProcedureRequestDecorator storedProcedure = null;
 
                     // Store the value.
                     if ( tlv.getLength() == 0 )
@@ -110,7 +111,7 @@ public final class StoredProcedureGramma
                             LOG.debug( "SP language found: " + language );
                         }
 
-                        storedProcedure = new StoredProcedure();
+                        storedProcedure = new StoredProcedureRequestDecorator( LdapCodecServiceFactory.getSingleton()
);
                         storedProcedure.setLanguage( language );
                         container.setStoredProcedure( storedProcedure );
                     }
@@ -130,7 +131,7 @@ public final class StoredProcedureGramma
                 {
                     TLV tlv = container.getCurrentTLV();
 
-                    StoredProcedure storedProcedure = container.getStoredProcedure();
+                    StoredProcedureRequestDecorator storedProcedure = container.getStoredProcedure();
 
                     // Store the value.
                     if ( tlv.getLength() == 0 )
@@ -194,7 +195,7 @@ public final class StoredProcedureGramma
                 public void action( StoredProcedureContainer container ) throws DecoderException
                 {
                     TLV tlv = container.getCurrentTLV();
-                    StoredProcedure storedProcedure = container.getStoredProcedure();
+                    StoredProcedureRequestDecorator storedProcedure = container.getStoredProcedure();
 
                     // Store the value.
                     if ( tlv.getLength() == 0 )
@@ -240,7 +241,7 @@ public final class StoredProcedureGramma
                     StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer
) container;
 
                     TLV tlv = storedProcedureContainer.getCurrentTLV();
-                    StoredProcedure storedProcedure = storedProcedureContainer.getStoredProcedure();
+                    StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
 
                     // Store the value.
                     if ( tlv.getLength() == 0 )

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureRequestDecorator.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureRequestDecorator.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureRequestDecorator.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/main/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureRequestDecorator.java
Sun Feb 27 17:03:35 2011
@@ -20,15 +20,23 @@
 package org.apache.directory.shared.ldap.extras.extended.ads_impl;
 
 
+import java.nio.BufferOverflowException;
 import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.List;
 
 import org.apache.directory.shared.asn1.EncoderException;
+import org.apache.directory.shared.asn1.ber.tlv.TLV;
+import org.apache.directory.shared.asn1.ber.tlv.UniversalTag;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.i18n.I18n;
 import org.apache.directory.shared.ldap.codec.api.ExtendedRequestDecorator;
 import org.apache.directory.shared.ldap.codec.api.LdapCodecService;
+import org.apache.directory.shared.ldap.extras.extended.StoredProcedureParameter;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequest;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureRequestImpl;
 import org.apache.directory.shared.ldap.extras.extended.StoredProcedureResponse;
+import org.apache.directory.shared.util.Strings;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -44,18 +52,228 @@ public class StoredProcedureRequestDecor
 {
     private static final Logger LOG = LoggerFactory.getLogger( StoredProcedureRequestDecorator.class
);
 
-    private StoredProcedure procedure;
+
+    private StoredProcedureParameter currentParameter;
+    
+    /** The stored procedure length */
+    private int storedProcedureLength;
+    
+    /** The parameters length */
+    private int parametersLength;
+
+    /** The list of all parameter lengths */
+    private List<Integer> parameterLength;
+
+    /** The list of all parameter type lengths */
+    private List<Integer> paramTypeLength;
+
+    /** The list of all parameter value lengths */
+    private List<Integer> paramValueLength;
+    
+    
+    public StoredProcedureRequestDecorator( LdapCodecService codec )
+    {
+        super( codec, new StoredProcedureRequestImpl() );
+    }
+
+    
+    public StoredProcedureRequestDecorator( LdapCodecService codec, StoredProcedureRequest
decoratedRequest )
+    {
+        super( codec, decoratedRequest );
+        if ( decoratedRequest == null )
+        {
+            throw new NullPointerException( "decorated stored procedulre request is null"
);
+        }
+    }
+
     
+    public StoredProcedureParameter getCurrentParameter()
+    {
+        return currentParameter;
+    }
+
+
+    public void setCurrentParameter( StoredProcedureParameter currentParameter )
+    {
+        this.currentParameter = currentParameter;
+    }
+
     
-    public StoredProcedureRequestDecorator( LdapCodecService codec, StoredProcedureRequest
decoratedMessage )
+    /**
+     * Compute the StoredProcedure length 
+     * 
+     * 0x30 L1 
+     *   | 
+     *   +--> 0x04 L2 language
+     *   +--> 0x04 L3 procedure
+     *  [+--> 0x30 L4 (parameters)
+     *          |
+     *          +--> 0x30 L5-1 (parameter)
+     *          |      |
+     *          |      +--> 0x04 L6-1 type
+     *          |      +--> 0x04 L7-1 value
+     *          |      
+     *          +--> 0x30 L5-2 (parameter)
+     *          |      |
+     *          |      +--> 0x04 L6-2 type
+     *          |      +--> 0x04 L7-2 value
+     *          |
+     *          +--> ...
+     *          |      
+     *          +--> 0x30 L5-m (parameter)
+     *                 |
+     *                 +--> 0x04 L6-m type
+     *                 +--> 0x04 L7-m value
+     */
+    public int computeLength()
     {
-        super( codec, decoratedMessage );
+        // The language
+        byte[] languageBytes = Strings.getBytesUtf8( getDecorated().getLanguage() );
         
-        procedure = new StoredProcedure( ( StoredProcedureRequestImpl ) decoratedMessage
);
+        int languageLength = 1 + TLV.getNbBytes( languageBytes.length )
+            + languageBytes.length;
+        
+        byte[] procedure = getDecorated().getProcedure();
+        
+        // The procedure
+        int procedureLength = 1 + TLV.getNbBytes( procedure.length )
+            + procedure.length;
+        
+        // Compute parameters length value
+        if ( getDecorated().getParameters() != null )
+        {
+            parameterLength = new LinkedList<Integer>();
+            paramTypeLength = new LinkedList<Integer>();
+            paramValueLength = new LinkedList<Integer>();
+            
+            for ( StoredProcedureParameter spParam : getDecorated().getParameters() )
+            {
+                int localParameterLength = 0;
+                int localParamTypeLength = 0;
+                int localParamValueLength = 0;
+                
+                localParamTypeLength = 1 + TLV.getNbBytes( spParam.getType().length ) + spParam.getType().length;
+                localParamValueLength = 1 + TLV.getNbBytes( spParam.getValue().length ) +
spParam.getValue().length;
+                
+                localParameterLength = localParamTypeLength + localParamValueLength;
+                
+                parametersLength += 1 + TLV.getNbBytes( localParameterLength ) + localParameterLength;
+                
+                parameterLength.add( localParameterLength );
+                paramTypeLength.add( localParamTypeLength );
+                paramValueLength.add( localParamValueLength );
+            }
+        }
+        
+        int localParametersLength = 1 + TLV.getNbBytes( parametersLength ) + parametersLength;

+        storedProcedureLength = languageLength + procedureLength + localParametersLength;
+
+        return 1 + TLV.getNbBytes( storedProcedureLength ) + storedProcedureLength; 
+    }
+
+    /**
+     * Encode the StoredProcedure message to a PDU. 
+     * 
+     * @return The PDU.
+     */
+    public ByteBuffer encode() throws EncoderException
+    {
+        // Allocate the bytes buffer.
+        ByteBuffer bb = ByteBuffer.allocate( computeLength() );
+
+        try
+        {
+            // The StoredProcedure Tag
+            bb.put( UniversalTag.SEQUENCE.getValue() );
+            bb.put( TLV.getBytes( storedProcedureLength ) );
+
+            // The language
+            Value.encode( bb, getDecorated().getLanguage() );
+
+            // The procedure
+            Value.encode( bb, getDecorated().getProcedure() );
+            
+            // The parameters sequence
+            bb.put( UniversalTag.SEQUENCE.getValue() );
+            bb.put( TLV.getBytes( parametersLength ) );
+
+            // The parameters list
+            if ( ( getDecorated().getParameters() != null ) && ( getDecorated().getParameters().size()
!= 0 ) )
+            {
+                int parameterNumber = 0;
+
+                for ( StoredProcedureParameter spParam : getDecorated().getParameters() )
+                {
+                    // The parameter sequence
+                    bb.put( UniversalTag.SEQUENCE.getValue() );
+                    int localParameterLength = parameterLength.get( parameterNumber );
+                    bb.put( TLV.getBytes( localParameterLength ) );
+
+                    // The parameter type
+                    Value.encode( bb, spParam.getType() );
+
+                    // The parameter value
+                    Value.encode( bb, spParam.getValue() );
+
+                    // Go to the next parameter;
+                    parameterNumber++;
+                }
+            }
+        }
+        catch ( BufferOverflowException boe )
+        {
+            throw new EncoderException( I18n.err( I18n.ERR_04005 ) );
+        }
+
+        return bb;
     }
 
 
     /**
+     * Returns the StoredProcedure string
+     * 
+     * @return The StoredProcedure string
+     */
+    public String toString()
+    {
+
+        StringBuffer sb = new StringBuffer();
+
+        sb.append( "    StoredProcedure\n" );
+        sb.append( "        Language : '" ).append( getDecorated().getLanguage() ).append(
"'\n" );
+        sb.append( "        Procedure\n" ).append( getDecorated().getProcedureSpecification()
).append( "'\n" );
+
+        if ( ( getDecorated().getParameters() == null ) || ( getDecorated().getParameters().size()
== 0 ) )
+        {
+            sb.append( "        No parameters\n" );
+        }
+        else
+        {
+            sb.append( "        Parameters\n" );
+
+            int i = 1;
+            
+            for ( StoredProcedureParameter spParam : getDecorated().getParameters() )
+            {
+                sb.append( "            type[" ).append( i ) .append( "] : '" ).
+                    append( Strings.utf8ToString(spParam.getType()) ).append( "'\n" );
+                sb.append( "            value[" ).append( i ) .append( "] : '" ).
+                    append( Strings.dumpBytes(spParam.getValue()) ).append( "'\n" );
+            }
+        }
+
+        return sb.toString();
+    }
+
+    
+    public void setProcedure( byte[] procedure )
+    {
+        getDecorated().setProcedure( procedure );
+    }
+
+
+
+    /**
      * {@inheritDoc}
      */
     public void setRequestValue( byte[] payload )
@@ -66,7 +284,6 @@ public class StoredProcedureRequestDecor
         try
         {
             decoder.decode( ByteBuffer.wrap( payload ), container );
-            this.procedure = container.getStoredProcedure();
         }
         catch ( Exception e )
         {
@@ -85,7 +302,7 @@ public class StoredProcedureRequestDecor
         {
             try
             {
-                requestValue = procedure.encode().array();
+                requestValue = encode().array();
             }
             catch ( EncoderException e )
             {
@@ -119,15 +336,6 @@ public class StoredProcedureRequestDecor
     /**
      * {@inheritDoc}
      */
-    public void setProcedure( String procedure )
-    {
-        getDecorated().setProcedure( procedure );
-    }
-
-
-    /**
-     * {@inheritDoc}
-     */
     public String getProcedureSpecification()
     {
         return getDecorated().getProcedureSpecification();
@@ -188,4 +396,31 @@ public class StoredProcedureRequestDecor
     {
         getDecorated().addParameter( type, value );
     }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public byte[] getProcedure()
+    {
+        return getDecorated().getProcedure();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public List<StoredProcedureParameter> getParameters()
+    {
+        return getDecorated().getParameters();
+    }
+
+
+    /**
+     * {@inheritDoc}
+     */
+    public void addParameter( StoredProcedureParameter parameter )
+    {
+        getDecorated().addParameter( parameter );
+    }
 }

Modified: directory/shared/branches/akarasulu/ldap-extras/codec/src/test/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureTest.java
URL: http://svn.apache.org/viewvc/directory/shared/branches/akarasulu/ldap-extras/codec/src/test/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureTest.java?rev=1075088&r1=1075087&r2=1075088&view=diff
==============================================================================
--- directory/shared/branches/akarasulu/ldap-extras/codec/src/test/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureTest.java
(original)
+++ directory/shared/branches/akarasulu/ldap-extras/codec/src/test/java/org/apache/directory/shared/ldap/extras/extended/ads_impl/StoredProcedureTest.java
Sun Feb 27 17:03:35 2011
@@ -21,16 +21,17 @@
 package org.apache.directory.shared.ldap.extras.extended.ads_impl;
 
 
-import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertEquals; 
 import static org.junit.Assert.fail;
 
 import java.nio.ByteBuffer;
 
 import org.apache.directory.shared.asn1.EncoderException;
 import org.apache.directory.shared.asn1.ber.Asn1Decoder;
-import org.apache.directory.shared.asn1.ber.Asn1Container;
+import org.apache.directory.shared.asn1.ber.tlv.IntegerDecoder;
+import org.apache.directory.shared.asn1.ber.tlv.IntegerDecoderException;
+import org.apache.directory.shared.asn1.ber.tlv.Value;
 import org.apache.directory.shared.asn1.DecoderException;
-import org.apache.directory.shared.ldap.extras.extended.ads_impl.StoredProcedure;
 import org.apache.directory.shared.ldap.extras.extended.ads_impl.StoredProcedureContainer;
 import org.apache.directory.shared.ldap.extras.extended.ads_impl.StoredProcedureDecoder;
 import org.apache.directory.shared.util.Strings;
@@ -51,7 +52,7 @@ import com.mycila.junit.concurrent.Concu
 public class StoredProcedureTest
 {
     @Test
-    public void testDecodeStoredProcedureNParams()
+    public void testDecodeStoredProcedureNParams() throws IntegerDecoderException
     {
         Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
 
@@ -91,7 +92,7 @@ public class StoredProcedureTest
             fail( de.getMessage() );
         }
 
-        StoredProcedure storedProcedure = storedProcedureContainer.getStoredProcedure();
+        StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
 
         assertEquals("Java", storedProcedure.getLanguage());
         
@@ -99,14 +100,14 @@ public class StoredProcedureTest
 
         assertEquals( 3, storedProcedure.size() );
 
-        assertEquals( "int", storedProcedure.getParameterTypeString( 0 ) );
-        assertEquals( 1, storedProcedure.getParameterValueString( 0 ) );
+        assertEquals( "int", Strings.utf8ToString( ( byte[] ) storedProcedure.getParameterType(
0 ) ) );
+        assertEquals( 1, IntegerDecoder.parse( new Value( ( byte[] ) storedProcedure.getParameterValue(
0 ) ) ) );
 
-        assertEquals( "boolean", storedProcedure.getParameterTypeString( 1 ) );
-        assertEquals( "true", storedProcedure.getParameterValueString( 1 ) );
+        assertEquals( "boolean", Strings.utf8ToString( ( byte[] ) storedProcedure.getParameterType(
1 ) ) );
+        assertEquals( "true", Strings.utf8ToString( ( byte[] ) storedProcedure.getParameterValue(
1 ) ) );
 
-        assertEquals( "String", storedProcedure.getParameterTypeString( 2 ) );
-        assertEquals( "parameter3", storedProcedure.getParameterValueString( 2 ) );
+        assertEquals( "String", Strings.utf8ToString( ( byte[] ) storedProcedure.getParameterType(
2 ) ) );
+        assertEquals( "parameter3", Strings.utf8ToString( ( byte [] ) storedProcedure.getParameterValue(
2 ) ) );
 
         // Check the encoding
         try
@@ -141,7 +142,7 @@ public class StoredProcedureTest
         stream.flip();
 
         // Allocate a StoredProcedure Container
-        Asn1Container storedProcedureContainer = new StoredProcedureContainer();
+        StoredProcedureContainer storedProcedureContainer = new StoredProcedureContainer();
 
         // Decode a StoredProcedure message
         try
@@ -154,7 +155,7 @@ public class StoredProcedureTest
             fail( de.getMessage() );
         }
 
-        StoredProcedure storedProcedure = ( ( StoredProcedureContainer ) storedProcedureContainer
).getStoredProcedure();
+        StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
 
         assertEquals("Java", storedProcedure.getLanguage());
         
@@ -180,7 +181,7 @@ public class StoredProcedureTest
 
     
     @Test
-    public void testDecodeStoredProcedureOneParam()
+    public void testDecodeStoredProcedureOneParam() throws IntegerDecoderException
     {
         Asn1Decoder storedProcedureDecoder = new StoredProcedureDecoder();
 
@@ -201,7 +202,7 @@ public class StoredProcedureTest
         stream.flip();
 
         // Allocate a StoredProcedure Container
-        Asn1Container storedProcedureContainer = new StoredProcedureContainer();
+        StoredProcedureContainer storedProcedureContainer = new StoredProcedureContainer();
 
         // Decode a StoredProcedure message
         try
@@ -214,7 +215,7 @@ public class StoredProcedureTest
             fail( de.getMessage() );
         }
 
-        StoredProcedure storedProcedure = ( ( StoredProcedureContainer ) storedProcedureContainer
).getStoredProcedure();
+        StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();
 
         assertEquals("Java", storedProcedure.getLanguage());
         
@@ -222,8 +223,8 @@ public class StoredProcedureTest
 
         assertEquals( 1, storedProcedure.size() );
 
-        assertEquals( "int", storedProcedure.getParameterTypeString( 0 ) );
-        assertEquals( 1, storedProcedure.getParameterValueString( 0 ) );
+        assertEquals( "int", Strings.utf8ToString( ( byte[] ) storedProcedure.getParameterType(
0 ) ) );
+        assertEquals( 1, IntegerDecoder.parse( new Value( ( byte [] ) storedProcedure.getParameterValue(
0 ) ) ) );
 
         // Check the encoding
         try



Mime
View raw message