KickJava   Java API By Example, From Geeks To Geeks.

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


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.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 /**
36  * DataSourceTestCase.
37  *
38  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
39  * @version $Revision: 44750 $
40  */

41 public class InterceptedMixinTestCase extends AbstractProxyTest
42 {
43    public void testSimpleMixinDefaultConstructor() throws Exception JavaDoc
44    {
45       SimpleMixin.invoked = false;
46       SimpleInterceptor.invoked = null;
47
48       PlainBean bean = new PlainBean();
49       AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixin.class, new Class JavaDoc[]{Simple.class})};
50       Object JavaDoc 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 JavaDoc
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 JavaDoc[]{Simple.class}, "this")};
67       Object JavaDoc 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 JavaDoc name)
87    {
88       super(name);
89    }
90 }
91
Popular Tags