1 8 9 package test.javax.management.modelmbean; 10 11 import java.lang.reflect.Constructor ; 12 import javax.management.Descriptor ; 13 import javax.management.MBeanParameterInfo ; 14 import javax.management.RuntimeOperationsException ; 15 import javax.management.modelmbean.DescriptorSupport ; 16 import javax.management.modelmbean.ModelMBeanConstructorInfo ; 17 18 import junit.framework.TestCase; 19 import junit.textui.TestRunner; 20 21 24 public class ModelMBeanConstructorInfoTest extends TestCase 25 { 26 public static class Bob 27 { 28 public Bob(String address) 29 { 30 } 31 } 32 33 public static void main(String [] args) 34 { 35 TestRunner.run(ModelMBeanConstructorInfoTest.class); 36 } 37 38 public ModelMBeanConstructorInfoTest(String name) 39 { 40 super(name); 41 } 42 43 public void testValid() throws Exception 44 { 45 Constructor bobctor = 46 ModelMBeanConstructorInfoTest.Bob.class.getConstructor(new Class []{String .class}); 47 String [] fields = {"name", "descriptorType", "displayName", "role"}; 48 String [] values = 49 {bobctor.getName(), "operation", "bob maker", "constructor"}; 50 DescriptorSupport ds = new DescriptorSupport (fields, values); 51 ModelMBeanConstructorInfo ctorinfo = 52 new ModelMBeanConstructorInfo ("BobBuilder", bobctor, ds); 53 } 54 55 public void testAddDefaultDisplayName() throws Exception 56 { 57 Constructor bobctor = 58 ModelMBeanConstructorInfoTest.Bob.class.getConstructor(new Class []{String .class}); 59 String [] fields = {"name", "descriptorType", "role"}; 60 String [] values = {bobctor.getName(), "operation", "constructor"}; 61 DescriptorSupport ds = new DescriptorSupport (fields, values); 62 ModelMBeanConstructorInfo ctorinfo = 63 new ModelMBeanConstructorInfo ("BobBuilder", bobctor, ds); 64 Descriptor d = ctorinfo.getDescriptor(); 65 String dispname = (String )d.getFieldValue("displayName"); 66 assertTrue("Unexpected displayName", 67 dispname.compareTo(bobctor.getName()) == 0); 68 } 69 70 public void testBadRole() throws Exception 71 { 72 try 73 { 74 Constructor bobctor = 75 ModelMBeanConstructorInfoTest.Bob.class.getConstructor(new Class []{String .class}); 76 String [] fields = 77 {"name", "descriptorType", "displayName", "role"}; 78 String [] values = 79 {bobctor.getName(), "operation", "bob maker", "getter"}; 80 DescriptorSupport ds = new DescriptorSupport (fields, values); 81 ModelMBeanConstructorInfo ctorinfo = 82 new ModelMBeanConstructorInfo ("BobBuilder", bobctor, ds); 83 fail("Expecting RuntimeOperationsException"); 84 } 85 catch (RuntimeOperationsException x) 86 { 87 if (!(x.getTargetException() instanceof IllegalArgumentException )) 88 { 89 fail("Target exception should be IllegalArgumentException"); 90 } 91 assertTrue(true); } 93 } 94 95 public void testCaseInsensitiveDescriptorType() 96 { 97 DescriptorSupport ds = 98 new DescriptorSupport (new String []{ 99 "descriptorType=OPERATION", 100 "role=constructor", 101 "name=BobBuilder", 102 "displayname=bob maker"}); 103 ModelMBeanConstructorInfo ctorinfo = 104 new ModelMBeanConstructorInfo ("BobBuilder", 105 "Default Bob Constructor", 106 new MBeanParameterInfo [0], 107 ds); 108 } 109 110 protected void setUp() 111 { 112 } 113 114 protected void tearDown() 115 { 116 } 117 } 118 | Popular Tags |