KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > proxyfactory > test > InterfaceAndMixinTestCase


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

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 /**
40  * DataSourceTestCase.
41  *
42  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
43  * @version $Revision: 44806 $
44  */

45 public class InterfaceAndMixinTestCase extends AbstractProxyTest
46 {
47    public void testInterfaceAndMixin() throws Exception JavaDoc
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 JavaDoc[]{Simple.class}),
57             new AOPProxyFactoryMixin(AnotherMixin.class, new Class JavaDoc[] {Another.class})};
58       Object JavaDoc proxy = assertCreateProxy(
59             bean,
60             new Class JavaDoc[] {Other.class, Tagging.class},
61             mixins,
62             new Class JavaDoc[] {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 JavaDoc name)
99    {
100       super(name);
101    }
102 }
103
Popular Tags