KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > implementation > interceptor > SharedInterceptorTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, 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 test.implementation.interceptor;
23
24 import javax.management.MBeanServer JavaDoc;
25 import javax.management.MBeanServerFactory JavaDoc;
26 import javax.management.ObjectName JavaDoc;
27
28 import junit.framework.TestCase;
29
30 import org.jboss.mx.server.Invocation;
31 import org.jboss.mx.server.InvocationContext;
32 import org.jboss.mx.server.ServerConstants;
33 import org.jboss.mx.service.ServiceConstants;
34
35 import test.implementation.interceptor.support.MySharedInterceptor;
36
37
38 /**
39  *
40  * @author <a HREF="mailto:juha@jboss.org">Juha Lindfors</a>.
41  * @version $Revision: 37459 $
42  *
43  */

44 public class SharedInterceptorTEST extends TestCase
45    implements ServerConstants, ServiceConstants
46 {
47    public SharedInterceptorTEST(String JavaDoc s)
48    {
49       super(s);
50    }
51    
52    
53    public void testSharedInterceptor() throws Exception JavaDoc
54    {
55       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
56       
57       MySharedInterceptor shared = new MySharedInterceptor();
58       
59       ObjectName JavaDoc oname = shared.register(server);
60       
61       assertTrue(server.isRegistered(new ObjectName JavaDoc(
62             JBOSSMX_DOMAIN + ":" + "type=Interceptor,name=MySharedInterceptor,ID=0"
63       )));
64       
65       InvocationContext ic = new InvocationContext();
66       Invocation i = new Invocation();
67
68       i.addContext(ic);
69       i.setType("bloopah");
70       
71       server.invoke(oname, "invoke",
72             new Object JavaDoc[] { i },
73             new String JavaDoc[] { Invocation.class.getName() }
74       );
75       
76       assertTrue(i.getType().equals("something"));
77    }
78    
79    public void testIsShared() throws Exception JavaDoc
80    {
81       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
82       
83       MySharedInterceptor shared = new MySharedInterceptor();
84       
85       assertTrue(shared.isShared() == false);
86       
87       shared.register(server);
88       
89       assertTrue(shared.isShared() == true);
90    }
91    
92    public void testLifecycleCallbacks() throws Exception JavaDoc
93    {
94       MBeanServer JavaDoc server = MBeanServerFactory.createMBeanServer();
95       
96       MySharedInterceptor shared = new MySharedInterceptor();
97       
98       assertTrue(shared.isInit == false);
99       assertTrue(shared.isStart == false);
100       
101       ObjectName JavaDoc oname = shared.register(server);
102       
103       assertTrue(shared.isInit == true);
104       assertTrue(shared.isStart == true);
105       
106       assertTrue(shared.isStop == false);
107       assertTrue(shared.isDestroy == false);
108       
109       server.unregisterMBean(oname);
110       
111       assertTrue(shared.isStop == true);
112       assertTrue(shared.isDestroy = true);
113    }
114    
115
116    
117    
118    
119 }
120
121
122
Popular Tags