KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.lang.reflect.Method JavaDoc;
25
26 import junit.framework.Test;
27
28 import org.jboss.aop.proxy.container.AOPProxyFactoryMixin;
29 import org.jboss.aop.proxy.container.Delegate;
30 import org.jboss.test.proxyfactory.AbstractProxyTest;
31 import org.jboss.test.proxyfactory.support.PlainBean;
32 import org.jboss.test.proxyfactory.support.Simple;
33 import org.jboss.test.proxyfactory.support.SimpleInterceptor;
34 import org.jboss.test.proxyfactory.support.SimpleMixin;
35 import org.jboss.test.proxyfactory.support.SimpleMixinWithConstructorAndDelegate;
36
37 /**
38  * HollowTestCase.
39  *
40  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
41  * @version $Revision: 44803 $
42  */

43 public class HollowWithMixinTestCase extends AbstractProxyTest
44 {
45    public void testSimpleMixinDefaultConstructor() throws Exception JavaDoc
46    {
47       SimpleMixin.invoked = false;
48       SimpleInterceptor.invoked = null;
49
50       AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixin.class, new Class JavaDoc[]{Simple.class})};
51       Object JavaDoc proxy = assertCreateHollowProxy(mixins, null, Simple.class);
52
53       Simple simple = (Simple)proxy;
54       simple.doSomething();
55       assertTrue(SimpleMixin.invoked);
56       assertNotNull(SimpleInterceptor.invoked);
57       assertEquals("doSomething", SimpleInterceptor.invoked.getName());
58    }
59    
60    public void testSimpleMixinConstructorProxyTarget() throws Exception JavaDoc
61    {
62       SimpleMixinWithConstructorAndDelegate.invoked = false;
63       SimpleMixinWithConstructorAndDelegate.proxy = null;
64       SimpleMixinWithConstructorAndDelegate.delegate = null;
65
66       AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixinWithConstructorAndDelegate.class, new Class JavaDoc[]{Simple.class}, "this")};
67       Object JavaDoc proxy = assertCreateHollowProxy(mixins, null, Simple.class);
68
69       System.out.println(SimpleMixinWithConstructorAndDelegate.delegate);
70       Simple simple = (Simple)proxy;
71       simple.doSomething();
72       assertTrue(SimpleMixinWithConstructorAndDelegate.invoked);
73       assertNotNull(SimpleMixinWithConstructorAndDelegate.proxy);
74       assertEquals(proxy, SimpleMixinWithConstructorAndDelegate.proxy);
75       assertNotNull(SimpleMixinWithConstructorAndDelegate.delegate);
76       assertTrue(SimpleMixinWithConstructorAndDelegate.delegate.getClass().equals(Object JavaDoc.class));
77       assertNotNull(SimpleInterceptor.invoked);
78       assertEquals("doSomething", SimpleInterceptor.invoked.getName());
79       
80       PlainBean bean = new PlainBean();
81       ((Delegate)proxy).setDelegate(bean);
82       assertNotNull(SimpleMixinWithConstructorAndDelegate.delegate);
83       assertEquals(bean, SimpleMixinWithConstructorAndDelegate.delegate);
84    }
85    
86    public static Test suite()
87    {
88       return suite(HollowWithMixinTestCase.class);
89    }
90
91    public HollowWithMixinTestCase(String JavaDoc name)
92    {
93       super(name);
94    }
95 }
96
Popular Tags