KickJava   Java API By Example, From Geeks To Geeks.

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


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

40 public class MBeanConstructorInfoTEST
41   extends TestCase
42 {
43    // Static --------------------------------------------------------------------
44

45    MBeanParameterInfo JavaDoc[] params1 = new MBeanParameterInfo JavaDoc[]
46    {
47       new MBeanParameterInfo JavaDoc("FooParam", "java.lang.Object", "description"),
48       new MBeanParameterInfo JavaDoc("BarParam", "java.lang.String", "description")
49    };
50    MBeanParameterInfo JavaDoc[] params2 = new MBeanParameterInfo JavaDoc[]
51    {
52       new MBeanParameterInfo JavaDoc("FooParam", "java.lang.Character", "description"),
53       new MBeanParameterInfo JavaDoc("BarParam", "java.lang.String", "description")
54    };
55
56    // Attributes ----------------------------------------------------------------
57

58    // Constructor ---------------------------------------------------------------
59

60    /**
61     * Construct the test
62     */

63    public MBeanConstructorInfoTEST(String JavaDoc s)
64    {
65       super(s);
66    }
67
68    // Tests ---------------------------------------------------------------------
69

70    public void testMBeanConstructorInfo()
71       throws Exception JavaDoc
72    {
73       MBeanConstructorInfo JavaDoc info = new MBeanConstructorInfo JavaDoc(
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 JavaDoc
82    {
83       MBeanConstructorInfo JavaDoc info1 = new MBeanConstructorInfo JavaDoc("name", "description", params1);
84       MBeanConstructorInfo JavaDoc info2 = new MBeanConstructorInfo JavaDoc("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 JavaDoc
91    {
92       MBeanConstructorInfo JavaDoc info = new MBeanConstructorInfo JavaDoc(
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 JavaDoc()) == false);
97
98       MBeanConstructorInfo JavaDoc info2 = new MBeanConstructorInfo JavaDoc(
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 JavaDoc(
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 JavaDoc(
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 JavaDoc(
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 JavaDoc
125    {
126       MBeanConstructorInfo JavaDoc info = new MBeanConstructorInfo JavaDoc(
127          "name", "description", params1);
128
129       // Serialize it
130
ByteArrayOutputStream JavaDoc baos = new ByteArrayOutputStream JavaDoc();
131       ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(baos);
132       oos.writeObject(info);
133     
134       // Deserialize it
135
ByteArrayInputStream JavaDoc bais = new ByteArrayInputStream JavaDoc(baos.toByteArray());
136       ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bais);
137       Object JavaDoc result = ois.readObject();
138
139       assertEquals(info, result);
140    }
141 }
142
Popular Tags