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