Author: jcarman Date: Mon Oct 17 10:20:02 2005 New Revision: 325936 URL: http://svn.apache.org/viewcvs?rev=325936&view=rev Log: Improving test coverage.
Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java (with props) jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java (with props) Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.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/JavassistInvocation.java jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingInterceptor.java jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/PooledProvider.java jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/ProviderUtils.java jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.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/TestCloningProvider.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/AbstractEcho.java jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/EchoImpl.java Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/ProxyUtils.java Mon Oct 17 10:20:02 2005 @@ -22,6 +22,7 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import java.util.LinkedList; /** * @author James Carman @@ -83,17 +84,16 @@ */ public static Class[] getAllInterfaces( Class cls ) { - final List interfaces = getAllInterfacesImpl( cls ); - return ( Class[] ) interfaces.toArray( new Class[interfaces.size()] ); + final List interfaces = getAllInterfacesImpl( cls, new LinkedList() ); + return interfaces == null ? null : ( Class[] ) interfaces.toArray( new Class[interfaces.size()] ); } - private static List getAllInterfacesImpl( Class cls ) + private static List getAllInterfacesImpl( Class cls, List list ) { if( cls == null ) { return null; } - List list = new ArrayList(); while( cls != null ) { Class[] interfaces = cls.getInterfaces(); @@ -103,15 +103,7 @@ { list.add( interfaces[i] ); } - List superInterfaces = getAllInterfacesImpl( interfaces[i] ); - for( Iterator it = superInterfaces.iterator(); it.hasNext(); ) - { - Class intface = ( Class ) it.next(); - if( !list.contains( intface ) ) - { - list.add( intface ); - } - } + getAllInterfacesImpl( interfaces[i], list ); } cls = cls.getSuperclass(); } @@ -193,7 +185,7 @@ return null; } Class proxyFactoryClass = classLoader.loadClass( className ); - if( proxyFactoryClass.isAssignableFrom( ProxyFactory.class ) ) + if( !ProxyFactory.class.isAssignableFrom( proxyFactoryClass ) ) { return null; } 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=325936&r1=325935&r2=325936&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 Mon Oct 17 10:20:02 2005 @@ -19,14 +19,12 @@ import net.sf.cglib.proxy.Dispatcher; import net.sf.cglib.proxy.Enhancer; import net.sf.cglib.proxy.MethodProxy; -import org.apache.commons.proxy.Invocation; import org.apache.commons.proxy.Interceptor; +import org.apache.commons.proxy.Invocation; import org.apache.commons.proxy.Invoker; import org.apache.commons.proxy.ObjectProvider; -import org.apache.commons.proxy.ProxyUtils; import org.apache.commons.proxy.factory.util.AbstractSubclassingProxyFactory; -import java.lang.reflect.AccessibleObject; import java.lang.reflect.Method; /** @@ -123,7 +121,7 @@ this.target = target; this.method = method; this.methodProxy = methodProxy; - this.args = args == null ? ProxyUtils.EMPTY_ARGUMENTS : args; + this.args = args; } public Method getMethod() @@ -144,11 +142,6 @@ public Object getProxy() { return target; - } - - public AccessibleObject getStaticPart() - { - return method; } } Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistInvocation.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistInvocation.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistInvocation.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistInvocation.java Mon Oct 17 10:20:02 2005 @@ -159,7 +159,7 @@ { this.method = method; this.target = target; - this.arguments = ( arguments == null ? ProxyUtils.EMPTY_ARGUMENTS : arguments ); + this.arguments = arguments; } //---------------------------------------------------------------------------------------------------------------------- Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/factory/javassist/JavassistUtils.java Mon Oct 17 10:20:02 2005 @@ -69,20 +69,10 @@ ctClass.addInterface( resolve( proxyInterface ) ); } } - - public static CtClass createClass() - { - return createClass( DEFAULT_BASE_NAME ); - } - + public static CtClass createClass( Class superclass ) { return createClass( DEFAULT_BASE_NAME, superclass ); - } - - public static CtClass createClass( String baseName ) - { - return createClass( baseName, Object.class ); } public synchronized static CtClass createClass( String baseName, Class superclass ) Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingInterceptor.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingInterceptor.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingInterceptor.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/interceptor/LoggingInterceptor.java Mon Oct 17 10:20:02 2005 @@ -92,7 +92,7 @@ buffer.append( "BEGIN " ); buffer.append( methodName ); buffer.append( "(" ); - int count = ( args == null ) ? 0 : args.length; + int count = args.length; for( int i = 0; i < count; i++ ) { Object arg = args[i]; Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/PooledProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/PooledProvider.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/PooledProvider.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/PooledProvider.java Mon Oct 17 10:20:02 2005 @@ -43,8 +43,13 @@ public PooledProvider( ObjectProvider inner ) { + this( inner, new GenericObjectPool.Config() ); + } + + public PooledProvider( ObjectProvider inner, GenericObjectPool.Config config ) + { super( inner ); - pool = new GenericObjectPool( new Factory() ); + pool = new GenericObjectPool( new Factory(), config ); } //---------------------------------------------------------------------------------------------------------------------- @@ -92,65 +97,6 @@ public void setCache( Cache cache ) { this.cache = cache; - } - -//---------------------------------------------------------------------------------------------------------------------- -// Other Methods -//---------------------------------------------------------------------------------------------------------------------- - - public void setMaxActive( int i ) - { - pool.setMaxActive( i ); - } - - public void setMaxIdle( int i ) - { - pool.setMaxIdle( i ); - } - - public void setMaxWait( long l ) - { - pool.setMaxWait( l ); - } - - public void setMinEvictableIdleTimeMillis( long l ) - { - pool.setMinEvictableIdleTimeMillis( l ); - } - - public void setMinIdle( int i ) - { - pool.setMinIdle( i ); - } - - public void setNumTestsPerEvictionRun( int i ) - { - pool.setNumTestsPerEvictionRun( i ); - } - - public void setTestOnBorrow( boolean b ) - { - pool.setTestOnBorrow( b ); - } - - public void setTestOnReturn( boolean b ) - { - pool.setTestOnReturn( b ); - } - - public void setTestWhileIdle( boolean b ) - { - pool.setTestWhileIdle( b ); - } - - public void setTimeBetweenEvictionRunsMillis( long l ) - { - pool.setTimeBetweenEvictionRunsMillis( l ); - } - - public void setWhenExhaustedAction( byte b ) - { - pool.setWhenExhaustedAction( b ); } //---------------------------------------------------------------------------------------------------------------------- Modified: jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/ProviderUtils.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/ProviderUtils.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/ProviderUtils.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/java/org/apache/commons/proxy/provider/ProviderUtils.java Mon Oct 17 10:20:02 2005 @@ -42,10 +42,5 @@ { return new SingletonProvider( inner ); } - - public static ObjectProvider synchronizedProvider( ObjectProvider inner ) - { - return new SynchronizedProvider( inner ); - } } Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/TestProxyUtils.java Mon Oct 17 10:20:02 2005 @@ -15,18 +15,40 @@ * limitations under the License. */ package org.apache.commons.proxy; + import junit.framework.TestCase; +import org.apache.commons.proxy.exception.ProxyFactoryException; import org.apache.commons.proxy.factory.cglib.CglibProxyFactory; import org.apache.commons.proxy.factory.javassist.JavassistProxyFactory; import org.apache.commons.proxy.factory.reflect.ReflectionProxyFactory; +import org.apache.commons.proxy.factory.util.AbstractProxyFactory; +import org.apache.commons.proxy.util.DuplicateEcho; import org.apache.commons.proxy.util.Echo; -import org.apache.commons.proxy.exception.ProxyFactoryException; +import org.apache.commons.proxy.util.EchoImpl; + +import java.io.Serializable; +import java.util.Arrays; +import java.util.Properties; public class TestProxyUtils extends TestCase { + private Properties prevProperties; + + protected void setUp() throws Exception + { + prevProperties = System.getProperties(); + System.setProperties( new Properties() ); + } + + protected void tearDown() throws Exception + { + System.setProperties( prevProperties ); + } + public void testCreateNullObject() throws Exception { - final Echo nullEcho = ( Echo )ProxyUtils.createNullObject( new JavassistProxyFactory(), new Class[] { Echo.class } ); + final Echo nullEcho = ( Echo ) ProxyUtils + .createNullObject( new JavassistProxyFactory(), new Class[]{ Echo.class } ); assertNull( nullEcho.echoBack( "hello" ) ); assertNull( nullEcho.echoBack( "hello", "world" ) ); assertEquals( ( int ) 0, nullEcho.echoBack( 12345 ) ); @@ -34,12 +56,20 @@ public void testCreateNullObjectWithClassLoader() throws Exception { - final Echo nullEcho = ( Echo )ProxyUtils.createNullObject( new JavassistProxyFactory(), Echo.class.getClassLoader(), new Class[] { Echo.class } ); + final Echo nullEcho = ( Echo ) ProxyUtils.createNullObject( new JavassistProxyFactory(), + Echo.class.getClassLoader(), + new Class[]{ Echo.class } ); assertNull( nullEcho.echoBack( "hello" ) ); assertNull( nullEcho.echoBack( "hello", "world" ) ); assertEquals( ( int ) 0, nullEcho.echoBack( 12345 ) ); } + public void testGetAllInterfaces() + { + assertNull( ProxyUtils.getAllInterfaces( null ) ); + assertEquals( Arrays.asList( new Class[] { DuplicateEcho.class, Serializable.class, Echo.class } ), Arrays.asList( ProxyUtils.getAllInterfaces( EchoImpl.class ) ) ); + } + public void testGetJavaClassName() throws Exception { assertEquals( "java.lang.Object[]", ProxyUtils.getJavaClassName( Object[].class ) ); @@ -55,15 +85,20 @@ assertEquals( "boolean", ProxyUtils.getJavaClassName( Boolean.TYPE ) ); } + + public void testGetProxyFactory() throws Exception { assertTrue( ProxyUtils.getProxyFactory() instanceof JavassistProxyFactory ); + System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, "java.lang.String" ); + assertTrue( ProxyUtils.getProxyFactory() instanceof JavassistProxyFactory ); System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, CglibProxyFactory.class.getName() ); assertTrue( ProxyUtils.getProxyFactory() instanceof CglibProxyFactory ); System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, ReflectionProxyFactory.class.getName() ); assertTrue( ProxyUtils.getProxyFactory() instanceof ReflectionProxyFactory ); System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, "" ); - ClassLoader cl = new IsolatingClassLoader( JavassistProxyFactory.class, Thread.currentThread().getContextClassLoader() ); + ClassLoader cl = new IsolatingClassLoader( JavassistProxyFactory.class, + Thread.currentThread().getContextClassLoader() ); assertTrue( ProxyUtils.getProxyFactory( cl ) instanceof CglibProxyFactory ); cl = new IsolatingClassLoader( CglibProxyFactory.class, cl ); assertTrue( ProxyUtils.getProxyFactory( cl ) instanceof ReflectionProxyFactory ); @@ -75,10 +110,22 @@ } catch( ProxyFactoryException e ) { - } } + public void testPrivateProxyFactoryConstructor() + { + System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, PrivateProxyFactory.class.getName() ); + assertTrue( ProxyUtils.getProxyFactory() instanceof JavassistProxyFactory ); + + } + + public void testNonConcreteProxyFactoryClass() + { + System.setProperty( ProxyUtils.PROXY_FACTORY_PROPERTY, AbstractProxyFactory.class.getName() ); + assertTrue( ProxyUtils.getProxyFactory() instanceof JavassistProxyFactory ); + } + private static class IsolatingClassLoader extends ClassLoader { private Class isolatedClass; @@ -96,6 +143,13 @@ throw new ClassNotFoundException( name + " not found." ); } return getParent().loadClass( name ); + } + } + + public static class PrivateProxyFactory extends ReflectionProxyFactory + { + private PrivateProxyFactory() + { } } } Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java?rev=325936&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java Mon Oct 17 10:20:02 2005 @@ -0,0 +1,27 @@ +/* $Id$ + * + * 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.exception; +import junit.framework.*; +import org.apache.commons.proxy.exception.InvocationHandlerException; + +public class TestInvocationHandlerException extends AbstractExceptionClassTestCase +{ + public TestInvocationHandlerException() + { + super( InvocationHandlerException.class ); + } +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/exception/TestInvocationHandlerException.java ------------------------------------------------------------------------------ svn:keywords = Id 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=325936&r1=325935&r2=325936&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 Mon Oct 17 10:20:02 2005 @@ -61,7 +61,7 @@ set.add( "Hello" ); } - public void testInvocationHandlerProxy() throws Exception + public void testInvokerProxy() throws Exception { final InvokerTester tester = new InvokerTester(); final Echo echo = ( Echo )factory.createInvokerProxy( tester, ECHO_ONLY ); Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java?rev=325936&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java Mon Oct 17 10:20:02 2005 @@ -0,0 +1,86 @@ +/* $Id$ + * + * 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.interceptor; + +import junit.framework.TestCase; +import org.aopalliance.intercept.MethodInterceptor; +import org.aopalliance.intercept.MethodInvocation; +import org.apache.commons.proxy.ProxyUtils; +import org.apache.commons.proxy.util.Echo; +import org.apache.commons.proxy.util.EchoImpl; + +public class TestMethodInterceptorAdapter extends TestCase +{ + public void testMethodInterception() + { + final Echo proxy = ( Echo ) ProxyUtils.getProxyFactory().createInterceptorProxy( new EchoImpl(), + new MethodInterceptorAdapter( new SuffixMethodInterceptor( + " suffix" ) ), + new Class[]{ Echo.class } ); + assertEquals( "message suffix", proxy.echoBack( "message" ) ); + } + + public void testMethodInvocationImplementation() throws Exception + { + final InterceptorTester tester = new InterceptorTester(); + final EchoImpl target = new EchoImpl(); + final Echo proxy = ( Echo ) ProxyUtils.getProxyFactory().createInterceptorProxy( target, new MethodInterceptorAdapter( tester ), new Class[] { Echo.class } ); + proxy.echo(); + assertNotNull( tester.invocation.getArguments() ); + assertEquals( 0, tester.invocation.getArguments().length ); + assertEquals( Echo.class.getMethod( "echo", new Class[] {} ), tester.invocation.getMethod() ); + assertEquals( Echo.class.getMethod( "echo", new Class[] {} ), tester.invocation.getStaticPart() ); + assertEquals( target, tester.invocation.getThis() ); + proxy.echoBack( "Hello" ); + assertNotNull( tester.invocation.getArguments() ); + assertEquals( 1, tester.invocation.getArguments().length ); + assertEquals( "Hello", tester.invocation.getArguments()[0] ); + assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class } ), tester.invocation.getMethod() ); + assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class } ), tester.invocation.getStaticPart() ); + proxy.echoBack( "Hello", "World" ); + assertNotNull( tester.invocation.getArguments() ); + assertEquals( 2, tester.invocation.getArguments().length ); + assertEquals( "Hello", tester.invocation.getArguments()[0] ); + assertEquals( "World", tester.invocation.getArguments()[1] ); + assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class, String.class } ), tester.invocation.getMethod() ); + assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class, String.class } ), tester.invocation.getStaticPart() ); + } + private static class InterceptorTester implements MethodInterceptor + { + private MethodInvocation invocation; + + public Object invoke( MethodInvocation methodInvocation ) throws Throwable + { + this.invocation = methodInvocation; + return methodInvocation.proceed(); + } + } + private class SuffixMethodInterceptor implements MethodInterceptor + { + private final String suffix; + + public SuffixMethodInterceptor( String suffix ) + { + this.suffix = suffix; + } + + public Object invoke( MethodInvocation methodInvocation ) throws Throwable + { + return methodInvocation.proceed() + suffix; + } + } +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/interceptor/TestMethodInterceptorAdapter.java ------------------------------------------------------------------------------ svn:keywords = Id Added: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java?rev=325936&view=auto ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java (added) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java Mon Oct 17 10:20:02 2005 @@ -0,0 +1,54 @@ +/* $Id$ + * + * 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.invoker; +import junit.framework.*; +import org.apache.commons.proxy.invoker.InvocationHandlerAdapter; +import org.apache.commons.proxy.util.Echo; +import org.apache.commons.proxy.ProxyUtils; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class TestInvocationHandlerAdapter extends TestCase +{ + public void testMethodInvocation() throws Exception + { + InvocationHandlerTester tester = new InvocationHandlerTester(); + final Echo echo = ( Echo ) ProxyUtils.getProxyFactory().createInvokerProxy( new InvocationHandlerAdapter( tester ), new Class[] { Echo.class } ); + echo.echoBack( "hello" ); + assertEquals( Echo.class.getMethod( "echoBack", new Class[] { String.class } ), tester.method ); + assertSame( echo, tester.proxy ); + assertNotNull( tester.arguments ); + assertEquals( 1, tester.arguments.length ); + assertEquals( "hello", tester.arguments[0] ); + } + + private class InvocationHandlerTester implements InvocationHandler + { + private Object proxy; + private Method method; + private Object[] arguments; + + public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable + { + this.proxy = proxy; + this.method = method; + this.arguments = args; + return null; + } + } +} \ No newline at end of file Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/invoker/TestInvocationHandlerAdapter.java ------------------------------------------------------------------------------ svn:keywords = Id Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCloningProvider.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCloningProvider.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCloningProvider.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/provider/TestCloningProvider.java Mon Oct 17 10:20:02 2005 @@ -27,9 +27,13 @@ { final Date now = new Date(); final CloningProvider provider = new CloningProvider( now ); - final Date clone = ( Date ) provider.getObject(); - assertEquals( now, clone ); - assertNotSame( now, clone ); + final Date clone1 = ( Date ) provider.getObject(); + assertEquals( now, clone1 ); + assertNotSame( now, clone1 ); + final Date clone2 = ( Date )provider.getObject(); + assertEquals( now, clone2 ); + assertNotSame( now, clone2 ); + assertNotSame( clone2, clone1 ); } public void testWithInvalidCloneable() 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=325936&r1=325935&r2=325936&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 Mon Oct 17 10:20:02 2005 @@ -22,6 +22,9 @@ import org.apache.commons.proxy.provider.cache.ThreadLocalCache; import org.apache.commons.proxy.util.Echo; import org.apache.commons.proxy.util.EchoImpl; +import org.apache.commons.proxy.ObjectProvider; +import org.apache.commons.proxy.ProxyUtils; +import org.apache.commons.proxy.exception.ObjectProviderException; public class TestPooledProvider extends TestCase { @@ -43,15 +46,9 @@ public void testWithThreadLocalCache() throws Exception { final CountingProvider counter = new CountingProvider( ProviderUtils.constantProvider( new EchoImpl() ) ); - final PooledProvider provider = new PooledProvider( 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 GenericObjectPool.Config config = new GenericObjectPool.Config(); + config.whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW; + final PooledProvider provider = new PooledProvider( counter, config ); final ThreadLocalCache cache = new ThreadLocalCache(); provider.setCache( cache ); final CountDown goLatch = new CountDown( 1 ); @@ -86,5 +83,30 @@ goLatch.release(); finished.acquire(); assertEquals( 10, counter.getCount() ); + } + + public void testWithExceptionFromInner() + { + final PooledProvider provider = new PooledProvider( new ExceptionProvider() ); + final SimpleCache cache = new SimpleCache(); + provider.setCache( cache ); + + final Echo echo = ( Echo )ProxyUtils.getProxyFactory().createDelegatorProxy( provider, new Class[] { Echo.class } ); + try + { + echo.echoBack( "Hello." ); + fail(); + } + catch( ObjectProviderException e ) + { + + } + } + private class ExceptionProvider implements ObjectProvider + { + public Object getObject() + { + throw new ObjectProviderException( "Ha ha!" ); + } } } Modified: jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/AbstractEcho.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/AbstractEcho.java?rev=325936&r1=325935&r2=325936&view=diff ============================================================================== --- jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/AbstractEcho.java (original) +++ jakarta/commons/sandbox/proxy/trunk/src/test/org/apache/commons/proxy/util/AbstractEcho.java Mon Oct 17 10:20:02 2005 @@ -16,11 +16,13 @@ */ package org.apache.commons.proxy.util; +import java.io.Serializable; + /** * @author James Carman * @version 1.0 */ -public abstract class AbstractEcho implements Echo +public abstract class AbstractEcho implements Echo, Serializable { public String echoBack( String message ) { 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=325936&r1=325935&r2=325936&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 Mon Oct 17 10:20:02 2005 @@ -16,12 +16,13 @@ package org.apache.commons.proxy.util; import java.io.IOException; +import java.io.Serializable; /** * @author James Carman * @version 1.0 */ -public class EchoImpl extends AbstractEcho implements DuplicateEcho +public class EchoImpl extends AbstractEcho implements DuplicateEcho, Serializable { public String echoBack( String message1, String message2 ) --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]