KickJava   Java API By Example, From Geeks To Geeks.

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


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
29 import javax.management.MBeanParameterInfo JavaDoc;
30
31 import junit.framework.TestCase;
32
33 /**
34  * MBean Parameter Info tests.<p>
35  *
36  * @author <a HREF="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
37  */

38 public class MBeanParameterInfoTEST
39   extends TestCase
40 {
41    // Static --------------------------------------------------------------------
42

43    // Attributes ----------------------------------------------------------------
44

45    // Constructor ---------------------------------------------------------------
46

47    /**
48     * Construct the test
49     */

50    public MBeanParameterInfoTEST(String JavaDoc s)
51    {
52       super(s);
53    }
54
55    // Tests ---------------------------------------------------------------------
56

57    public void testMBeanParameterInfo()
58       throws Exception JavaDoc
59    {
60       MBeanParameterInfo JavaDoc info = new MBeanParameterInfo JavaDoc(
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 JavaDoc
69    {
70       MBeanParameterInfo JavaDoc info1 = new MBeanParameterInfo JavaDoc("name", "type", "description");
71       MBeanParameterInfo JavaDoc info2 = new MBeanParameterInfo JavaDoc("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 JavaDoc
78    {
79       MBeanParameterInfo JavaDoc info = new MBeanParameterInfo JavaDoc(
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 JavaDoc()) == false);
84
85       MBeanParameterInfo JavaDoc info2 = new MBeanParameterInfo JavaDoc(
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 JavaDoc(
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 JavaDoc(
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 JavaDoc(
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 JavaDoc
112    {
113       MBeanParameterInfo JavaDoc info = new MBeanParameterInfo JavaDoc(
114          "name", "type", "description");
115
116       // Serialize it
117
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
118       ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
119       oos.writeObject(info);
120     
121       // Deserialize it
122
ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
123       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
124       Object JavaDoc result = ois.readObject();
125
126       assertEquals(info, result);
127    }
128 }
129
Popular Tags