1 22 package org.jboss.test.proxyfactory.test; 23 24 import java.lang.reflect.Method ; 25 26 import junit.framework.Test; 27 28 import org.jboss.aop.proxy.container.AOPProxyFactoryMixin; 29 import org.jboss.aop.proxy.container.Delegate; 30 import org.jboss.test.proxyfactory.AbstractProxyTest; 31 import org.jboss.test.proxyfactory.support.PlainBean; 32 import org.jboss.test.proxyfactory.support.Simple; 33 import org.jboss.test.proxyfactory.support.SimpleInterceptor; 34 import org.jboss.test.proxyfactory.support.SimpleMixin; 35 import org.jboss.test.proxyfactory.support.SimpleMixinWithConstructorAndDelegate; 36 37 43 public class HollowWithMixinTestCase extends AbstractProxyTest 44 { 45 public void testSimpleMixinDefaultConstructor() throws Exception 46 { 47 SimpleMixin.invoked = false; 48 SimpleInterceptor.invoked = null; 49 50 AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixin.class, new Class []{Simple.class})}; 51 Object proxy = assertCreateHollowProxy(mixins, null, Simple.class); 52 53 Simple simple = (Simple)proxy; 54 simple.doSomething(); 55 assertTrue(SimpleMixin.invoked); 56 assertNotNull(SimpleInterceptor.invoked); 57 assertEquals("doSomething", SimpleInterceptor.invoked.getName()); 58 } 59 60 public void testSimpleMixinConstructorProxyTarget() throws Exception 61 { 62 SimpleMixinWithConstructorAndDelegate.invoked = false; 63 SimpleMixinWithConstructorAndDelegate.proxy = null; 64 SimpleMixinWithConstructorAndDelegate.delegate = null; 65 66 AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixinWithConstructorAndDelegate.class, new Class []{Simple.class}, "this")}; 67 Object proxy = assertCreateHollowProxy(mixins, null, Simple.class); 68 69 System.out.println(SimpleMixinWithConstructorAndDelegate.delegate); 70 Simple simple = (Simple)proxy; 71 simple.doSomething(); 72 assertTrue(SimpleMixinWithConstructorAndDelegate.invoked); 73 assertNotNull(SimpleMixinWithConstructorAndDelegate.proxy); 74 assertEquals(proxy, SimpleMixinWithConstructorAndDelegate.proxy); 75 assertNotNull(SimpleMixinWithConstructorAndDelegate.delegate); 76 assertTrue(SimpleMixinWithConstructorAndDelegate.delegate.getClass().equals(Object .class)); 77 assertNotNull(SimpleInterceptor.invoked); 78 assertEquals("doSomething", SimpleInterceptor.invoked.getName()); 79 80 PlainBean bean = new PlainBean(); 81 ((Delegate)proxy).setDelegate(bean); 82 assertNotNull(SimpleMixinWithConstructorAndDelegate.delegate); 83 assertEquals(bean, SimpleMixinWithConstructorAndDelegate.delegate); 84 } 85 86 public static Test suite() 87 { 88 return suite(HollowWithMixinTestCase.class); 89 } 90 91 public HollowWithMixinTestCase(String name) 92 { 93 super(name); 94 } 95 } 96 | Popular Tags |