KickJava   Java API By Example, From Geeks To Geeks.

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


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.SimpleMixin;
32 import org.jboss.test.proxyfactory.support.SimpleMixinWithConstructorAndDelegate;
33
34 /**
35  * DataSourceTestCase.
36  *
37  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
38  * @version $Revision: 44750 $
39  */

40 public class SimpleMixinTestCase extends AbstractProxyTest
41 {
42    public void testSimpleMixinDefaultConstructor() throws Exception JavaDoc
43    {
44       SimpleMixin.invoked = false;
45
46       PlainBean bean = new PlainBean();
47       AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixin.class, new Class JavaDoc[]{Simple.class})};
48       Object JavaDoc proxy = assertCreateProxy(bean, mixins, Simple.class);
49
50       Simple simple = (Simple)proxy;
51       simple.doSomething();
52       assertTrue(SimpleMixin.invoked);
53    }
54    
55    public void testSimpleMixinConstructorProxyTarget() throws Exception JavaDoc
56    {
57       SimpleMixinWithConstructorAndDelegate.invoked = false;
58       SimpleMixinWithConstructorAndDelegate.proxy = null;
59       SimpleMixinWithConstructorAndDelegate.delegate = null;
60
61       PlainBean bean = new PlainBean();
62       AOPProxyFactoryMixin[] mixins = {new AOPProxyFactoryMixin(SimpleMixinWithConstructorAndDelegate.class, new Class JavaDoc[]{Simple.class}, "this")};
63       Object JavaDoc proxy = assertCreateProxy(bean, mixins, Simple.class);
64
65       Simple simple = (Simple)proxy;
66       simple.doSomething();
67       assertTrue(SimpleMixinWithConstructorAndDelegate.invoked);
68       assertNotNull(SimpleMixinWithConstructorAndDelegate.proxy);
69       assertEquals(proxy, SimpleMixinWithConstructorAndDelegate.proxy);
70       assertNotNull(SimpleMixinWithConstructorAndDelegate.delegate);
71       assertEquals(bean, SimpleMixinWithConstructorAndDelegate.delegate);
72    }
73    
74    
75    public static Test suite()
76    {
77       return suite(SimpleMixinTestCase.class);
78    }
79
80    public SimpleMixinTestCase(String JavaDoc name)
81    {
82       super(name);
83    }
84 }
85
Popular Tags