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:
031: import javax.management.MBeanParameterInfo;
032:
033: /**
034: * MBean Parameter Info tests.<p>
035: *
036: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
037: */
038: public class MBeanParameterInfoTEST extends TestCase {
039: // Static --------------------------------------------------------------------
040:
041: // Attributes ----------------------------------------------------------------
042:
043: // Constructor ---------------------------------------------------------------
044:
045: /**
046: * Construct the test
047: */
048: public MBeanParameterInfoTEST(String s) {
049: super (s);
050: }
051:
052: // Tests ---------------------------------------------------------------------
053:
054: public void testMBeanParameterInfo() throws Exception {
055: MBeanParameterInfo info = new MBeanParameterInfo("name",
056: "type", "description");
057: assertEquals("name", info.getName());
058: assertEquals("type", info.getType());
059: assertEquals("description", info.getDescription());
060: }
061:
062: public void testHashCode() throws Exception {
063: MBeanParameterInfo info1 = new MBeanParameterInfo("name",
064: "type", "description");
065: MBeanParameterInfo info2 = new MBeanParameterInfo("name",
066: "type", "description");
067:
068: assertTrue(
069: "Different instances with the same hashcode are equal",
070: info1.hashCode() == info2.hashCode());
071: }
072:
073: public void testEquals() throws Exception {
074: MBeanParameterInfo info = new MBeanParameterInfo("name",
075: "type", "description");
076:
077: assertTrue("Null should not be equal",
078: info.equals(null) == false);
079: assertTrue("Only MBeanParameterInfo should be equal", info
080: .equals(new Object()) == false);
081:
082: MBeanParameterInfo info2 = new MBeanParameterInfo("name",
083: "type", "description");
084:
085: assertTrue("Different instances of the same data are equal",
086: info.equals(info2));
087: assertTrue("Different instances of the same data are equal",
088: info2.equals(info));
089:
090: info2 = new MBeanParameterInfo("name", "type", "description2");
091:
092: assertTrue(
093: "Different instances with different descriptions are not equal",
094: info.equals(info2) == false);
095: assertTrue(
096: "Different instances with different descritpions are not equal",
097: info2.equals(info) == false);
098:
099: info2 = new MBeanParameterInfo("name2", "type", "description");
100:
101: assertTrue("Instances with different names are not equal", info
102: .equals(info2) == false);
103: assertTrue("Instances with different names are not equal",
104: info2.equals(info) == false);
105:
106: info2 = new MBeanParameterInfo("name", "type2", "description");
107:
108: assertTrue("Instances with different types are not equal", info
109: .equals(info2) == false);
110: assertTrue("Instances with different types are not equal",
111: info2.equals(info) == false);
112: }
113:
114: public void testSerialization() throws Exception {
115: MBeanParameterInfo info = new MBeanParameterInfo("name",
116: "type", "description");
117:
118: // Serialize it
119: ByteArrayOutputStream baos = new ByteArrayOutputStream();
120: ObjectOutputStream oos = new ObjectOutputStream(baos);
121: oos.writeObject(info);
122:
123: // Deserialize it
124: ByteArrayInputStream bais = new ByteArrayInputStream(baos
125: .toByteArray());
126: ObjectInputStream ois = new ObjectInputStream(bais);
127: Object result = ois.readObject();
128:
129: assertEquals(info, result);
130: }
131:
132: public void testErrors() throws Exception {
133: boolean caught = false;
134: try {
135: MBeanParameterInfo info = new MBeanParameterInfo(null,
136: "type", "description");
137: } catch (IllegalArgumentException e) {
138: caught = true;
139: }
140: if (caught == false)
141: fail("Expected IllegalArgumentException for null name");
142:
143: caught = false;
144: try {
145: MBeanParameterInfo info = new MBeanParameterInfo("",
146: "type", "description");
147: } catch (IllegalArgumentException e) {
148: caught = true;
149: }
150: if (caught == false)
151: fail("Expected IllegalArgumentException for an empty name");
152:
153: caught = false;
154: try {
155: MBeanParameterInfo info = new MBeanParameterInfo(
156: "invalid name", "type", "description");
157: } catch (IllegalArgumentException e) {
158: caught = true;
159: }
160: if (caught == false)
161: fail("Expected IllegalArgumentException for an 'invalid name'");
162:
163: caught = false;
164: try {
165: MBeanParameterInfo info = new MBeanParameterInfo("name",
166: null, "description");
167: } catch (IllegalArgumentException e) {
168: caught = true;
169: }
170: if (caught == false)
171: fail("Expected IllegalArgumentException for null type");
172:
173: caught = false;
174: try {
175: MBeanParameterInfo info = new MBeanParameterInfo("name",
176: "", "description");
177: } catch (IllegalArgumentException e) {
178: caught = true;
179: }
180: if (caught == false)
181: fail("Expected IllegalArgumentException for an empty type");
182:
183: caught = false;
184: try {
185: MBeanParameterInfo info = new MBeanParameterInfo("name",
186: "invalid type", "description");
187: } catch (IllegalArgumentException e) {
188: caught = true;
189: }
190: if (caught == false)
191: fail("Expected IllegalArgumentException for an 'invalid type'");
192: }
193: }
|