commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jcar...@apache.org
Subject svn commit: r243564 - in /jakarta/commons/sandbox/proxy/trunk: ./ src/java/org/apache/commons/proxy/factory/ src/java/org/apache/commons/proxy/factory/cglib/ src/java/org/apache/commons/proxy/factory/javassist/ src/java/org/apache/commons/proxy/factory...
Date Sat, 27 Aug 2005 23:40:31 GMT
Author: jcarman
Date: Sat Aug 27 16:40:21 2005
New Revision: 243564

URL: http://svn.apache.org/viewcvs?rev=243564&view=rev
Log:
Beefed up proxy factory test harness and improved code coverage.

Added:
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestBeanProvider.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/TestCacheEvictionEvent.java
Modified:
    jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/AbstractProxyFactory.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/cglib/CglibProxyFactory.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistProxyFactory.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/DelegatingInvocationHandler.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/ReflectionMethodInvocation.java
    jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/cache/AbstractCache.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractProxyFactoryTestCase.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/CountingProvider.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCachedProvider.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestPooledProvider.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/Echo.java
    jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java

Modified: jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml (original)
+++ jakarta/commons/sandbox/proxy/trunk/commons-proxy.iml Sat Aug 27 16:40:21 2005
@@ -2,9 +2,9 @@
 <module version="4" relativePaths="true" type="JAVA_MODULE">
   <component name="ModuleRootManager" />
   <component name="NewModuleRootManager">
-    <output url="file://$MODULE_DIR$/build/java" />
+    <output url="file://$MODULE_DIR$/target/idea-classes" />
     <exclude-output />
-    <output-test url="file://$MODULE_DIR$/build/test" />
+    <output-test url="file://$MODULE_DIR$/target/idea-test-classes" />
     <content url="file://$MODULE_DIR$">
       <sourceFolder url="file://$MODULE_DIR$/src/java" isTestSource="false" />
       <sourceFolder url="file://$MODULE_DIR$/src/test" isTestSource="true" />

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/AbstractProxyFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/AbstractProxyFactory.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/AbstractProxyFactory.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/AbstractProxyFactory.java
Sat Aug 27 16:40:21 2005
@@ -28,7 +28,12 @@
  */
 public abstract class AbstractProxyFactory implements ProxyFactory
 {
-    protected Log log = LogFactory.getLog( getClass() );
+    protected Log log;
+
+    protected AbstractProxyFactory()
+    {
+        setLog( LogFactory.getLog( getClass() ) );
+    }
 
     public void setLog( Log log )
     {

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/cglib/CglibProxyFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/cglib/CglibProxyFactory.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/cglib/CglibProxyFactory.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/cglib/CglibProxyFactory.java
Sat Aug 27 16:40:21 2005
@@ -82,7 +82,7 @@
             this.target = target;
             this.method = method;
             this.methodProxy = methodProxy;
-            this.args = args;
+            this.args = args == null || args.length == 0 ? null : args;
         }
 
         public Method getMethod()
@@ -102,12 +102,12 @@
 
         public Object getThis()
         {
-            return null;
+            return target;
         }
 
         public AccessibleObject getStaticPart()
         {
-            return null;
+            return method;
         }
     }
 

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistProxyFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistProxyFactory.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistProxyFactory.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistProxyFactory.java
Sat Aug 27 16:40:21 2005
@@ -29,6 +29,7 @@
 import org.apache.commons.proxy.exception.ProxyFactoryException;
 import org.apache.commons.proxy.factory.AbstractProxyFactory;
 
+import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Method;
 
 /**
@@ -102,24 +103,31 @@
         {
             final CtClass invocationClass = createClass();
             invocationClass.addInterface( resolve( MethodInvocation.class ) );
-            addField( targetClass, "target", invocationClass );
+            addField( Object.class, "target", invocationClass );
+            addField( Object[].class, "arguments", invocationClass );
             final Class[] argumentTypes = method.getParameterTypes();
             final Class[] constructorArgs = new Class[argumentTypes.length + 1];
             constructorArgs[0] = targetClass;
             for( int i = 0; i < argumentTypes.length; i++ )
             {
-                Class argumentType = argumentTypes[i];
-                final CtField argumentField = new CtField( resolve( argumentType ), "argument"
+ i, invocationClass );
-                invocationClass.addField( argumentField );
-                constructorArgs[i + 1] = argumentType;
+                constructorArgs[i + 1] = argumentTypes[i];
             }
             final CtConstructor constructor = new CtConstructor( resolve( constructorArgs
), invocationClass );
             final StringBuffer constructorBody = new StringBuffer( "{\n" );
             constructorBody.append( "\tthis.target = $1;\n" );
+            if( argumentTypes.length == 0 )
+            {
+                constructorBody.append( "\tthis.arguments = null;\n" );
+            }
+            else
+            {
+                constructorBody.append( "\tthis.arguments = new Object[" );
+                constructorBody.append( argumentTypes.length );
+                constructorBody.append( "];\n" );
+            }
             for( int i = 0; i < argumentTypes.length; i++ )
             {
-                constructorBody.append( "\tthis.argument" ).append( i ).append( " = $" ).append(
2 + i ).append( ";\n" );
-
+                constructorBody.append( "\tthis.arguments[" + i + "] = $" + ( i + 2 ) + ";\n"
);
             }
             constructorBody.append( "}" );
             log.debug( "Constructor body:\n" + constructorBody );
@@ -131,6 +139,33 @@
             log.debug( "Proceed method body:\n" + proceedBody );
             proceedMethod.setBody( proceedBody.toString() );
             invocationClass.addMethod( proceedMethod );
+            final CtMethod getMethodMethod = new CtMethod( resolve( Method.class ), "getMethod",
resolve( new Class[0] ), invocationClass );
+            final StringBuffer getMethodBody = new StringBuffer();
+            getMethodBody.append( "{\n\tfinal Class[] parameterTypes = new Class[" + argumentTypes.length
+ "];\n" );
+            for( int i = 0; i < argumentTypes.length; ++i )
+            {
+                getMethodBody.append( "\tparameterTypes[" + i + "] = " + argumentTypes[i].getName()
+ ".class;\n" );
+            }
+            getMethodBody.append( "\ttry\n\t{\n\t\treturn " + method.getDeclaringClass().getName()
+ ".class.getMethod(\"" + method.getName() + "\", parameterTypes );\n\t}\n\tcatch( NoSuchMethodException
e )\n\t{\n\t\treturn null;\n\t}" );
+            getMethodBody.append( "}" );
+            log.debug( "getMethod() body:\n" + getMethodBody.toString() );
+            getMethodMethod.setBody( getMethodBody.toString() );
+            invocationClass.addMethod( getMethodMethod );
+            final CtMethod getArgumentsMethod = new CtMethod( resolve( Object[].class ),
"getArguments", resolve( new Class[0] ), invocationClass );
+            final String getArgumentsBody = "{\n\treturn arguments;\n}";
+            log.debug( "getArguments() body:\n" + getArgumentsBody );
+            getArgumentsMethod.setBody( getArgumentsBody );
+            invocationClass.addMethod( getArgumentsMethod );
+            final CtMethod getStaticPartMethod = new CtMethod( resolve( AccessibleObject.class
), "getStaticPart", resolve( new Class[0] ), invocationClass );
+            final String getStaticPartBody = "{\n\treturn getMethod();\n}";
+            log.debug( "getStaticPart() body:\n" + getStaticPartBody );
+            getStaticPartMethod.setBody( getStaticPartBody );
+            invocationClass.addMethod( getStaticPartMethod );
+            final CtMethod getThisMethod = new CtMethod( resolve( Object.class ), "getThis",
resolve( new Class[0] ), invocationClass );
+            final String getThisMethodBody = "{\n\treturn target;\n}";
+            log.debug( "getThis() body:\n" + getThisMethodBody );
+            getThisMethod.setBody( getThisMethodBody );
+            invocationClass.addMethod( getThisMethod );
             return invocationClass.toClass( classLoader );
         }
         catch( CannotCompileException e )
@@ -150,10 +185,10 @@
         {
             proceedBody.append( "\t" );
         }
-        proceedBody.append( "target." ).append( method.getName() ).append( "(" );
+        proceedBody.append( "( ( " + method.getDeclaringClass().getName() + " )target )."
).append( method.getName() ).append( "(" );
         for( int i = 0; i < argumentTypes.length; ++i )
         {
-            proceedBody.append( "argument" ).append( i );
+            proceedBody.append( "(" + argumentTypes[i].getName() + ")arguments[" ).append(
i ).append( "]" );
             if( i != argumentTypes.length - 1 )
             {
                 proceedBody.append( ", " );
@@ -162,7 +197,7 @@
         proceedBody.append( ");\n" );
         if( Void.TYPE.equals( method.getReturnType() ) )
         {
-            proceedBody.append( "return null;" );
+            proceedBody.append( "\treturn null;\n" );
         }
         proceedBody.append( "}" );
         return proceedBody.toString();
@@ -210,7 +245,7 @@
     {
         try
         {
-            return classPool.get( clazz.getName() );
+            return classPool.get( getJavaClassName( clazz ) );
         }
         catch( NotFoundException e )
         {
@@ -236,5 +271,14 @@
     public static CtClass createClass( Class superclass )
     {
         return classPool.makeClass( "JavassistProxyFactoryGenerated_" + ( ++classNumber ),
resolve( superclass ) );
+    }
+
+    public static String getJavaClassName( Class inputClass )
+    {
+        if( inputClass.isArray() )
+        {
+            return getJavaClassName( inputClass.getComponentType() ) + "[]";
+        }
+        return inputClass.getName();
     }
 }

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/DelegatingInvocationHandler.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/DelegatingInvocationHandler.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/DelegatingInvocationHandler.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/DelegatingInvocationHandler.java
Sat Aug 27 16:40:21 2005
@@ -16,6 +16,7 @@
 package org.apache.commons.proxy.factory.reflect;
 
 import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
 
 /**
  * An invocation handler which delegates to another object.
@@ -29,12 +30,20 @@
 
     public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable
     {
-        return method.invoke( getDelegate(), args );
+        try
+        {
+            return method.invoke( getDelegate(), args );
+        }
+        catch( InvocationTargetException e )
+        {
+            throw e.getTargetException();
+        }
     }
 
     /**
      * A simplified proxy creation method which merely creates a proxy which supports
      * all the interfaces implemented by the delegate.
+     *
      * @return a proxy which supports all the interfaces implemented by the delegate
      */
     public Object createProxy()
@@ -45,8 +54,9 @@
     /**
      * A simplified proxy creation method which merely creates a proxy which supports
      * all the interfaces implemented by the delegate, using the specified class loader.
+     *
      * @return a proxy which supports all the interfaces implemented by the delegate,
-     * using the specified class loader.
+     *         using the specified class loader.
      */
     public Object createProxy( ClassLoader classLoader )
     {

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/ReflectionMethodInvocation.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/ReflectionMethodInvocation.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/ReflectionMethodInvocation.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/reflect/ReflectionMethodInvocation.java
Sat Aug 27 16:40:21 2005
@@ -18,11 +18,12 @@
 import org.aopalliance.intercept.MethodInvocation;
 
 import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 
 /**
  * A reflection-based implementation of the <code>MethodInvocation</code> interface.
- * 
+ *
  * @author James Carman
  * @version 1.0
  */
@@ -51,7 +52,20 @@
 
     public Object proceed() throws Throwable
     {
-        return method.invoke( target, arguments );
+        try
+        {
+            return method.invoke( target, arguments );
+        }
+        catch( InvocationTargetException e )
+        {
+            throw e.getTargetException();
+        }
+        catch( Exception e )
+        {
+            System.out.println( "An unknown exception happened:" );
+            e.printStackTrace( System.out );
+            throw e;
+        }
     }
 
     public Object getThis()

Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/cache/AbstractCache.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/cache/AbstractCache.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/cache/AbstractCache.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/cache/AbstractCache.java
Sat Aug 27 16:40:21 2005
@@ -24,7 +24,7 @@
  */
 public abstract class AbstractCache implements Cache
 {
-    protected abstract Map<Object,CachedObject> getCachedObjectMap();
+    protected abstract Map<Object, CachedObject> getCachedObjectMap();
 
     public void storeObject( Object key, Object value )
     {
@@ -44,17 +44,15 @@
 
     public void clearCache()
     {
-        for( Object cacheKey: new LinkedList<Object>( getCachedObjectMap().keySet()
) )
+        for( Object cacheKey : new LinkedList<Object>( getCachedObjectMap().keySet()
) )
         {
             final CachedObject cachedObject = getCachedObjectMap().get( cacheKey );
-            if( cachedObject != null )
+            getCachedObjectMap().remove( cacheKey );
+            if( cachedObject.getListener() != null )
             {
-                getCachedObjectMap().remove( cacheKey );
-                if( cachedObject.getListener() != null )
-                {
-                    cachedObject.getListener().objectEvicted( new CacheEvictionEvent( cacheKey,
cachedObject.getObject() ) );
-                }
+                cachedObject.getListener().objectEvicted( new CacheEvictionEvent( cacheKey,
cachedObject.getObject() ) );
             }
+
         }
     }
 

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractProxyFactoryTestCase.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractProxyFactoryTestCase.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractProxyFactoryTestCase.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/factory/AbstractProxyFactoryTestCase.java
Sat Aug 27 16:40:21 2005
@@ -15,14 +15,21 @@
  */
 package org.apache.commons.proxy.factory;
 
+import org.aopalliance.intercept.MethodInterceptor;
+import org.aopalliance.intercept.MethodInvocation;
 import org.apache.commons.proxy.ProxyFactory;
-import org.apache.commons.proxy.provider.BeanProvider;
-import org.apache.commons.proxy.provider.SingletonProvider;
+import org.apache.commons.proxy.provider.ConstantProvider;
+import static org.apache.commons.proxy.provider.ProviderUtils.beanProvider;
+import static org.apache.commons.proxy.provider.ProviderUtils.singletonProvider;
 import org.apache.commons.proxy.util.AbstractTestCase;
 import org.apache.commons.proxy.util.Echo;
 import org.apache.commons.proxy.util.EchoImpl;
 import org.apache.commons.proxy.util.SuffixMethodInterceptor;
 
+import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.Method;
+import java.io.IOException;
+
 /**
  * @author James Carman
  * @version 1.0
@@ -38,16 +45,128 @@
 
     public void testCreateProxy()
     {
-        final Echo echo = ( Echo )factory.createProxy( new SingletonProvider<Echo>(
new BeanProvider<Echo>( EchoImpl.class ) ), Echo.class );
+        final Echo echo = ( Echo ) factory.createProxy( singletonProvider( beanProvider(
EchoImpl.class ) ), Echo.class );
         echo.echo();
         assertEquals( "message", echo.echoBack( "message" ) );
+        assertEquals( "ab", echo.echoBack( "a", "b" ) );
     }
 
     public void testCreateInterceptorProxy()
     {
-        final Echo target = ( Echo )factory.createProxy( new SingletonProvider<Echo>(
new BeanProvider<Echo>( EchoImpl.class ) ), Echo.class );
-        final Echo proxy = ( Echo )factory.createInterceptorProxy( target, new SuffixMethodInterceptor(
" suffix" ), Echo.class );
+        final Echo target = ( Echo ) factory.createProxy( singletonProvider( beanProvider(
EchoImpl.class ) ), Echo.class );
+        final Echo proxy = ( Echo ) factory.createInterceptorProxy( target, new SuffixMethodInterceptor(
" suffix" ), Echo.class );
         proxy.echo();
         assertEquals( "message suffix", proxy.echoBack( "message" ) );
+    }
+
+    public void testMethodInvocationImplementation() throws Exception
+    {
+        final MethodInvocationTester tester = new MethodInvocationTester();
+        final EchoImpl target = new EchoImpl();
+        final Echo proxy = ( Echo ) factory.createInterceptorProxy( target, tester, Echo.class
);
+        proxy.echo();
+        assertNull( tester.arguments );
+        assertEquals( Echo.class.getMethod( "echo" ), tester.method );
+        assertEquals( target, tester.target );
+        assertEquals( Echo.class.getMethod( "echo" ), tester.staticPart );
+        proxy.echoBack( "Hello" );
+        assertNotNull( tester.arguments );
+        assertEquals( 1, tester.arguments.length );
+        assertEquals( "Hello", tester.arguments[0] );
+        assertEquals( Echo.class.getMethod( "echoBack", String.class ), tester.method );
+        proxy.echoBack( "Hello", "World" );
+        assertNotNull( tester.arguments );
+        assertEquals( 2, tester.arguments.length );
+        assertEquals( "Hello", tester.arguments[0] );
+        assertEquals( "World", tester.arguments[1] );
+        assertEquals( Echo.class.getMethod( "echoBack", String.class, String.class ), tester.method
);
+    }
+
+    public void testProxyWithCheckedException() throws Exception
+    {
+        final Echo proxy = ( Echo ) factory.createProxy( new ConstantProvider( new EchoImpl()
), Echo.class );
+        try
+        {
+            proxy.ioException();
+            fail();
+        }
+        catch( IOException e )
+        {
+        }
+    }
+
+    public void testProxyWithUncheckedException() throws Exception
+    {
+        final Echo proxy = ( Echo ) factory.createProxy( new ConstantProvider( new EchoImpl()
), Echo.class );
+        try
+        {
+            proxy.illegalArgument();
+            fail();
+        }
+        catch( IllegalArgumentException e )
+        {
+        }
+    }
+
+    public void testInterceptorProxyWithUncheckedException() throws Exception
+    {
+        final Echo proxy = ( Echo ) factory.createInterceptorProxy( new EchoImpl(), new NoOpMethodInterceptor(),
 Echo.class );
+        try
+        {
+            proxy.illegalArgument();
+            fail();
+        }
+        catch( IllegalArgumentException e )
+        {
+        }
+    }
+
+    public void testInterceptorProxyWithCheckedException() throws Exception
+    {
+        final Echo proxy = ( Echo ) factory.createInterceptorProxy( new EchoImpl(), new NoOpMethodInterceptor(),
 Echo.class );
+        try
+        {
+            proxy.ioException();
+            fail();
+        }
+        catch( IOException e )
+        {
+        }
+    }
+
+    public void testWithNonAccessibleTargetType()
+    {
+        final Echo proxy = ( Echo ) factory.createInterceptorProxy( new PrivateEcho(), new
NoOpMethodInterceptor(), Echo.class );
+        proxy.echo();
+
+    }
+
+    private static class PrivateEcho extends EchoImpl
+    {
+    }
+
+    private static class NoOpMethodInterceptor implements MethodInterceptor
+    {
+        public Object invoke( MethodInvocation methodInvocation ) throws Throwable
+        {
+            return methodInvocation.proceed();
+        }
+    }
+
+    private static class MethodInvocationTester implements MethodInterceptor
+    {
+        private Object[] arguments;
+        private Method method;
+        private Object target;
+        private AccessibleObject staticPart;
+
+        public Object invoke( MethodInvocation methodInvocation ) throws Throwable
+        {
+            this.arguments = methodInvocation.getArguments();
+            this.method = methodInvocation.getMethod();
+            this.target = methodInvocation.getThis();
+            this.staticPart = methodInvocation.getStaticPart();
+            return methodInvocation.proceed();
+        }
     }
 }

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/CountingProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/CountingProvider.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/CountingProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/CountingProvider.java
Sat Aug 27 16:40:21 2005
@@ -25,7 +25,7 @@
 {
     private int count = 0;
 
-    public CountingProvider( ObjectProvider<T> inner )
+    public CountingProvider( ObjectProvider<? extends T> inner )
     {
         super( inner );
     }

Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestBeanProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestBeanProvider.java?rev=243564&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestBeanProvider.java
(added)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestBeanProvider.java
Sat Aug 27 16:40:21 2005
@@ -0,0 +1,56 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.commons.proxy.provider;
+
+import junit.framework.TestCase;
+import org.apache.commons.proxy.exception.ObjectProviderException;
+
+public class TestBeanProvider extends TestCase
+{
+    public void testAbstractBeanClass()
+    {
+        try
+        {
+            new BeanProvider( Number.class ).getObject();
+            fail();
+        }
+        catch( ObjectProviderException e )
+        {
+
+        }
+    }
+
+    public void testNonAccessibleConstructor()
+    {
+        try
+        {
+            new BeanProvider( MyBean.class ).getObject();
+            fail();
+        }
+        catch( ObjectProviderException e )
+        {
+
+        }
+    }
+
+    public static class MyBean
+    {
+        private MyBean()
+        {
+
+        }
+    }
+}
\ No newline at end of file

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCachedProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCachedProvider.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCachedProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCachedProvider.java
Sat Aug 27 16:40:21 2005
@@ -41,7 +41,8 @@
     {
         final CountingProvider<Echo> counter = new CountingProvider<Echo>( new
ConstantProvider<Echo>( new EchoImpl() ) );
         final CachedProvider<Echo> provider = new CachedProvider<Echo>( counter
);
-        provider.setCache( new ThreadLocalCache() );
+        final ThreadLocalCache cache = new ThreadLocalCache();
+        provider.setCache( cache );
         final CountDownLatch latch = new CountDownLatch( 10 );
         for( int i = 0; i < 10; ++i )
         {
@@ -50,6 +51,7 @@
                 public void run()
                 {
                     provider.getObject().echoBack( "Hello, World" );
+                    cache.clearCache();
                     latch.countDown();
                 }
             }).start();

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestPooledProvider.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestPooledProvider.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestPooledProvider.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestPooledProvider.java
Sat Aug 27 16:40:21 2005
@@ -23,12 +23,13 @@
 import org.apache.commons.proxy.util.EchoImpl;
 
 import java.util.concurrent.CountDownLatch;
+import static org.apache.commons.proxy.provider.ProviderUtils.constantProvider;
 
 public class TestPooledProvider extends TestCase
 {
     public void testWithSimpleCache()
     {
-        final CountingProvider<Echo> counter = new CountingProvider<Echo>( new
ConstantProvider<Echo>( new EchoImpl() ) );
+        final CountingProvider<Echo> counter = new CountingProvider<Echo>( constantProvider(
new EchoImpl() ) );
         final PooledProvider<Echo> provider = new PooledProvider<Echo>( counter
);
         final SimpleCache cache = new SimpleCache();
         provider.setCache( cache );
@@ -43,11 +44,16 @@
 
     public void testWithThreadLocalCache() throws Exception
     {
-        final CountingProvider<Echo> counter = new CountingProvider<Echo>( new
ConstantProvider<Echo>( new EchoImpl() ) );
+        final CountingProvider<Echo> counter = new CountingProvider<Echo>( constantProvider(
new EchoImpl() ) );
         final PooledProvider<Echo> provider = new PooledProvider<Echo>( counter
);
         provider.setMaxActive( 10 );
         provider.setMinIdle( 5 );
         provider.setWhenExhaustedAction( GenericObjectPool.WHEN_EXHAUSTED_GROW );
+        provider.setMaxWait( 1000 );
+        provider.setMinEvictableIdleTimeMillis( 10000 );
+        provider.setTestOnBorrow( false );
+        provider.setTestOnReturn( false );
+        provider.setTestWhileIdle( false );
         final ThreadLocalCache cache = new ThreadLocalCache();
         provider.setCache( cache );
         final CountDownLatch goLatch = new CountDownLatch( 1 );

Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/TestCacheEvictionEvent.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/TestCacheEvictionEvent.java?rev=243564&view=auto
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/TestCacheEvictionEvent.java
(added)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/cache/TestCacheEvictionEvent.java
Sat Aug 27 16:40:21 2005
@@ -0,0 +1,28 @@
+/*
+ *  Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.commons.proxy.provider.cache;
+import junit.framework.TestCase;
+
+public class TestCacheEvictionEvent extends TestCase
+{
+    public void testConstructor()
+    {
+        final CacheEvictionEvent event = new CacheEvictionEvent( "hello", "world" );
+        assertEquals( "world", event.getSource() );
+        assertEquals( "hello", event.getCacheKey() );
+        assertEquals( "world", event.getEvictedObject() );
+    }
+}
\ No newline at end of file

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/Echo.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/Echo.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/Echo.java (original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/Echo.java Sat
Aug 27 16:40:21 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.commons.proxy.util;
 
+import java.io.IOException;
+
 /**
  * @author James Carman
  * @version 1.0
@@ -22,5 +24,9 @@
 public interface Echo
 {
     public String echoBack( String message );
+    public String echoBack( String message1, String message2 );
     public void echo();
+
+    public void ioException() throws IOException;
+    public void illegalArgument();
 }

Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java?rev=243564&r1=243563&r2=243564&view=diff
==============================================================================
--- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java
(original)
+++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java
Sat Aug 27 16:40:21 2005
@@ -15,6 +15,8 @@
  */
 package org.apache.commons.proxy.util;
 
+import java.io.IOException;
+
 /**
  * @author James Carman
  * @version 1.0
@@ -26,7 +28,22 @@
         return message;
     }
 
+    public String echoBack( String message1, String message2 )
+    {
+        return message1 + message2;
+    }
+
     public void echo()
     {
+    }
+
+    public void ioException() throws IOException
+    {
+        throw new IOException( "dummy message" );
+    }
+
+    public void illegalArgument()
+    {
+        throw new IllegalArgumentException( "dummy message" );
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message