1 22 package org.jboss.test.aop.test; 23 24 import javax.management.Attribute ; 25 import javax.management.InstanceNotFoundException ; 26 import javax.management.MBeanServerConnection ; 27 import javax.management.MBeanInfo ; 28 import javax.management.ObjectName ; 29 30 31 import junit.framework.Test; 32 import junit.framework.TestSuite; 33 34 35 import org.jboss.test.JBossTestCase; 36 37 43 44 public class MicrocontainerJMXUnitTestCase 45 extends JBossTestCase 46 { 47 static boolean deployed = false; 48 static int test = 0; 49 50 public MicrocontainerJMXUnitTestCase(String name) 51 { 52 super(name); 53 } 54 55 public void testAnnotated() throws Exception 56 { 57 ObjectName testerName = new ObjectName ("jboss.aop:name=AnnotatedBean"); 58 testBean(testerName); 59 } 60 61 public void testXml() throws Exception 62 { 63 ObjectName testerName = new ObjectName ("jboss.aop:name=XmlBean"); 64 testBean(testerName); 65 } 66 67 public void testBeanWithCtorMethodCall() throws Exception 68 { 69 MBeanServerConnection server = getServer(); 70 ObjectName testerName = new ObjectName ("jboss.aop:name=BeanWithCtorMethodCall"); 71 MBeanInfo info = server.getMBeanInfo(testerName); 72 assertNotNull(info); 73 server.setAttribute(testerName, new Attribute ("Property", 42)); 74 assertEquals(42, server.getAttribute(testerName, "Property")); 75 } 76 77 public void testBeanWithDependencyFromAspect() throws Exception 78 { 79 doTestDeployDependencies(); 81 } 82 83 public void testRedeployedBeanWithDependencyFromAspect() throws Exception 84 { 85 doTestDeployDependencies(); 87 } 88 89 private void doTestDeployDependencies() throws Exception 90 { 91 deploy("aop-mc-jmxtest-has-dependency.jar"); 92 try 93 { 94 MBeanServerConnection server = getServer(); 95 ObjectName testerName = new ObjectName ("jboss.aop:name=BeanWithDependency"); 96 try 97 { 98 server.getMBeanInfo(testerName); 99 fail(testerName + " should not have been found"); 100 } 101 catch (InstanceNotFoundException expected) 102 { 103 } 104 105 deploy("aop-mc-jmxtest-dependency.jar"); 106 try 107 { 108 server.setAttribute(testerName, new Attribute ("Property", 42)); 109 assertEquals(42, server.getAttribute(testerName, "Property")); 110 String ret = (String )server.invoke(testerName, "someAction", new Object [0], new String [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 expected) 125 { 126 } 127 } 128 finally 129 { 130 undeploy("aop-mc-jmxtest-has-dependency.jar"); 131 } 132 } 133 134 private void testBean(ObjectName on) throws Exception 135 { 136 MBeanServerConnection server = getServer(); 137 server.setAttribute(on, new Attribute ("Property", 42)); 138 assertEquals(42, server.getAttribute(on, "Property")); 139 140 Object ret = server.invoke(on, "someAction", new Object [0], new String [0]); 141 assertEquals("JMX42", ret); 142 } 143 144 145 public static Test suite() throws Exception 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 |