1 22 package test.implementation.interceptor; 23 24 import javax.management.MBeanServer ; 25 import javax.management.MBeanServerFactory ; 26 import javax.management.ObjectName ; 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 44 public class SharedInterceptorTEST extends TestCase 45 implements ServerConstants, ServiceConstants 46 { 47 public SharedInterceptorTEST(String s) 48 { 49 super(s); 50 } 51 52 53 public void testSharedInterceptor() throws Exception 54 { 55 MBeanServer server = MBeanServerFactory.createMBeanServer(); 56 57 MySharedInterceptor shared = new MySharedInterceptor(); 58 59 ObjectName oname = shared.register(server); 60 61 assertTrue(server.isRegistered(new ObjectName ( 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 [] { i }, 73 new String [] { Invocation.class.getName() } 74 ); 75 76 assertTrue(i.getType().equals("something")); 77 } 78 79 public void testIsShared() throws Exception 80 { 81 MBeanServer 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 93 { 94 MBeanServer server = MBeanServerFactory.createMBeanServer(); 95 96 MySharedInterceptor shared = new MySharedInterceptor(); 97 98 assertTrue(shared.isInit == false); 99 assertTrue(shared.isStart == false); 100 101 ObjectName 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 |