001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package test.compliance.metadata;
023:
024: import junit.framework.TestCase;
025:
026: import java.io.ByteArrayInputStream;
027: import java.io.ByteArrayOutputStream;
028: import java.io.ObjectInputStream;
029: import java.io.ObjectOutputStream;
030: import java.util.Arrays;
031:
032: import javax.management.MBeanConstructorInfo;
033: import javax.management.MBeanParameterInfo;
034:
035: /**
036: * MBean Parameter Info tests.<p>
037: *
038: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
039: */
040: public class MBeanConstructorInfoTEST extends TestCase {
041: // Static --------------------------------------------------------------------
042:
043: MBeanParameterInfo[] params1 = new MBeanParameterInfo[] {
044: new MBeanParameterInfo("FooParam", "java.lang.Object",
045: "description"),
046: new MBeanParameterInfo("BarParam", "java.lang.String",
047: "description") };
048: MBeanParameterInfo[] params2 = new MBeanParameterInfo[] {
049: new MBeanParameterInfo("FooParam", "java.lang.Character",
050: "description"),
051: new MBeanParameterInfo("BarParam", "java.lang.String",
052: "description") };
053:
054: // Attributes ----------------------------------------------------------------
055:
056: // Constructor ---------------------------------------------------------------
057:
058: /**
059: * Construct the test
060: */
061: public MBeanConstructorInfoTEST(String s) {
062: super (s);
063: }
064:
065: // Tests ---------------------------------------------------------------------
066:
067: public void testMBeanConstructorInfo() throws Exception {
068: MBeanConstructorInfo info = new MBeanConstructorInfo("name",
069: "description", params1);
070: assertEquals("name", info.getName());
071: assertEquals("description", info.getDescription());
072: assertEquals(Arrays.asList(params1), Arrays.asList(info
073: .getSignature()));
074: }
075:
076: public void testHashCode() throws Exception {
077: MBeanConstructorInfo info1 = new MBeanConstructorInfo("name",
078: "description", params1);
079: MBeanConstructorInfo info2 = new MBeanConstructorInfo("name",
080: "description", params1);
081:
082: assertTrue(
083: "Different instances with the same hashcode are equal",
084: info1.hashCode() == info2.hashCode());
085: }
086:
087: public void testEquals() throws Exception {
088: MBeanConstructorInfo info = new MBeanConstructorInfo("name",
089: "description", params1);
090:
091: assertTrue("Null should not be equal",
092: info.equals(null) == false);
093: assertTrue("Only MBeanConstructorInfo should be equal", info
094: .equals(new Object()) == false);
095:
096: MBeanConstructorInfo info2 = new MBeanConstructorInfo("name",
097: "description", params1);
098:
099: assertTrue("Different instances of the same data are equal",
100: info.equals(info2));
101: assertTrue("Different instances of the same data are equal",
102: info2.equals(info));
103:
104: info2 = new MBeanConstructorInfo("name", "description2",
105: params1);
106:
107: assertTrue(
108: "Different instances with different descriptions are not equal",
109: info.equals(info2) == false);
110: assertTrue(
111: "Different instances with different descritpions are not equal",
112: info2.equals(info) == false);
113:
114: info2 = new MBeanConstructorInfo("name2", "description",
115: params1);
116:
117: assertTrue("Instances with different names are not equal", info
118: .equals(info2) == false);
119: assertTrue("Instances with different names are not equal",
120: info2.equals(info) == false);
121:
122: info2 = new MBeanConstructorInfo("name", "description", params2);
123:
124: assertTrue("Instances with different types are not equal", info
125: .equals(info2) == false);
126: assertTrue("Instances with different types are not equal",
127: info2.equals(info) == false);
128: }
129:
130: public void testSerialization() throws Exception {
131: MBeanConstructorInfo info = new MBeanConstructorInfo("name",
132: "description", params1);
133:
134: // Serialize it
135: ByteArrayOutputStream baos = new ByteArrayOutputStream();
136: ObjectOutputStream oos = new ObjectOutputStream(baos);
137: oos.writeObject(info);
138:
139: // Deserialize it
140: ByteArrayInputStream bais = new ByteArrayInputStream(baos
141: .toByteArray());
142: ObjectInputStream ois = new ObjectInputStream(bais);
143: Object result = ois.readObject();
144:
145: assertEquals(info, result);
146: }
147:
148: public void testErrors() throws Exception {
149: boolean caught = false;
150: try {
151: MBeanConstructorInfo info = new MBeanConstructorInfo(null,
152: "description", params1);
153: } catch (IllegalArgumentException e) {
154: caught = true;
155: }
156: if (caught == false)
157: fail("Expected IllegalArgumentException for null name");
158:
159: caught = false;
160: try {
161: MBeanConstructorInfo info = new MBeanConstructorInfo("",
162: "description", params1);
163: } catch (IllegalArgumentException e) {
164: caught = true;
165: }
166: if (caught == false)
167: fail("Expected IllegalArgumentException for an empty name");
168:
169: caught = false;
170: try {
171: MBeanConstructorInfo info = new MBeanConstructorInfo(
172: "invalid name", "description", params1);
173: } catch (IllegalArgumentException e) {
174: caught = true;
175: }
176: if (caught == false)
177: fail("Expected IllegalArgumentException for an 'invalid name'");
178: }
179: }
|