1 22 package org.jboss.test.jmx.test; 23 24 import javax.management.Attribute ; 25 import javax.management.AttributeList ; 26 import javax.management.MBeanServerConnection ; 27 import javax.management.ObjectName ; 28 29 import org.jboss.logging.Logger; 30 import org.jboss.test.JBossTestCase; 31 import org.jboss.test.jmx.xmbean.CustomType; 32 33 39 public class XMLAttributePersistenceManagerUnitTestCase extends JBossTestCase 40 { 41 public XMLAttributePersistenceManagerUnitTestCase(String name) 42 { 43 super(name); 44 } 45 46 50 public void testPersistCustomMBeanAttributes() throws Exception 51 { 52 Logger log = getLog(); 53 log.info("+++ testPersistCustomMBeanAttributes"); 54 55 String testService = "xmbean-custom-attr-pers.sar"; 56 String customMBean = "jboss.test:service=ServiceUsingCustomAttribute"; 57 58 MBeanServerConnection server = super.getServer(); 59 ObjectName aps = new ObjectName ("jboss:service=AttributePersistenceService"); 61 server.invoke(aps, "apmRemove", new Object [] { customMBean }, new String [] { "java.lang.String" }); 63 try 64 { 65 deploy(testService); 66 ObjectName target = new ObjectName (customMBean); 67 CustomType ct = new CustomType(777, 888); 68 server.setAttribute(target, new Attribute ("Attr", ct)); 70 undeploy(testService); 72 deploy(testService); 74 ct = (CustomType)server.getAttribute(target, "Attr"); 76 assertTrue("CustomType.x == 777", ct.getX() == 777); 77 assertTrue("CustomType.y == 888", ct.getY() == 888); 78 server.invoke(aps, "apmRemove", new Object [] { customMBean }, new String [] { "java.lang.String" }); 80 } 81 catch (Exception e) 82 { 83 getLog().warn("Caught exception", e); 84 fail("Unexcepted Exception, see the Log file"); 85 } 86 finally 87 { 88 undeploy(testService); 89 } 90 } 91 92 97 public void testWriteToPathNameContainingSpaces() throws Exception 98 { 99 Logger log = getLog(); 100 log.info("+++ testWriteToPathNameContainingSpaces"); 101 102 String testService = "xmlapm-xmbean.sar"; 103 104 try 105 { 106 deploy(testService); 107 108 MBeanServerConnection server = super.getServer(); 109 ObjectName target = new ObjectName ("jboss.test:service=XMLAttributePersistenceManagerTestService"); 110 111 AttributeList atlist = new AttributeList (); 113 String storeId = "testId"; 114 Integer anInteger = new Integer (666); 115 String aString = new String ("Evil Test"); 116 atlist.add(new Attribute ("Attr1", anInteger)); 117 atlist.add(new Attribute ("Attr2", aString)); 118 119 getLog().info("Storing AttributeList"); 120 server.invoke( 121 target, 122 "store", 123 new Object [] { storeId, atlist }, 124 new String [] { storeId.getClass().getName(), atlist.getClass().getName() } 125 ); 126 127 getLog().info("Loading AttributeList"); 128 server.invoke( 129 target, 130 "load", 131 new Object [] { storeId }, 132 new String [] { storeId.getClass().getName() } 133 ); 134 135 } 136 catch (Exception e) 137 { 138 getLog().warn("Caught exception", e); 139 fail("Unexcepted Exception, see the Log file"); 140 } 141 finally 142 { 143 undeploy(testService); 144 } 145 } 146 } | Popular Tags |