KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jmx > compliance > metadata > MBeanNotificationInfoTEST


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.test.jmx.compliance.metadata;
23
24 import java.io.ByteArrayInputStream JavaDoc;
25 import java.io.ByteArrayOutputStream JavaDoc;
26 import java.io.ObjectInputStream JavaDoc;
27 import java.io.ObjectOutputStream JavaDoc;
28 import java.util.Arrays JavaDoc;
29
30 import javax.management.MBeanNotificationInfo JavaDoc;
31
32 import junit.framework.TestCase;
33
34 /**
35  * MBean Notification Info tests.<p>
36  *
37  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
38  */

39 public class MBeanNotificationInfoTEST
40   extends TestCase
41 {
42    // Static --------------------------------------------------------------------
43

44    private String JavaDoc[] types1 = new String JavaDoc[] { "type1", "type2" };
45    private String JavaDoc[] types2 = new String JavaDoc[] { "typex", "type2" };
46
47    // Attributes ----------------------------------------------------------------
48

49    // Constructor ---------------------------------------------------------------
50

51    /**
52     * Construct the test
53     */

54    public MBeanNotificationInfoTEST(String JavaDoc s)
55    {
56       super(s);
57    }
58
59    // Tests ---------------------------------------------------------------------
60

61    public void testMBeanNotificationInfo()
62       throws Exception JavaDoc
63    {
64       MBeanNotificationInfo JavaDoc info = new MBeanNotificationInfo JavaDoc(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 JavaDoc
73    {
74       MBeanNotificationInfo JavaDoc info1 = new MBeanNotificationInfo JavaDoc(types1, "name", "description");
75       MBeanNotificationInfo JavaDoc info2 = new MBeanNotificationInfo JavaDoc(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 JavaDoc
82    {
83       MBeanNotificationInfo JavaDoc info = new MBeanNotificationInfo JavaDoc(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 JavaDoc()) == false);
88
89       MBeanNotificationInfo JavaDoc info2 = new MBeanNotificationInfo JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc(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 JavaDoc
116    {
117       MBeanNotificationInfo JavaDoc info = new MBeanNotificationInfo JavaDoc(types1,
118          "name", "description");
119
120       // Serialize it
121
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
122       ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
123       oos.writeObject(info);
124     
125       // Deserialize it
126
ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
127       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
128       Object JavaDoc result = ois.readObject();
129
130       assertEquals(info, result);
131    }
132 }
133
Popular Tags