KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > aop > test > MicrocontainerJMXUnitTestCase


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.aop.test;
23
24 import javax.management.Attribute JavaDoc;
25 import javax.management.InstanceNotFoundException JavaDoc;
26 import javax.management.MBeanServerConnection JavaDoc;
27 import javax.management.MBeanInfo JavaDoc;
28 import javax.management.ObjectName JavaDoc;
29
30
31 import junit.framework.Test;
32 import junit.framework.TestSuite;
33
34
35 import org.jboss.test.JBossTestCase;
36
37 /**
38  * Sample client for the jboss container.
39  *
40  * @author <a HREF="mailto:bill@burkecentral.com">Bill Burke</a>
41  * @version $Id: JMXUnitTestCase.java 58115 2006-11-04 08:42:14Z scott.stark@jboss.org $
42  */

43
44 public class MicrocontainerJMXUnitTestCase
45         extends JBossTestCase
46 {
47    static boolean deployed = false;
48    static int test = 0;
49
50    public MicrocontainerJMXUnitTestCase(String JavaDoc name)
51    {
52       super(name);
53    }
54
55    public void testAnnotated() throws Exception JavaDoc
56    {
57       ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.aop:name=AnnotatedBean");
58       testBean(testerName);
59    }
60
61    public void testXml() throws Exception JavaDoc
62    {
63       ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.aop:name=XmlBean");
64       testBean(testerName);
65    }
66
67    public void testBeanWithCtorMethodCall() throws Exception JavaDoc
68    {
69       MBeanServerConnection JavaDoc server = getServer();
70       ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.aop:name=BeanWithCtorMethodCall");
71       MBeanInfo JavaDoc info = server.getMBeanInfo(testerName);
72       assertNotNull(info);
73       server.setAttribute(testerName, new Attribute JavaDoc("Property", 42));
74       assertEquals(42, server.getAttribute(testerName, "Property"));
75    }
76
77    public void testBeanWithDependencyFromAspect() throws Exception JavaDoc
78    {
79       //Do this twice since there was a problem with redeployment
80
doTestDeployDependencies();
81    }
82
83    public void testRedeployedBeanWithDependencyFromAspect() throws Exception JavaDoc
84    {
85       //Do this twice since there was a problem with redeployment
86
doTestDeployDependencies();
87    }
88
89    private void doTestDeployDependencies() throws Exception JavaDoc
90    {
91       deploy("aop-mc-jmxtest-has-dependency.jar");
92       try
93       {
94          MBeanServerConnection JavaDoc server = getServer();
95          ObjectName JavaDoc testerName = new ObjectName JavaDoc("jboss.aop:name=BeanWithDependency");
96          try
97          {
98             server.getMBeanInfo(testerName);
99             fail(testerName + " should not have been found");
100          }
101          catch (InstanceNotFoundException JavaDoc expected)
102          {
103          }
104
105          deploy("aop-mc-jmxtest-dependency.jar");
106          try
107          {
108             server.setAttribute(testerName, new Attribute JavaDoc("Property", 42));
109             assertEquals(42, server.getAttribute(testerName, "Property"));
110             String JavaDoc ret = (String JavaDoc)server.invoke(testerName, "someAction", new Object JavaDoc[0], new String JavaDoc[0]);
111             assertNotNull(ret);
112             assertEquals("true", ret);
113          }
114          finally
115          {
116             undeploy("aop-mc-jmxtest-dependency.jar");
117          }
118
119          try
120          {
121             server.getMBeanInfo(testerName);
122             fail(testerName + " should not have been found");
123          }
124          catch (InstanceNotFoundException JavaDoc expected)
125          {
126          }
127       }
128       finally
129       {
130          undeploy("aop-mc-jmxtest-has-dependency.jar");
131       }
132    }
133
134    private void testBean(ObjectName JavaDoc on) throws Exception JavaDoc
135    {
136       MBeanServerConnection JavaDoc server = getServer();
137       server.setAttribute(on, new Attribute JavaDoc("Property", 42));
138       assertEquals(42, server.getAttribute(on, "Property"));
139
140       Object JavaDoc ret = server.invoke(on, "someAction", new Object JavaDoc[0], new String JavaDoc[0]);
141       assertEquals("JMX42", ret);
142    }
143
144
145    public static Test suite() throws Exception JavaDoc
146    {
147       TestSuite suite = new TestSuite();
148       suite.addTest(new TestSuite(MicrocontainerJMXUnitTestCase.class));
149
150       AOPTestSetup setup = new AOPTestSetup(suite, "aop-mc-jmxtest.jar");
151       return setup;
152    }
153
154 }
155
Popular Tags