1 22 package org.jboss.test.proxyfactory.test; 23 24 import java.lang.reflect.InvocationHandler ; 25 import java.lang.reflect.Method ; 26 import java.lang.reflect.Proxy ; 27 28 import junit.framework.Test; 29 30 import org.jboss.test.proxyfactory.AbstractProxyTest; 31 import org.jboss.test.proxyfactory.support.Simple; 32 import org.jboss.test.proxyfactory.support.SimpleBean; 33 import org.jboss.test.proxyfactory.support.SimpleInterceptor; 34 35 41 public class SimpleTestCase extends AbstractProxyTest 42 { 43 private static final int iterations = 1000; 44 45 public void testSimple() throws Exception 46 { 47 SimpleBean bean = new SimpleBean(); 48 Simple simple = (Simple) assertCreateProxy(bean, Simple.class); 49 SimpleInterceptor.invoked = null; 50 simple.doSomething(); 51 assertTrue(bean.invoked); 52 Method invoked = SimpleInterceptor.invoked; 53 assertNotNull(invoked); 54 assertEquals("doSomething", invoked.getName()); 55 } 56 57 public void testStressNoProxy() throws Exception 58 { 59 for (int i = 0; i < iterations; ++i) 60 { 61 SimpleBean bean = new SimpleBean(); 62 bean.doSomething(); 63 } 64 } 65 66 public class MyInvocationHandler implements InvocationHandler 67 { 68 private Object target; 69 70 public MyInvocationHandler(Object target) 71 { 72 this.target = target; 73 } 74 75 public Object invoke(Object proxy, Method method, Object [] args) throws Throwable 76 { 77 return method.invoke(target, args); 78 } 79 } 80 81 public void testStressDynamicProxy() throws Exception 82 { 83 Class [] interfaces = new Class [] { Simple.class }; 84 ClassLoader cl = Simple.class.getClassLoader(); 85 for (int i = 0; i < iterations; ++i) 86 { 87 SimpleBean bean = new SimpleBean(); 88 InvocationHandler ih = new MyInvocationHandler(bean); 89 Simple simple = (Simple) Proxy.newProxyInstance(cl, interfaces, ih); 90 simple.doSomething(); 91 } 92 } 93 94 public void testStressProxyFactory() throws Exception 95 { 96 for (int i = 0; i < iterations; ++i) 97 { 98 SimpleBean bean = new SimpleBean(); 99 Simple simple = (Simple) createProxy(bean); 100 simple.doSomething(); 101 } 102 } 103 104 public static Test suite() 105 { 106 return suite(SimpleTestCase.class); 107 } 108 109 public SimpleTestCase(String name) 110 { 111 super(name); 112 } 113 } 114 | Popular Tags |