incubator-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: incubator-altrmi/src/test/org/apache/altrmi/test/generator BCELProxyGeneratorTestCase.java
Date Sat, 22 Feb 2003 14:53:54 GMT
hammant     2003/02/22 06:53:53

  Modified:    .        base.xml build.xml
               src/java/org/apache/altrmi/generator
                        AbstractProxyGenerator.java
                        BCELProxyGeneratorImpl.java ProxyGeneratorImpl.java
               src/test/org/apache/altrmi/test/generator
                        BCELProxyGeneratorTestCase.java
  Log:
  work on getting the bcel generator to the same level as the javac one
  
  Revision  Changes    Path
  1.2       +30 -1     incubator-altrmi/base.xml
  
  Index: base.xml
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/base.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- base.xml	16 Feb 2003 15:56:54 -0000	1.1
  +++ base.xml	22 Feb 2003 14:53:51 -0000	1.2
  @@ -22,6 +22,7 @@
       <pathelement location="${build.home}/classes"/>
       <pathelement location="${jakarta-commons-attributes.jar}"/>
       <pathelement location="${jakarta-commons-logging.jar}"/>    
  +    <pathelement location="${jakarta-bcel.jar}"/>
     </path>
   
     <taskdef name="altrmiproxies" classname="org.apache.altrmi.generator.ant.ProxyGenerationTask">
  @@ -53,7 +54,7 @@
           callbackfacades="org.apache.altrmi.test.TestCallBackListener">
         <classpath>
           <pathelement location="${build.home}/classes"/>
  -        <pathelement location="${build.home}/testclasses"/>            
  +        <pathelement location="${build.home}/testclasses"/>
         </classpath>
       </altrmiproxies> 
   
  @@ -66,6 +67,34 @@
         </classpath>
       </altrmiproxies>     
       
  +  </target>
  +
  +  <target name="generate-bcel" depends="prepare">
  +
  +    <echo>-${jakarta-bcel.jar}-</echo>
  +
  +    <altrmiproxies genname="Hello" srcgendir="${build.home}/genjava"
  +        classgendir="${build.home}/genclasses" verbose="true"
  +        interfaces="org.apache.altrmi.test.TestInterface"
  +        additionalfacades="org.apache.altrmi.test.TestInterface3,org.apache.altrmi.test.TestInterface2"
  +        callbackfacades="org.apache.altrmi.test.TestCallBackListener"
  +        generatorclass="org.apache.altrmi.generator.BCELProxyGeneratorImpl">
  +      <classpath>
  +        <pathelement location="${build.home}/classes"/>
  +        <pathelement location="${build.home}/testclasses"/>
  +      </classpath>
  +    </altrmiproxies>
  +
  +    <altrmiproxies genname="CallbackEnabledCustomStreamTestCase" srcgendir="${build.home}/genjava"
  +        classgendir="${build.home}/genclasses" verbose="true"
  +        interfaces="org.apache.altrmi.test.TestCallBackListener"
  +        generatorclass="org.apache.altrmi.generator.BCELProxyGeneratorImpl">
  +      <classpath>
  +        <pathelement location="${build.home}/classes"/>
  +        <pathelement location="${build.home}/testclasses"/>
  +      </classpath>
  +    </altrmiproxies>
  +
     </target>
   
   </project>
  
  
  
  1.5       +18 -8     incubator-altrmi/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/build.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- build.xml	17 Feb 2003 19:48:55 -0000	1.4
  +++ build.xml	22 Feb 2003 14:53:52 -0000	1.5
  @@ -43,7 +43,6 @@
           <pathelement path="${excalibur-container.jar}"/>
           <pathelement location="${qdox.jar}"/>
           <pathelement path="${phoenix-metagenerate.jar}"/>
  -        <pathelement location="${serialver.jar}"/>
           <path refid="clover.classpath"/>
       </path>
   
  @@ -302,11 +301,7 @@
           </javadoc>
       </target>
   
  -    <target name="test" depends="compile-test" description="Perform the unit tests">
  -
  -        <echo message="Performing Unit Tests"/>
  -
  -        <ant antfile="base.xml" target="generate"/>
  +    <target name="test-run">
   
           <mkdir dir="${build.tests}"/>
   
  @@ -325,7 +320,6 @@
   
                       <include name="**/${test.filter}.class"/>
                       <exclude name="**/Abstract*"/>
  -                    <exclude name="**/CustomHttpServletTestCase*"/>
                       <exclude name="**/JSXObjectStreamTestCase.class"/>
                   </fileset>
               </batchtest>
  @@ -354,7 +348,23 @@
   
       </target>
   
  -    <target name="test-reports" depends="test" description="Generate Reports for the
unit tests">
  +    <target name="test" depends="compile-test" description="Perform the unit tests">
  +
  +        <echo message="Performing Unit Tests using Javac proxy generator"/>
  +        <ant antfile="base.xml" target="generate"/>
  +        <antcall target="test-run"/>
  +
  +    </target>
  +
  +    <target name="test-bcel" depends="compile-test" description="Perform the unit tests">
  +
  +        <echo message="Performing Unit Tests using BCEL proxy generator"/>
  +        <ant antfile="base.xml" target="generate-bcel"/>
  +        <antcall target="test-run"/>
  +
  +    </target>
  +
  +    <target name="test-reports" description="Generate Reports for the unit tests">
   
           <!-- <ant antfile="${depchecker.prefix}/depchecker.xml" target="checkBSF"/>
-->
   
  
  
  
  1.4       +27 -1     incubator-altrmi/src/java/org/apache/altrmi/generator/AbstractProxyGenerator.java
  
  Index: AbstractProxyGenerator.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/generator/AbstractProxyGenerator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractProxyGenerator.java	17 Feb 2003 20:28:38 -0000	1.3
  +++ AbstractProxyGenerator.java	22 Feb 2003 14:53:52 -0000	1.4
  @@ -58,6 +58,8 @@
   import org.apache.altrmi.common.ProxyGenerationException;
   import org.apache.altrmi.server.PublicationDescriptionItem;
   
  +import java.lang.reflect.Method;
  +
   
   /**
    * Abstract parent for Proxy Generators
  @@ -341,4 +343,28 @@
          }
          return false;
       }
  +
  +    protected Method[] getGeneratableMethods(Class clazz) {
  +
  +        Method[] methods = null;
  +        try
  +        {
  +            Method ts = Object.class.getMethod("toString", new Class[0]);
  +            Method hc = Object.class.getMethod("hashCode", new Class[0]);
  +            Method[] interfaceMethods = clazz.getMethods();
  +            methods = new Method[interfaceMethods.length +2];
  +            System.arraycopy(interfaceMethods,0,methods, 0,interfaceMethods.length);
  +            methods[interfaceMethods.length] = ts;
  +            methods[interfaceMethods.length+1] = hc;
  +        }
  +        catch (NoSuchMethodException e)
  +        {
  +            // never!
  +        }
  +        return methods;
  +
  +    }
  +
  +
  +
   }
  
  
  
  1.4       +28 -17    incubator-altrmi/src/java/org/apache/altrmi/generator/BCELProxyGeneratorImpl.java
  
  Index: BCELProxyGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/generator/BCELProxyGeneratorImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BCELProxyGeneratorImpl.java	20 Feb 2003 07:36:58 -0000	1.3
  +++ BCELProxyGeneratorImpl.java	22 Feb 2003 14:53:52 -0000	1.4
  @@ -395,7 +395,8 @@
               {
                   System.out.println("ProxyGen: Processing interface: " + clazz.getName());
               }
  -            Method[] methods = clazz.getMethods();
  +            Method[] methods = getGeneratableMethods(clazz);
  +            generateEqualsMethod();
               for (int i = 0; i < methods.length; i++)
               {
                   createInterfaceMethod(generatedClassName, methods[i]);
  @@ -469,25 +470,25 @@
            * ================================================
            * try
            * {
  -             *      Object retVal = mProxyHelper.processObjectRequest("foo1(int,
  -                    float, java.lang.String, java.lang.Integer)",args,argClasses);
  -             *      return (java.lang.String) retVal;
  +         *      Object retVal = mProxyHelper.processObjectRequest("foo1(int,
  +                 float, java.lang.String, java.lang.Integer)",args,argClasses);
  +         *      return (java.lang.String) retVal;
            * }
            *  catch (Throwable t)
            *     {
  -             *         if (t instanceof RuntimeException)
  -             *         {
  -             *           throw (RuntimeException) t;
  -             *      } else if (t instanceof Error)
  -             *         {
  -             *                throw (Error) t;
  -             *      } else
  -             *         {
  -             *                t.printStackTrace();
  -             *                 throw new org.apache.altrmi.client.
  +         *         if (t instanceof RuntimeException)
  +         *         {
  +         *           throw (RuntimeException) t;
  +         *      } else if (t instanceof Error)
  +         *         {
  +         *                throw (Error) t;
  +         *      } else
  +         *         {
  +         *                t.printStackTrace();
  +         *                 throw new org.apache.altrmi.client.
                                  InvocationException("Should never get here:" +t.getMessage());
  -             *      }
  -             *     }
  +         *      }
  +         *     }
            * ================================================
            */
           InstructionHandle ihe1 = il.append(m_factory.createLoad(Type.OBJECT, 0));
  @@ -729,6 +730,16 @@
           method.setMaxLocals();
           m_classGen.addMethod(method.getMethod());
           il.dispose();
  +    }
  +
  +    private void generateEqualsMethod()
  +    {
  +        // TODO ....
  +
  +       /* public boolean equals(Object o) {
  +        *   return m_proxyHelper.isEquals(this,o);
  +        * }
  +        */
       }
   
       /**
  
  
  
  1.4       +6 -21     incubator-altrmi/src/java/org/apache/altrmi/generator/ProxyGeneratorImpl.java
  
  Index: ProxyGeneratorImpl.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/java/org/apache/altrmi/generator/ProxyGeneratorImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ProxyGeneratorImpl.java	20 Feb 2003 07:36:58 -0000	1.3
  +++ ProxyGeneratorImpl.java	22 Feb 2003 14:53:52 -0000	1.4
  @@ -244,22 +244,7 @@
                   System.out.println( "ProxyGen: Processing interface: " + clazz.getName()
);
               }
   
  -            Method[] methods = null;
  -
  -            try
  -            {
  -                Method ts = Object.class.getMethod("toString", new Class[0]);
  -                Method hc = Object.class.getMethod("hashCode", new Class[0]);
  -                Method[] interfaceMethods = clazz.getMethods();
  -                methods = new Method[interfaceMethods.length +2];
  -                System.arraycopy(interfaceMethods,0,methods, 0,interfaceMethods.length);
  -                methods[interfaceMethods.length] = ts;
  -                methods[interfaceMethods.length+1] = hc;
  -            }
  -            catch (NoSuchMethodException e)
  -            {
  -                // never!
  -            }
  +            Method[] methods = getGeneratableMethods(clazz);
   
               for( int y = 0; y < methods.length; y++ )
               {
  @@ -382,7 +367,7 @@
           if( rClass.equals( "void" ) )
           {
               classSource.println( "      m_proxyHelper.processVoidRequest(\""
  -                                  + methodSignature.toString() + "\",args);" );
  +                                  + methodSignature + "\",args);" );
           }
           else
           {
  @@ -463,7 +448,7 @@
           classSource.println( "    try {" );
           classSource.println( "      m_asyncInvocations.removeAllElements();");
           classSource.println( "      m_proxyHelper.processVoidRequest(\""
  -                              + methodSignature.toString() + "\",args);" );
  +                              + methodSignature + "\",args);" );
           classSource.println( "    } catch (Throwable t) {" );
           classSource.println( "      if (t instanceof RuntimeException) { " );
           classSource.println( "        throw (RuntimeException) t;" );
  @@ -496,7 +481,7 @@
               classSource.println(
                   "  Object retVal = m_proxyHelper.processObjectRequestGettingFacade("
                   + retClassType.getName() + ".class , \""
  -                + methodSignature.toString() + "\",args,\""
  +                + methodSignature + "\",args,\""
                   + MethodNameHelper.encodeClassName( getClassType( rClass ) ) + "\");" );
               classSource.println( "      return (" + getClassType( rClass )
                                     + ") retVal;" );
  @@ -505,7 +490,7 @@
           {
               classSource.println(
                   "      Object retVal = m_proxyHelper.processObjectRequest(\""
  -                + methodSignature.toString() + "\",args,argClasses);" );
  +                + methodSignature + "\",args,argClasses);" );
               generateReturnLine( classSource, rClass );
           }
       }
  
  
  
  1.3       +45 -54    incubator-altrmi/src/test/org/apache/altrmi/test/generator/BCELProxyGeneratorTestCase.java
  
  Index: BCELProxyGeneratorTestCase.java
  ===================================================================
  RCS file: /home/cvs/incubator-altrmi/src/test/org/apache/altrmi/test/generator/BCELProxyGeneratorTestCase.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- BCELProxyGeneratorTestCase.java	17 Feb 2003 20:29:26 -0000	1.2
  +++ BCELProxyGeneratorTestCase.java	22 Feb 2003 14:53:52 -0000	1.3
  @@ -76,32 +76,32 @@
    */
   public class BCELProxyGeneratorTestCase  extends TestCase
   {
  -    private ProxyGenerator mProxyGenerator;
  -    private Class mGeneratedProxyClass;
  -    private Object mGeneratedProxyObject;
  -	private ClientSideClassFactory mAltrmiFactory;
  +    private ProxyGenerator m_proxyGenerator;
  +    private Class m_generatedProxyClass;
  +    private Object m_generatedProxyObject;
  +	private ClientSideClassFactory m_altrmiFactory;
       /************************ TestInterface *******************/
  -    public  static final Class mTestInterfaceClass=//org.apache.altrmi.test.TestInterface.class;
  +    public  static final Class m_testInterfaceClass=//org.apache.altrmi.test.TestInterface.class;
                                                        TestRemoteInterface.class;
       public BCELProxyGeneratorTestCase(String testName)
       {
           super(testName);
       }
   
  -    private Class _createNewClass()
  +    private Class createNewClass()
       {
  -        if(mGeneratedProxyClass!=null)
  -            return mGeneratedProxyClass;
  -        mProxyGenerator.setGenName("Something");
  -        mProxyGenerator.setInterfacesToExpose(new PublicationDescriptionItem[]{
  -            new PublicationDescriptionItem(mTestInterfaceClass)});
  -        mProxyGenerator.setClassGenDir(".");
  -        mProxyGenerator.verbose(true);
  -        mProxyGenerator.generateClass(null);
  +        if(m_generatedProxyClass!=null)
  +            return m_generatedProxyClass;
  +        m_proxyGenerator.setGenName("Something");
  +        m_proxyGenerator.setInterfacesToExpose(new PublicationDescriptionItem[]{
  +            new PublicationDescriptionItem(m_testInterfaceClass)});
  +        m_proxyGenerator.setClassGenDir(".");
  +        m_proxyGenerator.verbose(true);
  +        m_proxyGenerator.generateClass(null);
   
   
  -        mGeneratedProxyClass=((BCELProxyGeneratorImpl)mProxyGenerator).getGeneratedClass("AltrmiGeneratedSomething_Main");
  -        return mGeneratedProxyClass;
  +        m_generatedProxyClass=((BCELProxyGeneratorImpl)m_proxyGenerator).getGeneratedClass("AltrmiGeneratedSomething_Main");
  +        return m_generatedProxyClass;
       }
   
   
  @@ -111,24 +111,15 @@
        */
       protected void setUp() throws Exception
       {
  -        try
  -        {
  -            mProxyGenerator =
  +        m_proxyGenerator =
                   (ProxyGenerator) Class
                       .forName("org.apache.altrmi.generator.BCELProxyGeneratorImpl")
                           .newInstance();
  -        }
  -        catch (Exception e)
  -        {
  -            e.printStackTrace();
  -
  -            throw new RuntimeException("PrimaryGenerator Impl jar not in m_classpath");
  -        }
  -        //create the Proxy Class using the BCEL Generator
  -        _createNewClass();
  -        mProxyGenerator.verbose(true);
  +          //create the Proxy Class using the BCEL Generator
  +        createNewClass();
  +        m_proxyGenerator.verbose(true);
   		//create the factory;
  -		mAltrmiFactory=new ClientSideClassFactory();
  +		m_altrmiFactory=new ClientSideClassFactory();
       }
   
   
  @@ -138,9 +129,9 @@
        */
       public void testGeneratedClassNameOfProxy()
       {
  -        assertNotNull(mProxyGenerator);
  -        assertNotNull(mGeneratedProxyClass);
  -        assertEquals(mGeneratedProxyClass.getName().equals("AltrmiGeneratedSomething_Main"),true);
  +        assertNotNull(m_proxyGenerator);
  +        assertNotNull(m_generatedProxyClass);
  +        assertEquals(m_generatedProxyClass.getName().equals("AltrmiGeneratedSomething_Main"),true);
       }
   
       /**
  @@ -151,25 +142,25 @@
        */
       public void testConstructorOfProxy() throws Exception
       {
  -        if(mGeneratedProxyClass==null)
  +        if(m_generatedProxyClass==null)
               testGeneratedClassNameOfProxy();
           TestInvocationHandler invocationHandler =new TestInvocationHandler();
  -		mAltrmiFactory.setHostContext(new DirectHostContext(invocationHandler));
  +		m_altrmiFactory.setHostContext(new DirectHostContext(invocationHandler));
           DefaultProxyHelper defaultProxyHelper =
  -                            new DefaultProxyHelper(mAltrmiFactory,
  +                            new DefaultProxyHelper(m_altrmiFactory,
                                                     invocationHandler,
                                                     "PublishedName",
                                                     "ObjectName",
                                                     new Long(1010),
                                                     new Long(3030));
   
  -        Constructor[] _constructors=  mGeneratedProxyClass.getConstructors();
  +        Constructor[] _constructors=  m_generatedProxyClass.getConstructors();
           //there shld be only 1 constructor for the generated proxy
           // one that takes BaseServedObject as the argument
           assertEquals(_constructors.length,1);
   
  -        mGeneratedProxyObject = _constructors[0].newInstance(new Object[]{defaultProxyHelper});
  -        assertNotNull(mGeneratedProxyObject);
  +        m_generatedProxyObject = _constructors[0].newInstance(new Object[]{defaultProxyHelper});
  +        assertNotNull(m_generatedProxyObject);
   
       }
   
  @@ -186,12 +177,12 @@
        */
       public void testGetReferenceIDMethodOfProxy() throws Exception
       {
  -        if(mGeneratedProxyObject==null)
  +        if(m_generatedProxyObject==null)
               testConstructorOfProxy();
   
  -        Method _getReferenceIDMethod = mGeneratedProxyClass.getMethod("altrmiGetReferenceID",new
Class[]{Object.class});
  +        Method _getReferenceIDMethod = m_generatedProxyClass.getMethod("altrmiGetReferenceID",new
Class[]{Object.class});
           assertNotNull(_getReferenceIDMethod);
  -        Object _ret = _getReferenceIDMethod.invoke(mGeneratedProxyObject,new Object[]{mAltrmiFactory});
  +        Object _ret = _getReferenceIDMethod.invoke(m_generatedProxyObject,new Object[]{m_altrmiFactory});
           assertEquals(new Long(1010),_ret);
       }
   
  @@ -206,32 +197,32 @@
        */
       public void testGeneratedMethodsPassOne() throws Exception
       {
  -        if(mGeneratedProxyObject==null)
  +        if(m_generatedProxyObject==null)
               testConstructorOfProxy();
   
   
  -        Method[] __fooMethods = mGeneratedProxyClass.getMethods();
  -        for(int i=0;i<__fooMethods.length;i++)
  +        Method[] methods = m_generatedProxyClass.getMethods();
  +        for(int i=0;i<methods.length;i++)
           {
  -            if(__fooMethods[i].getName().indexOf("test")==-1)
  +            if(methods[i].getName().indexOf("test")==-1)
               {
                   continue;
               }
  -            //System.out.println("Testing method["+__fooMethods[i].getName()+"]");
  -            Object[] _arguments= new Object[__fooMethods[i].getParameterTypes().length];
  +            //System.out.println("Testing method["+methods[i].getName()+"]");
  +            Object[] _arguments= new Object[methods[i].getParameterTypes().length];
               for(int j=0;j<_arguments.length;j++)
               {
   
  -                _arguments[j]=mTestInterfaceClass.getField(__fooMethods[i].getName()+"_arg"+j).get(null);
  -                //System.out.println("argType["+__fooMethods[i].getParameterTypes()[j]+"]arg["+j+"]"+_arguments[j]);
  +                _arguments[j]=m_testInterfaceClass.getField(methods[i].getName()+"_arg"+j).get(null);
  +                //System.out.println("argType["+methods[i].getParameterTypes()[j]+"]arg["+j+"]"+_arguments[j]);
               }
  -            if(__fooMethods[i].getParameterTypes().length==0)
  +            if(methods[i].getParameterTypes().length==0)
                   _arguments=null;
  -            Object _ret=__fooMethods[i].invoke(mGeneratedProxyObject,_arguments);
  +            Object _ret=methods[i].invoke(m_generatedProxyObject,_arguments);
   
  -            if(__fooMethods[i].getReturnType()!=Void.TYPE)
  +            if(methods[i].getReturnType()!=Void.TYPE)
               {
  -                assertEquals(mTestInterfaceClass.getField(__fooMethods[i].getName()+"_retValue").get(null),_ret);
  +                assertEquals(m_testInterfaceClass.getField(methods[i].getName()+"_retValue").get(null),_ret);
               }
           }
       }
  
  
  

Mime
View raw message