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.Another; 30 import org.jboss.test.proxyfactory.support.AnotherMixin; 31 import org.jboss.test.proxyfactory.support.Other; 32 import org.jboss.test.proxyfactory.support.PlainBean; 33 import org.jboss.test.proxyfactory.support.ReturningInterceptor; 34 import org.jboss.test.proxyfactory.support.Simple; 35 import org.jboss.test.proxyfactory.support.SimpleInterceptor; 36 import org.jboss.test.proxyfactory.support.SimpleMixin; 37 import org.jboss.test.proxyfactory.support.Tagging; 38 39 45 public class InterfaceAndMixinTestCase extends AbstractProxyTest 46 { 47 public void testInterfaceAndMixin() throws Exception 48 { 49 SimpleMixin.invoked = false; 50 SimpleInterceptor.invoked = null; 51 ReturningInterceptor.invoked = null; 52 AnotherMixin.invoked = false; 53 54 PlainBean bean = new PlainBean(); 55 AOPProxyFactoryMixin[] mixins = { 56 new AOPProxyFactoryMixin(SimpleMixin.class, new Class []{Simple.class}), 57 new AOPProxyFactoryMixin(AnotherMixin.class, new Class [] {Another.class})}; 58 Object proxy = assertCreateProxy( 59 bean, 60 new Class [] {Other.class, Tagging.class}, 61 mixins, 62 new Class [] {Other.class, Simple.class, Tagging.class, Another.class}); 63 64 Simple simple = (Simple)proxy; 65 simple.doSomething(); 66 assertTrue(SimpleMixin.invoked); 67 assertNotNull(SimpleInterceptor.invoked); 68 assertEquals("doSomething", SimpleInterceptor.invoked.getName()); 69 assertNull(ReturningInterceptor.invoked); 70 assertFalse(AnotherMixin.invoked); 71 72 SimpleInterceptor.invoked = null; 73 SimpleMixin.invoked = false; 74 Other other = (Other)proxy; 75 other.otherMethod(); 76 assertFalse(SimpleMixin.invoked); 77 assertNotNull(ReturningInterceptor.invoked); 78 assertEquals("otherMethod", ReturningInterceptor.invoked.getName()); 79 assertNull(SimpleInterceptor.invoked); 80 assertFalse(AnotherMixin.invoked); 81 82 SimpleInterceptor.invoked = null; 83 ReturningInterceptor.invoked = null; 84 SimpleMixin.invoked = false; 85 Another another = (Another)proxy; 86 another.anotherMethod(); 87 assertFalse(SimpleMixin.invoked); 88 assertNull(ReturningInterceptor.invoked); 89 assertNull(SimpleInterceptor.invoked); 90 assertTrue(AnotherMixin.invoked); 91 } 92 93 public static Test suite() 94 { 95 return suite(InterfaceAndMixinTestCase.class); 96 } 97 98 public InterfaceAndMixinTestCase(String name) 99 { 100 super(name); 101 } 102 } 103 | Popular Tags |