1 22 package org.jboss.test.jmx.compliance.metadata; 23 24 import java.io.ByteArrayInputStream ; 25 import java.io.ByteArrayOutputStream ; 26 import java.io.ObjectInputStream ; 27 import java.io.ObjectOutputStream ; 28 import java.util.Arrays ; 29 30 import javax.management.MBeanConstructorInfo ; 31 import javax.management.MBeanParameterInfo ; 32 33 import junit.framework.TestCase; 34 35 40 public class MBeanConstructorInfoTEST 41 extends TestCase 42 { 43 45 MBeanParameterInfo [] params1 = new MBeanParameterInfo [] 46 { 47 new MBeanParameterInfo ("FooParam", "java.lang.Object", "description"), 48 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 49 }; 50 MBeanParameterInfo [] params2 = new MBeanParameterInfo [] 51 { 52 new MBeanParameterInfo ("FooParam", "java.lang.Character", "description"), 53 new MBeanParameterInfo ("BarParam", "java.lang.String", "description") 54 }; 55 56 58 60 63 public MBeanConstructorInfoTEST(String s) 64 { 65 super(s); 66 } 67 68 70 public void testMBeanConstructorInfo() 71 throws Exception 72 { 73 MBeanConstructorInfo info = new MBeanConstructorInfo ( 74 "name", "description", params1); 75 assertEquals("name", info.getName()); 76 assertEquals("description", info.getDescription()); 77 assertEquals(Arrays.asList(params1), Arrays.asList(info.getSignature())); 78 } 79 80 public void testHashCode() 81 throws Exception 82 { 83 MBeanConstructorInfo info1 = new MBeanConstructorInfo ("name", "description", params1); 84 MBeanConstructorInfo info2 = new MBeanConstructorInfo ("name", "description", params1); 85 86 assertTrue("Different instances with the same hashcode are equal", info1.hashCode() == info2.hashCode()); 87 } 88 89 public void testEquals() 90 throws Exception 91 { 92 MBeanConstructorInfo info = new MBeanConstructorInfo ( 93 "name", "description", params1); 94 95 assertTrue("Null should not be equal", info.equals(null) == false); 96 assertTrue("Only MBeanConstructorInfo should be equal", info.equals(new Object ()) == false); 97 98 MBeanConstructorInfo info2 = new MBeanConstructorInfo ( 99 "name", "description", params1); 100 101 assertTrue("Different instances of the same data are equal", info.equals(info2)); 102 assertTrue("Different instances of the same data are equal", info2.equals(info)); 103 104 info2 = new MBeanConstructorInfo ( 105 "name", "description2", params1); 106 107 assertTrue("Different instances with different descriptions are not equal", info.equals(info2) == false); 108 assertTrue("Different instances with different descritpions are not equal", info2.equals(info) == false); 109 110 info2 = new MBeanConstructorInfo ( 111 "name2", "description", params1); 112 113 assertTrue("Instances with different names are not equal", info.equals(info2) == false); 114 assertTrue("Instances with different names are not equal", info2.equals(info) == false); 115 116 info2 = new MBeanConstructorInfo ( 117 "name", "description", params2); 118 119 assertTrue("Instances with different types are not equal", info.equals(info2) == false); 120 assertTrue("Instances with different types are not equal", info2.equals(info) == false); 121 } 122 123 public void testSerialization() 124 throws Exception 125 { 126 MBeanConstructorInfo info = new MBeanConstructorInfo ( 127 "name", "description", params1); 128 129 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 131 ObjectOutputStream oos = new ObjectOutputStream (baos); 132 oos.writeObject(info); 133 134 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 136 ObjectInputStream ois = new ObjectInputStream (bais); 137 Object result = ois.readObject(); 138 139 assertEquals(info, result); 140 } 141 } 142 | Popular Tags |