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.MBeanNotificationInfo ; 31 32 import junit.framework.TestCase; 33 34 39 public class MBeanNotificationInfoTEST 40 extends TestCase 41 { 42 44 private String [] types1 = new String [] { "type1", "type2" }; 45 private String [] types2 = new String [] { "typex", "type2" }; 46 47 49 51 54 public MBeanNotificationInfoTEST(String s) 55 { 56 super(s); 57 } 58 59 61 public void testMBeanNotificationInfo() 62 throws Exception 63 { 64 MBeanNotificationInfo info = new MBeanNotificationInfo (types1, 65 "name", "description"); 66 assertEquals("name", info.getName()); 67 assertEquals("description", info.getDescription()); 68 assertEquals(Arrays.asList(types1), Arrays.asList(info.getNotifTypes())); 69 } 70 71 public void testHashCode() 72 throws Exception 73 { 74 MBeanNotificationInfo info1 = new MBeanNotificationInfo (types1, "name", "description"); 75 MBeanNotificationInfo info2 = new MBeanNotificationInfo (types1, "name", "description"); 76 77 assertTrue("Different instances with the same hashcode are equal", info1.hashCode() == info2.hashCode()); 78 } 79 80 public void testEquals() 81 throws Exception 82 { 83 MBeanNotificationInfo info = new MBeanNotificationInfo (types1, 84 "name", "description"); 85 86 assertTrue("Null should not be equal", info.equals(null) == false); 87 assertTrue("Only MBeanNotificationInfo should be equal", info.equals(new Object ()) == false); 88 89 MBeanNotificationInfo info2 = new MBeanNotificationInfo (types1, 90 "name", "description"); 91 92 assertTrue("Different instances of the same data are equal", info.equals(info2)); 93 assertTrue("Different instances of the same data are equal", info2.equals(info)); 94 95 info2 = new MBeanNotificationInfo (types1, 96 "name", "description2"); 97 98 assertTrue("Different instances with different descriptions are not equal", info.equals(info2) == false); 99 assertTrue("Different instances with different descritpions are not equal", info2.equals(info) == false); 100 101 info2 = new MBeanNotificationInfo (types1, 102 "name2", "description"); 103 104 assertTrue("Instances with different names are not equal", info.equals(info2) == false); 105 assertTrue("Instances with different names are not equal", info2.equals(info) == false); 106 107 info2 = new MBeanNotificationInfo (types2, 108 "name", "description"); 109 110 assertTrue("Instances with different types are not equal", info.equals(info2) == false); 111 assertTrue("Instances with different types are not equal", info2.equals(info) == false); 112 } 113 114 public void testSerialization() 115 throws Exception 116 { 117 MBeanNotificationInfo info = new MBeanNotificationInfo (types1, 118 "name", "description"); 119 120 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 122 ObjectOutputStream oos = new ObjectOutputStream (baos); 123 oos.writeObject(info); 124 125 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 127 ObjectInputStream ois = new ObjectInputStream (bais); 128 Object result = ois.readObject(); 129 130 assertEquals(info, result); 131 } 132 } 133 | Popular Tags |