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 29 import javax.management.MBeanParameterInfo ; 30 31 import junit.framework.TestCase; 32 33 38 public class MBeanParameterInfoTEST 39 extends TestCase 40 { 41 43 45 47 50 public MBeanParameterInfoTEST(String s) 51 { 52 super(s); 53 } 54 55 57 public void testMBeanParameterInfo() 58 throws Exception 59 { 60 MBeanParameterInfo info = new MBeanParameterInfo ( 61 "name", "type", "description"); 62 assertEquals("name", info.getName()); 63 assertEquals("type", info.getType()); 64 assertEquals("description", info.getDescription()); 65 } 66 67 public void testHashCode() 68 throws Exception 69 { 70 MBeanParameterInfo info1 = new MBeanParameterInfo ("name", "type", "description"); 71 MBeanParameterInfo info2 = new MBeanParameterInfo ("name", "type", "description"); 72 73 assertTrue("Different instances with the same hashcode are equal", info1.hashCode() == info2.hashCode()); 74 } 75 76 public void testEquals() 77 throws Exception 78 { 79 MBeanParameterInfo info = new MBeanParameterInfo ( 80 "name", "type", "description"); 81 82 assertTrue("Null should not be equal", info.equals(null) == false); 83 assertTrue("Only MBeanParameterInfo should be equal", info.equals(new Object ()) == false); 84 85 MBeanParameterInfo info2 = new MBeanParameterInfo ( 86 "name", "type", "description"); 87 88 assertTrue("Different instances of the same data are equal", info.equals(info2)); 89 assertTrue("Different instances of the same data are equal", info2.equals(info)); 90 91 info2 = new MBeanParameterInfo ( 92 "name", "type", "description2"); 93 94 assertTrue("Different instances with different descriptions are not equal", info.equals(info2) == false); 95 assertTrue("Different instances with different descritpions are not equal", info2.equals(info) == false); 96 97 info2 = new MBeanParameterInfo ( 98 "name2", "type", "description"); 99 100 assertTrue("Instances with different names are not equal", info.equals(info2) == false); 101 assertTrue("Instances with different names are not equal", info2.equals(info) == false); 102 103 info2 = new MBeanParameterInfo ( 104 "name", "type2", "description"); 105 106 assertTrue("Instances with different types are not equal", info.equals(info2) == false); 107 assertTrue("Instances with different types are not equal", info2.equals(info) == false); 108 } 109 110 public void testSerialization() 111 throws Exception 112 { 113 MBeanParameterInfo info = new MBeanParameterInfo ( 114 "name", "type", "description"); 115 116 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 118 ObjectOutputStream oos = new ObjectOutputStream (baos); 119 oos.writeObject(info); 120 121 ByteArrayInputStream bais = new ByteArrayInputStream (baos.toByteArray()); 123 ObjectInputStream ois = new ObjectInputStream (bais); 124 Object result = ois.readObject(); 125 126 assertEquals(info, result); 127 } 128 } 129 | Popular Tags |