KickJava   Java API By Example, From Geeks To Geeks.

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


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.ReturningInterceptor;
33 import org.jboss.test.proxyfactory.support.Simple;
34 import org.jboss.test.proxyfactory.support.SimpleInterceptor;
35 import org.jboss.test.proxyfactory.support.SimpleMixin;
36 import org.jboss.test.proxyfactory.support.Tagging;
37
38 /**
39  * DataSourceTestCase.
40  *
41  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
42  * @version $Revision: 44806 $
43  */

44 public class HollowInterfaceAndMixinTestCase extends AbstractProxyTest
45 {
46    public void testInterfaceAndMixin() throws Exception JavaDoc
47    {
48       SimpleMixin.invoked = false;
49       SimpleInterceptor.invoked = null;
50       ReturningInterceptor.invoked = null;
51       AnotherMixin.invoked = false;
52
53       AOPProxyFactoryMixin[] mixins = {
54             new AOPProxyFactoryMixin(SimpleMixin.class, new Class JavaDoc[]{Simple.class}),
55             new AOPProxyFactoryMixin(AnotherMixin.class, new Class JavaDoc[] {Another.class})};
56       Object JavaDoc proxy = assertCreateHollowProxy(
57             new Class JavaDoc[] {Other.class, Tagging.class},
58             mixins,
59             null,
60             new Class JavaDoc[] {Other.class, Simple.class, Tagging.class, Another.class});
61
62       Simple simple = (Simple)proxy;
63       simple.doSomething();
64       assertTrue(SimpleMixin.invoked);
65       assertNotNull(SimpleInterceptor.invoked);
66       assertEquals("doSomething", SimpleInterceptor.invoked.getName());
67       assertNull(ReturningInterceptor.invoked);
68       assertFalse(AnotherMixin.invoked);
69       
70       SimpleInterceptor.invoked = null;
71       SimpleMixin.invoked = false;
72       Other other = (Other)proxy;
73       other.otherMethod();
74       assertFalse(SimpleMixin.invoked);
75       assertNotNull(ReturningInterceptor.invoked);
76       assertEquals("otherMethod", ReturningInterceptor.invoked.getName());
77       assertNull(SimpleInterceptor.invoked);
78       assertFalse(AnotherMixin.invoked);
79       
80       SimpleInterceptor.invoked = null;
81       ReturningInterceptor.invoked = null;
82       SimpleMixin.invoked = false;
83       Another another = (Another)proxy;
84       another.anotherMethod();
85       assertFalse(SimpleMixin.invoked);
86       assertNull(ReturningInterceptor.invoked);
87       assertNull(SimpleInterceptor.invoked);
88       assertTrue(AnotherMixin.invoked);
89    }
90    
91    public static Test suite()
92    {
93       return suite(HollowInterfaceAndMixinTestCase.class);
94    }
95
96    public HollowInterfaceAndMixinTestCase(String JavaDoc name)
97    {
98       super(name);
99    }
100 }
101
Popular Tags