KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > test > InterceptableUnitTestCase


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 org.jboss.test.jmx.test;
23
24 import javax.management.MBeanServerConnection JavaDoc;
25 import javax.management.ObjectName JavaDoc;
26
27 import org.jboss.test.JBossTestCase;
28
29 /**
30  * Test the Interceptable interface
31  *
32  * @author <a HREF="mailto:dimitris@jboss.org">Dimitris Andreadis</a>
33  * @version $Revision: 41510 $
34  */

35 public class InterceptableUnitTestCase extends JBossTestCase
36 {
37    public InterceptableUnitTestCase(String JavaDoc name)
38    {
39       super(name);
40    }
41
42    public void testInterceptableXMBean() throws Exception JavaDoc
43    {
44       getLog().info("+++ testInterceptableXMBean");
45
46       MBeanServerConnection JavaDoc server = getServer();
47       String JavaDoc module1 = "interceptable-xmbean.sar";
48       String JavaDoc module2 = "adderinterceptor-mbean.sar";
49
50       // make sure both modules are not deployed
51
undeployForSure(module1);
52       undeployForSure(module2);
53
54       boolean isRegistered;
55       
56       try
57       {
58          ObjectName JavaDoc target1 = new ObjectName JavaDoc("jboss.test:service=interceptable");
59          ObjectName JavaDoc target2 = new ObjectName JavaDoc("jboss.test:service=adderinterceptor");
60          
61          deploy(module1);
62          
63          isRegistered = server.isRegistered(target1);
64          assertTrue(target1 + " is registered", isRegistered);
65          
66          // check 1+1 == 2
67
Object JavaDoc[] args = new Object JavaDoc[] { new Integer JavaDoc(1), new Integer JavaDoc(1) };
68          String JavaDoc[] desc = new String JavaDoc[] { int.class.getName(), int.class.getName() };
69          
70          Integer JavaDoc result = (Integer JavaDoc) server.invoke(
71                target1,
72                "add",
73                args,
74                desc);
75          
76          assertTrue("1+1 == 2, got: " + result, result.intValue() == 2);
77          
78          // not deploy the service that will install dynamically
79
// the interceptor on target1
80
deploy(module2);
81          
82          isRegistered = server.isRegistered(target2);
83          assertTrue(target2 + " is registered", isRegistered);
84          
85          // 1+1 == 3 now!
86
result = (Integer JavaDoc) server.invoke(
87                target1,
88                "add",
89                args,
90                desc);
91          
92          assertTrue("1+1 == 3, got: " + result, result.intValue() == 3);
93          
94          undeploy(module2);
95          
96          // 1+1=2 again!
97
result = (Integer JavaDoc) server.invoke(
98                target1,
99                "add",
100                args,
101                desc);
102          
103          assertTrue("1+1 == 2, got: " + result, result.intValue() == 2);
104       }
105       finally
106       {
107          undeploy(module1);
108       }
109    }
110    
111    private void undeployForSure(String JavaDoc module)
112    {
113       try
114       {
115          undeploy(module);
116       }
117       catch (Exception JavaDoc e)
118       {
119          // ignore
120
}
121    }
122 }
123
Popular Tags