[jboss-cvs] JBossAS SVN: r63919 - in projects/microcontainer/trunk/aop-mc-int/src: tests/org/jboss/test/microcontainer/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Jul 9 15:52:19 EDT 2007


Author: bstansberry at jboss.com
Date: 2007-07-09 15:52:19 -0400 (Mon, 09 Jul 2007)
New Revision: 63919

Modified:
   projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml
   projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java
Log:
[JBMICROCONT-109] Test handling of @JMX.registerDirectly

Modified: projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml	2007-07-09 19:51:54 UTC (rev 63918)
+++ projects/microcontainer/trunk/aop-mc-int/src/resources/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.xml	2007-07-09 19:52:19 UTC (rev 63919)
@@ -22,4 +22,20 @@
    <bean name="Bean" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
       <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="", exposedInterface=org.jboss.test.microcontainer.support.SimpleBean.class)</annotation>
    </bean>
+
+   <bean name="Bean1" class="org.jboss.test.microcontainer.support.SimpleBeanImpl">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:name=NotBean1", exposedInterface=org.jboss.test.microcontainer.support.SimpleBeanImplMBean.class)</annotation>
+   </bean>
+
+   <bean name="AnnotatedBean" class="org.jboss.test.microcontainer.support.SimpleBeanAnnotatedImpl"/>
+
+   <bean name="AnnotatedBean2" class="org.jboss.test.microcontainer.support.SimpleBeanAnnotatedImpl2"/>
+   
+   <bean name="DirectRegistrant" class="org.jboss.test.microcontainer.support.JmxRegistrantDirect">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:name=DirectRegistrant", exposedInterface=org.jboss.test.microcontainer.support.JmxRegistrantDirectMBean.class,registerDirectly=true)</annotation>
+   </bean>
+
+   <bean name="NotDirectRegistrant" class="org.jboss.test.microcontainer.support.JmxRegistrantDirect">
+      <annotation>@org.jboss.aop.microcontainer.aspects.jmx.JMX(name="test:name=NotDirectRegistrant", exposedInterface=org.jboss.test.microcontainer.support.JmxRegistrantDirectMBean.class,registerDirectly=false)</annotation>
+   </bean>
 </deployment>

Modified: projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java
===================================================================
--- projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java	2007-07-09 19:51:54 UTC (rev 63918)
+++ projects/microcontainer/trunk/aop-mc-int/src/tests/org/jboss/test/microcontainer/test/JMXLifecycleTestCase.java	2007-07-09 19:52:19 UTC (rev 63919)
@@ -21,6 +21,7 @@
   */
 package org.jboss.test.microcontainer.test;
 
+import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanInfo;
 import javax.management.MBeanOperationInfo;
 import javax.management.MBeanServer;
@@ -28,7 +29,12 @@
 
 import junit.framework.Test;
 
+import org.jboss.aop.microcontainer.aspects.jmx.JMX;
 import org.jboss.aop.microcontainer.junit.AOPMicrocontainerTest;
+import org.jboss.test.microcontainer.support.JmxRegistrant;
+import org.jboss.test.microcontainer.support.MetaDataContextInterceptor;
+import org.jboss.test.microcontainer.support.SimpleBean;
+import org.jboss.test.microcontainer.support.SimpleBeanImplMBean;
 
 public class JMXLifecycleTestCase extends AOPMicrocontainerTest
 {
@@ -42,7 +48,6 @@
       super(name);
    }
    
-   
    public void testJMX() throws Exception
    {
       MBeanServer server = (MBeanServer) getBean("MBeanServer");
@@ -54,5 +59,87 @@
       MBeanOperationInfo[] ops = info.getOperations();
       assertEquals(1, ops.length);
       assertEquals("someMethod", ops[0].getName());
+      
+      name = new ObjectName("test:name=NotBean1");
+      info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      ops = info.getOperations();
+      assertEquals(1, ops.length);
+      assertEquals("someOtherMethod", ops[0].getName());
+      
+      name = new ObjectName("test:name='AnnotatedBean'");
+      info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      ops = info.getOperations();
+      assertEquals(1, ops.length);
+      assertEquals("someOtherMethod", ops[0].getName());
+      
+      name = new ObjectName("test:name=AnnotatedNotBean");
+      info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      ops = info.getOperations();
+      assertEquals(1, ops.length);
+      assertEquals("someOtherMethod", ops[0].getName());
    }
+   
+   /**
+    * Tests that adding the registerDirectly=true attribute allows a
+    * standard MBean to be registered directly, while not specifying it
+    * causes a proxy to be registered (even if the bean is a standard MBean).
+    * Also confirms a bean that isn't an MBean will fail to deploy if
+    * registerDirectly=true.
+    * 
+    * @throws Exception
+    */
+   public void testRegisterDirectly() throws Exception
+   {
+      MBeanServer server = (MBeanServer) getBean("MBeanServer");
+      assertNotNull(server);
+
+      ObjectName name = new ObjectName("test:name=DirectRegistrant");
+      MBeanInfo info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      MBeanAttributeInfo[] attrs = info.getAttributes();
+      assertEquals(1, attrs.length);
+      assertEquals("RegisteredInJmx", attrs[0].getName());
+      assertTrue(attrs[0].isReadable());
+      assertFalse(attrs[0].isWritable());
+      
+      JmxRegistrant bean = (JmxRegistrant) getBean("DirectRegistrant");
+      assertTrue("MBeanRegistration callbacks invoked", bean.isRegisteredInJmx());
+      
+      name = new ObjectName("test:name=NotDirectRegistrant");
+      info = server.getMBeanInfo(name);
+      assertNotNull(info);
+      attrs = info.getAttributes();
+      assertEquals(1, attrs.length);
+      assertEquals("RegisteredInJmx", attrs[0].getName());
+      assertTrue(attrs[0].isReadable());
+      assertFalse(attrs[0].isWritable());
+      
+      bean = (JmxRegistrant) getBean("NotDirectRegistrant");
+      assertFalse("MBeanRegistration callbacks not invoked", bean.isRegisteredInJmx());
+      
+      // Deploy a bean that should fail as it's not an mbean
+      
+      deploy("JMXDecorated-flawed.xml");
+      try
+      {      
+         name = new ObjectName("test:name=FlawedRegistrant");
+         assertFalse(name + " not registered", server.isRegistered(name));
+         
+         Object broken = null;
+         try
+         {
+            broken = getBean("FlawedRegistrant");
+         }
+         catch (Exception good) {}         
+   
+         assertNull("FlawedRegistrant did not deploy", broken);
+      }
+      finally
+      {
+         undeploy("JMXDecorated-flawed.xml");
+      }
+   }
 }




More information about the jboss-cvs-commits mailing list