001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.implementation.interceptor;
023:
024: import javax.management.MBeanServer;
025: import javax.management.MBeanServerFactory;
026: import javax.management.ObjectName;
027:
028: import junit.framework.TestCase;
029:
030: import org.jboss.mx.server.Invocation;
031: import org.jboss.mx.server.InvocationContext;
032: import org.jboss.mx.server.ServerConstants;
033: import org.jboss.mx.service.ServiceConstants;
034:
035: import test.implementation.interceptor.support.MySharedInterceptor;
036:
037: /**
038: *
039: * @author <a href="mailto:juha@jboss.org">Juha Lindfors</a>.
040: * @version $Revision: 57200 $
041: *
042: */
043: public class SharedInterceptorTEST extends TestCase implements
044: ServerConstants, ServiceConstants {
045: public SharedInterceptorTEST(String s) {
046: super (s);
047: }
048:
049: public void testSharedInterceptor() throws Exception {
050: MBeanServer server = MBeanServerFactory.createMBeanServer();
051:
052: MySharedInterceptor shared = new MySharedInterceptor();
053:
054: ObjectName oname = shared.register(server);
055:
056: assertTrue(server.isRegistered(new ObjectName(JBOSSMX_DOMAIN
057: + ":"
058: + "type=Interceptor,name=MySharedInterceptor,ID=0")));
059:
060: InvocationContext ic = new InvocationContext();
061: Invocation i = new Invocation();
062:
063: i.addContext(ic);
064: i.setType("bloopah");
065:
066: server.invoke(oname, "invoke", new Object[] { i },
067: new String[] { Invocation.class.getName() });
068:
069: assertTrue(i.getType().equals("something"));
070: }
071:
072: public void testIsShared() throws Exception {
073: MBeanServer server = MBeanServerFactory.createMBeanServer();
074:
075: MySharedInterceptor shared = new MySharedInterceptor();
076:
077: assertTrue(shared.isShared() == false);
078:
079: shared.register(server);
080:
081: assertTrue(shared.isShared() == true);
082: }
083:
084: public void testLifecycleCallbacks() throws Exception {
085: MBeanServer server = MBeanServerFactory.createMBeanServer();
086:
087: MySharedInterceptor shared = new MySharedInterceptor();
088:
089: assertTrue(shared.isInit == false);
090: assertTrue(shared.isStart == false);
091:
092: ObjectName oname = shared.register(server);
093:
094: assertTrue(shared.isInit == true);
095: assertTrue(shared.isStart == true);
096:
097: assertTrue(shared.isStop == false);
098: assertTrue(shared.isDestroy == false);
099:
100: server.unregisterMBean(oname);
101:
102: assertTrue(shared.isStop == true);
103: assertTrue(shared.isDestroy = true);
104: }
105:
106: }
|