0001: /*
0002: * JBoss, Home of Professional Open Source.
0003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
0004: * as indicated by the @author tags. See the copyright.txt file in the
0005: * distribution for a full listing of individual contributors.
0006: *
0007: * This is free software; you can redistribute it and/or modify it
0008: * under the terms of the GNU Lesser General Public License as
0009: * published by the Free Software Foundation; either version 2.1 of
0010: * the License, or (at your option) any later version.
0011: *
0012: * This software is distributed in the hope that it will be useful,
0013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
0014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
0015: * Lesser General Public License for more details.
0016: *
0017: * You should have received a copy of the GNU Lesser General Public
0018: * License along with this software; if not, write to the Free
0019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
0020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
0021: */
0022: package test.compliance.openmbean;
0023:
0024: import junit.framework.TestCase;
0025:
0026: import java.io.ByteArrayInputStream;
0027: import java.io.ByteArrayOutputStream;
0028: import java.io.ObjectInputStream;
0029: import java.io.ObjectOutputStream;
0030:
0031: import javax.management.openmbean.ArrayType;
0032: import javax.management.openmbean.CompositeType;
0033: import javax.management.openmbean.OpenDataException;
0034: import javax.management.openmbean.OpenMBeanAttributeInfoSupport;
0035: import javax.management.openmbean.OpenType;
0036: import javax.management.openmbean.SimpleType;
0037: import javax.management.openmbean.TabularDataSupport;
0038: import javax.management.openmbean.TabularType;
0039:
0040: /**
0041: * Open MBean Attribute Info tests.<p>
0042: *
0043: * @author <a href="mailto:Adrian.Brock@HappeningTimes.com">Adrian Brock</a>.
0044: */
0045: public class OpenMBeanAttributeInfoSupportTestCase extends TestCase {
0046: // Static --------------------------------------------------------------------
0047:
0048: // Attributes ----------------------------------------------------------------
0049:
0050: // Constructor ---------------------------------------------------------------
0051:
0052: /**
0053: * Construct the test
0054: */
0055: public OpenMBeanAttributeInfoSupportTestCase(String s) {
0056: super (s);
0057: }
0058:
0059: // Tests ---------------------------------------------------------------------
0060:
0061: public void testOpenMBeanAttributeInfoSupport() throws Exception {
0062: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0063: "name", "description", SimpleType.STRING, true, true,
0064: false);
0065: assertEquals("name", info.getName());
0066: assertEquals("description", info.getDescription());
0067: assertEquals("java.lang.String", info.getType());
0068: assertEquals(true, info.isWritable());
0069: assertEquals(true, info.isReadable());
0070: assertEquals(false, info.isIs());
0071:
0072: info = new OpenMBeanAttributeInfoSupport("name", "description",
0073: SimpleType.STRING, true, true, false, "default");
0074: assertEquals("name", info.getName());
0075: assertEquals("description", info.getDescription());
0076: assertEquals("java.lang.String", info.getType());
0077: assertEquals(true, info.isWritable());
0078: assertEquals(true, info.isReadable());
0079: assertEquals(false, info.isIs());
0080: assertEquals("default", info.getDefaultValue());
0081: assertEquals(true, info.hasDefaultValue());
0082:
0083: info = new OpenMBeanAttributeInfoSupport("name", "description",
0084: SimpleType.STRING, true, true, false, null);
0085: assertEquals("name", info.getName());
0086: assertEquals("description", info.getDescription());
0087: assertEquals("java.lang.String", info.getType());
0088: assertEquals(true, info.isWritable());
0089: assertEquals(true, info.isReadable());
0090: assertEquals(false, info.isIs());
0091: assertEquals(null, info.getDefaultValue());
0092: assertEquals(false, info.hasDefaultValue());
0093:
0094: info = new OpenMBeanAttributeInfoSupport("name", "description",
0095: SimpleType.INTEGER, true, true, false, new Integer(3),
0096: new Integer(2), new Integer(4));
0097: assertEquals("name", info.getName());
0098: assertEquals("description", info.getDescription());
0099: assertEquals("java.lang.Integer", info.getType());
0100: assertEquals(true, info.isWritable());
0101: assertEquals(true, info.isReadable());
0102: assertEquals(false, info.isIs());
0103: assertEquals(new Integer(3), info.getDefaultValue());
0104: assertEquals(new Integer(2), info.getMinValue());
0105: assertEquals(new Integer(4), info.getMaxValue());
0106:
0107: info = new OpenMBeanAttributeInfoSupport("name", "description",
0108: SimpleType.INTEGER, true, true, false, null,
0109: new Integer(2), new Integer(4));
0110: assertEquals("name", info.getName());
0111: assertEquals("description", info.getDescription());
0112: assertEquals("java.lang.Integer", info.getType());
0113: assertEquals(true, info.isWritable());
0114: assertEquals(true, info.isReadable());
0115: assertEquals(false, info.isIs());
0116: assertEquals(null, info.getDefaultValue());
0117: assertEquals(new Integer(2), info.getMinValue());
0118: assertEquals(new Integer(4), info.getMaxValue());
0119:
0120: info = new OpenMBeanAttributeInfoSupport("name", "description",
0121: SimpleType.INTEGER, true, true, false, new Integer(3),
0122: null, new Integer(4));
0123: assertEquals("name", info.getName());
0124: assertEquals("description", info.getDescription());
0125: assertEquals("java.lang.Integer", info.getType());
0126: assertEquals(true, info.isWritable());
0127: assertEquals(true, info.isReadable());
0128: assertEquals(false, info.isIs());
0129: assertEquals(new Integer(3), info.getDefaultValue());
0130: assertEquals(null, info.getMinValue());
0131: assertEquals(new Integer(4), info.getMaxValue());
0132:
0133: info = new OpenMBeanAttributeInfoSupport("name", "description",
0134: SimpleType.INTEGER, true, true, false, new Integer(3),
0135: new Integer(2), null);
0136: assertEquals("name", info.getName());
0137: assertEquals("description", info.getDescription());
0138: assertEquals("java.lang.Integer", info.getType());
0139: assertEquals(true, info.isWritable());
0140: assertEquals(true, info.isReadable());
0141: assertEquals(false, info.isIs());
0142: assertEquals(new Integer(3), info.getDefaultValue());
0143: assertEquals(new Integer(2), info.getMinValue());
0144: assertEquals(null, info.getMaxValue());
0145:
0146: info = new OpenMBeanAttributeInfoSupport("name", "description",
0147: SimpleType.INTEGER, true, true, false, null, null,
0148: new Integer(4));
0149: assertEquals("name", info.getName());
0150: assertEquals("description", info.getDescription());
0151: assertEquals("java.lang.Integer", info.getType());
0152: assertEquals(true, info.isWritable());
0153: assertEquals(true, info.isReadable());
0154: assertEquals(false, info.isIs());
0155: assertEquals(null, info.getDefaultValue());
0156: assertEquals(null, info.getMinValue());
0157: assertEquals(new Integer(4), info.getMaxValue());
0158:
0159: info = new OpenMBeanAttributeInfoSupport("name", "description",
0160: SimpleType.INTEGER, true, true, false, null,
0161: new Integer(2), null);
0162: assertEquals("name", info.getName());
0163: assertEquals("description", info.getDescription());
0164: assertEquals("java.lang.Integer", info.getType());
0165: assertEquals(true, info.isWritable());
0166: assertEquals(true, info.isReadable());
0167: assertEquals(false, info.isIs());
0168: assertEquals(null, info.getDefaultValue());
0169: assertEquals(new Integer(2), info.getMinValue());
0170: assertEquals(null, info.getMaxValue());
0171:
0172: info = new OpenMBeanAttributeInfoSupport("name", "description",
0173: SimpleType.INTEGER, true, true, false, new Integer(3),
0174: null, null);
0175: assertEquals("name", info.getName());
0176: assertEquals("description", info.getDescription());
0177: assertEquals("java.lang.Integer", info.getType());
0178: assertEquals(true, info.isWritable());
0179: assertEquals(true, info.isReadable());
0180: assertEquals(false, info.isIs());
0181: assertEquals(new Integer(3), info.getDefaultValue());
0182: assertEquals(null, info.getMinValue());
0183: assertEquals(null, info.getMaxValue());
0184:
0185: info = new OpenMBeanAttributeInfoSupport("name", "description",
0186: SimpleType.INTEGER, true, true, false, null, null, null);
0187: assertEquals("name", info.getName());
0188: assertEquals("description", info.getDescription());
0189: assertEquals("java.lang.Integer", info.getType());
0190: assertEquals(true, info.isWritable());
0191: assertEquals(true, info.isReadable());
0192: assertEquals(false, info.isIs());
0193: assertEquals(null, info.getDefaultValue());
0194: assertEquals(null, info.getMinValue());
0195: assertEquals(null, info.getMaxValue());
0196:
0197: info = new OpenMBeanAttributeInfoSupport("name", "description",
0198: SimpleType.STRING, true, true, false, "default",
0199: new Object[] { "legal1", "legal2", "default" });
0200: assertEquals("name", info.getName());
0201: assertEquals("description", info.getDescription());
0202: assertEquals("java.lang.String", info.getType());
0203: assertEquals(true, info.isWritable());
0204: assertEquals(true, info.isReadable());
0205: assertEquals(false, info.isIs());
0206: assertEquals("default", info.getDefaultValue());
0207: assertEquals(3, info.getLegalValues().size());
0208: assertTrue("legal1 should be a legal value", info
0209: .getLegalValues().contains("legal1"));
0210: assertTrue("legal2 should be a legal value", info
0211: .getLegalValues().contains("legal2"));
0212: assertTrue("default should be a legal value", info
0213: .getLegalValues().contains("default"));
0214:
0215: info = new OpenMBeanAttributeInfoSupport("name", "description",
0216: SimpleType.STRING, true, true, false, null,
0217: new Object[] { "legal1", "legal2", "default" });
0218: assertEquals("name", info.getName());
0219: assertEquals("description", info.getDescription());
0220: assertEquals("java.lang.String", info.getType());
0221: assertEquals(true, info.isWritable());
0222: assertEquals(true, info.isReadable());
0223: assertEquals(false, info.isIs());
0224: assertEquals(null, info.getDefaultValue());
0225: assertEquals(3, info.getLegalValues().size());
0226: assertTrue("legal1 should be a legal value", info
0227: .getLegalValues().contains("legal1"));
0228: assertTrue("legal2 should be a legal value", info
0229: .getLegalValues().contains("legal2"));
0230: assertTrue("default should be a legal value", info
0231: .getLegalValues().contains("default"));
0232:
0233: info = new OpenMBeanAttributeInfoSupport("name", "description",
0234: SimpleType.STRING, true, true, false, "default", null);
0235: assertEquals("name", info.getName());
0236: assertEquals("description", info.getDescription());
0237: assertEquals("java.lang.String", info.getType());
0238: assertEquals(true, info.isWritable());
0239: assertEquals(true, info.isReadable());
0240: assertEquals(false, info.isIs());
0241: assertEquals("default", info.getDefaultValue());
0242: assertEquals(null, info.getLegalValues());
0243:
0244: info = new OpenMBeanAttributeInfoSupport("name", "description",
0245: SimpleType.STRING, true, true, false, null, null);
0246: assertEquals("name", info.getName());
0247: assertEquals("description", info.getDescription());
0248: assertEquals("java.lang.String", info.getType());
0249: assertEquals(true, info.isWritable());
0250: assertEquals(true, info.isReadable());
0251: assertEquals(false, info.isIs());
0252: assertEquals(null, info.getDefaultValue());
0253: assertEquals(null, info.getLegalValues());
0254: }
0255:
0256: public void testOpenType() throws Exception {
0257: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0258: "name", "description", SimpleType.STRING, true, true,
0259: false);
0260: assertEquals(SimpleType.STRING, info.getOpenType());
0261: }
0262:
0263: public void testHas() throws Exception {
0264: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0265: "name", "description", SimpleType.STRING, true, true,
0266: false, "default");
0267: assertEquals(true, info.hasDefaultValue());
0268:
0269: info = new OpenMBeanAttributeInfoSupport("name", "description",
0270: SimpleType.STRING, true, true, false, null);
0271: assertEquals(false, info.hasDefaultValue());
0272:
0273: info = new OpenMBeanAttributeInfoSupport("name", "description",
0274: SimpleType.INTEGER, true, true, false, null,
0275: new Integer(3), null);
0276: assertEquals(true, info.hasMinValue());
0277:
0278: info = new OpenMBeanAttributeInfoSupport("name", "description",
0279: SimpleType.INTEGER, true, true, false, null, null, null);
0280: assertEquals(false, info.hasMinValue());
0281:
0282: info = new OpenMBeanAttributeInfoSupport("name", "description",
0283: SimpleType.INTEGER, true, true, false, null, null,
0284: new Integer(3));
0285: assertEquals(true, info.hasMaxValue());
0286:
0287: info = new OpenMBeanAttributeInfoSupport("name", "description",
0288: SimpleType.INTEGER, true, true, false, null, null, null);
0289: assertEquals(false, info.hasMaxValue());
0290:
0291: info = new OpenMBeanAttributeInfoSupport("name", "description",
0292: SimpleType.INTEGER, true, true, false, null,
0293: new Object[] { new Integer(3) });
0294: assertEquals(true, info.hasLegalValues());
0295:
0296: info = new OpenMBeanAttributeInfoSupport("name", "description",
0297: SimpleType.INTEGER, true, true, false, null, null);
0298: assertEquals(false, info.hasLegalValues());
0299: }
0300:
0301: public void testIsValue() throws Exception {
0302: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0303: "name", "description", SimpleType.STRING, true, true,
0304: false);
0305: assertTrue("String should be a value", info.isValue("string"));
0306: assertTrue("Integer should not be a value", info
0307: .isValue(new Integer(3)) == false);
0308: assertTrue("Null should not be a value",
0309: info.isValue(null) == false);
0310: }
0311:
0312: public void testIsWritable() throws Exception {
0313: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0314: "name", "description", SimpleType.STRING, true, true,
0315: false);
0316: assertEquals(true, info.isWritable());
0317: info = new OpenMBeanAttributeInfoSupport("name", "description",
0318: SimpleType.STRING, true, false, false);
0319: assertEquals(false, info.isWritable());
0320: }
0321:
0322: public void testIsReadable() throws Exception {
0323: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0324: "name", "description", SimpleType.STRING, true, true,
0325: false);
0326: assertEquals(true, info.isReadable());
0327: info = new OpenMBeanAttributeInfoSupport("name", "description",
0328: SimpleType.STRING, false, true, false);
0329: assertEquals(false, info.isReadable());
0330: }
0331:
0332: public void testIsIs() throws Exception {
0333: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0334: "name", "description", SimpleType.BOOLEAN, true, true,
0335: true);
0336: assertEquals(true, info.isIs());
0337: info = new OpenMBeanAttributeInfoSupport("name", "description",
0338: SimpleType.STRING, true, true, false);
0339: assertEquals(false, info.isIs());
0340: }
0341:
0342: public void testEquals() throws Exception {
0343: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0344: "name", "description", SimpleType.STRING, true, true,
0345: false);
0346:
0347: assertTrue("Null should not be equal",
0348: info.equals(null) == false);
0349: assertTrue("Only OpenMBeanAttributeInfo should be equal", info
0350: .equals(new Object()) == false);
0351:
0352: OpenMBeanAttributeInfoSupport info2 = new OpenMBeanAttributeInfoSupport(
0353: "name", "description", SimpleType.STRING, true, true,
0354: false);
0355:
0356: assertTrue("Different instances of the same data are equal",
0357: info.equals(info2));
0358: assertTrue("Different instances of the same data are equal",
0359: info2.equals(info));
0360:
0361: info2 = new OpenMBeanAttributeInfoSupport("name",
0362: "description2", SimpleType.STRING, true, true, false);
0363:
0364: assertTrue(
0365: "Different instances with different descriptions are equal",
0366: info.equals(info2));
0367: assertTrue(
0368: "Different instances with different descritpions are equal",
0369: info2.equals(info));
0370:
0371: info2 = new OpenMBeanAttributeInfoSupport("name2",
0372: "description", SimpleType.STRING, true, true, false);
0373:
0374: assertTrue("Instances with different names are not equal", info
0375: .equals(info2) == false);
0376: assertTrue("Instances with different names are not equal",
0377: info2.equals(info) == false);
0378:
0379: info2 = new OpenMBeanAttributeInfoSupport("name",
0380: "description", SimpleType.INTEGER, true, true, false);
0381:
0382: assertTrue("Instances with different types are not equal", info
0383: .equals(info2) == false);
0384: assertTrue("Instances with different types are not equal",
0385: info2.equals(info) == false);
0386:
0387: info2 = new OpenMBeanAttributeInfoSupport("name",
0388: "description", SimpleType.INTEGER, false, true, false);
0389:
0390: assertTrue("Instances with different read are not equal", info
0391: .equals(info2) == false);
0392: assertTrue("Instances with different read are not equal", info2
0393: .equals(info) == false);
0394:
0395: info2 = new OpenMBeanAttributeInfoSupport("name",
0396: "description", SimpleType.INTEGER, true, false, false);
0397:
0398: assertTrue("Instances with different write are not equal", info
0399: .equals(info2) == false);
0400: assertTrue("Instances with different write are not equal",
0401: info2.equals(info) == false);
0402:
0403: info2 = new OpenMBeanAttributeInfoSupport("name",
0404: "description", SimpleType.BOOLEAN, true, true, true);
0405: info2 = new OpenMBeanAttributeInfoSupport("name",
0406: "description", SimpleType.BOOLEAN, true, true, true);
0407:
0408: assertTrue("Instances with different write are not equal", info
0409: .equals(info2) == false);
0410: assertTrue("Instances with different write are not equal",
0411: info2.equals(info) == false);
0412:
0413: info = new OpenMBeanAttributeInfoSupport("name", "description",
0414: SimpleType.INTEGER, true, true, false, new Integer(3),
0415: new Integer(2), new Integer(4));
0416: info2 = new OpenMBeanAttributeInfoSupport("name",
0417: "description", SimpleType.INTEGER, true, true, false,
0418: new Integer(2), new Integer(2), new Integer(4));
0419:
0420: assertTrue(
0421: "Instances with different default values are not equal",
0422: info.equals(info2) == false);
0423: assertTrue(
0424: "Instances with different default values are not equal",
0425: info2.equals(info) == false);
0426:
0427: info = new OpenMBeanAttributeInfoSupport("name", "description",
0428: SimpleType.INTEGER, true, true, false, new Integer(3),
0429: new Integer(2), new Integer(4));
0430: info2 = new OpenMBeanAttributeInfoSupport("name",
0431: "description", SimpleType.INTEGER, true, true, false,
0432: new Integer(2), null, new Integer(4));
0433:
0434: assertTrue(
0435: "Instances with different default values are not equal",
0436: info.equals(info2) == false);
0437: assertTrue(
0438: "Instances with different default values are not equal",
0439: info2.equals(info) == false);
0440:
0441: info = new OpenMBeanAttributeInfoSupport("name", "description",
0442: SimpleType.INTEGER, true, true, false, new Integer(3));
0443: info2 = new OpenMBeanAttributeInfoSupport("name",
0444: "description", SimpleType.INTEGER, true, true, false,
0445: new Integer(3));
0446:
0447: assertTrue(
0448: "Different instances of the same default value are equal",
0449: info.equals(info2));
0450: assertTrue(
0451: "Different instances of the same default value are equal",
0452: info2.equals(info));
0453:
0454: info = new OpenMBeanAttributeInfoSupport("name", "description",
0455: SimpleType.INTEGER, true, true, false, null,
0456: new Integer(2), null);
0457: info2 = new OpenMBeanAttributeInfoSupport("name",
0458: "description", SimpleType.INTEGER, true, true, false,
0459: null, new Integer(2), null);
0460:
0461: assertTrue("Different instances of the same minimum are equal",
0462: info.equals(info2));
0463: assertTrue("Different instances of the same minimum are equal",
0464: info2.equals(info));
0465:
0466: info = new OpenMBeanAttributeInfoSupport("name", "description",
0467: SimpleType.INTEGER, true, true, false, null, null,
0468: new Integer(2));
0469: info2 = new OpenMBeanAttributeInfoSupport("name",
0470: "description", SimpleType.INTEGER, true, true, false,
0471: null, null, new Integer(2));
0472:
0473: assertTrue("Different instances of the same maximum are equal",
0474: info.equals(info2));
0475: assertTrue("Different instances of the same maximum are equal",
0476: info2.equals(info));
0477:
0478: info = new OpenMBeanAttributeInfoSupport("name", "description",
0479: SimpleType.INTEGER, true, true, false, new Integer(3),
0480: new Integer(2), new Integer(4));
0481: info2 = new OpenMBeanAttributeInfoSupport("name",
0482: "description", SimpleType.INTEGER, true, true, false,
0483: new Integer(3), new Integer(1), new Integer(4));
0484:
0485: assertTrue("Instances with different minimums are not equal",
0486: info.equals(info2) == false);
0487: assertTrue("Instances with different minimums are not equal",
0488: info2.equals(info) == false);
0489:
0490: info = new OpenMBeanAttributeInfoSupport("name", "description",
0491: SimpleType.INTEGER, true, true, false, new Integer(3),
0492: new Integer(2), new Integer(4));
0493: info2 = new OpenMBeanAttributeInfoSupport("name",
0494: "description", SimpleType.INTEGER, true, true, false,
0495: new Integer(3), null, new Integer(4));
0496:
0497: assertTrue("Instances with different minimums are not equal",
0498: info.equals(info2) == false);
0499: assertTrue("Instances with different minimums are not equal",
0500: info2.equals(info) == false);
0501:
0502: info = new OpenMBeanAttributeInfoSupport("name", "description",
0503: SimpleType.INTEGER, true, true, false, new Integer(3),
0504: new Integer(2), new Integer(4));
0505: info2 = new OpenMBeanAttributeInfoSupport("name",
0506: "description", SimpleType.INTEGER, true, true, false,
0507: new Integer(3), new Integer(2), new Integer(5));
0508:
0509: assertTrue("Instances with different maximums are not equal",
0510: info.equals(info2) == false);
0511: assertTrue("Instances with different maximums are not equal",
0512: info2.equals(info) == false);
0513:
0514: info = new OpenMBeanAttributeInfoSupport("name", "description",
0515: SimpleType.INTEGER, true, true, false, new Integer(3),
0516: new Integer(2), new Integer(4));
0517: info2 = new OpenMBeanAttributeInfoSupport("name",
0518: "description", SimpleType.INTEGER, true, true, false,
0519: new Integer(3), new Integer(2), null);
0520:
0521: assertTrue("Instances with different maximums are not equal",
0522: info.equals(info2) == false);
0523: assertTrue("Instances with different maximums are not equal",
0524: info2.equals(info) == false);
0525:
0526: info = new OpenMBeanAttributeInfoSupport("name", "description",
0527: SimpleType.INTEGER, true, true, false, null,
0528: new Object[] { new Integer(2), new Integer(3) });
0529: info2 = new OpenMBeanAttributeInfoSupport("name",
0530: "description", SimpleType.INTEGER, true, true, false,
0531: null, new Object[] { new Integer(2), new Integer(3) });
0532:
0533: assertTrue(
0534: "Different instances of the same legal values are equal",
0535: info.equals(info2));
0536: assertTrue(
0537: "Different instances of the same legal values are equal",
0538: info2.equals(info));
0539:
0540: info = new OpenMBeanAttributeInfoSupport("name", "description",
0541: SimpleType.INTEGER, true, true, false, null,
0542: new Object[] { new Integer(2), new Integer(3) });
0543: info2 = new OpenMBeanAttributeInfoSupport("name",
0544: "description", SimpleType.INTEGER, true, true, false,
0545: null, new Object[] { new Integer(2), new Integer(4) });
0546:
0547: assertTrue(
0548: "Different instances with different legal values are equal",
0549: info.equals(info2) == false);
0550: assertTrue(
0551: "Different instances with different legal values are equal",
0552: info2.equals(info) == false);
0553:
0554: info = new OpenMBeanAttributeInfoSupport("name", "description",
0555: SimpleType.INTEGER, true, true, false, null,
0556: new Object[] { new Integer(2), new Integer(3) });
0557: info2 = new OpenMBeanAttributeInfoSupport("name",
0558: "description", SimpleType.INTEGER, true, true, false,
0559: null, new Object[] { new Integer(2) });
0560:
0561: assertTrue(
0562: "Different instances with different legal values are equal",
0563: info.equals(info2) == false);
0564: assertTrue(
0565: "Different instances with different legal values are equal",
0566: info2.equals(info) == false);
0567:
0568: info = new OpenMBeanAttributeInfoSupport("name", "description",
0569: SimpleType.INTEGER, true, true, false, null,
0570: new Object[] { new Integer(2), new Integer(3) });
0571: info2 = new OpenMBeanAttributeInfoSupport("name",
0572: "description", SimpleType.INTEGER, true, true, false,
0573: null, null);
0574:
0575: assertTrue(
0576: "Different instances with different legal values are equal",
0577: info.equals(info2) == false);
0578: assertTrue(
0579: "Different instances with different legal values are equal",
0580: info2.equals(info) == false);
0581: }
0582:
0583: public void testHashCode() throws Exception {
0584:
0585: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0586: "name", "description", SimpleType.INTEGER, true, true,
0587: false, new Integer(3), new Integer(2), new Integer(4));
0588: int myHash = "name".hashCode() + SimpleType.INTEGER.hashCode()
0589: + new Integer(3).hashCode() + new Integer(2).hashCode()
0590: + new Integer(4).hashCode();
0591: assertEquals(myHash, info.hashCode());
0592: info = new OpenMBeanAttributeInfoSupport("name", "description",
0593: SimpleType.INTEGER, true, true, false, new Integer(3),
0594: new Object[] { new Integer(2), new Integer(3),
0595: new Integer(4) });
0596: myHash = "name".hashCode() + SimpleType.INTEGER.hashCode()
0597: + new Integer(3).hashCode() + new Integer(2).hashCode()
0598: + new Integer(3).hashCode() + new Integer(4).hashCode();
0599: assertEquals(myHash, info.hashCode());
0600: }
0601:
0602: public void testToString() throws Exception {
0603: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0604: "name", "description", SimpleType.INTEGER, true, true,
0605: false, new Integer(3), new Integer(2), new Integer(4));
0606:
0607: String toString = info.toString();
0608: assertTrue("info.toString() should contain the name", toString
0609: .indexOf("name") != -1);
0610: assertTrue("info.toString() should contain the simple type",
0611: toString.indexOf(SimpleType.INTEGER.toString()) != -1);
0612: assertTrue("info.toString() should contain the default value",
0613: toString.indexOf(new Integer(3).toString()) != -1);
0614: assertTrue("info.toString() should contain the minimum value",
0615: toString.indexOf(new Integer(2).toString()) != -1);
0616: assertTrue("info.toString() should contain the maximum value",
0617: toString.indexOf(new Integer(4).toString()) != -1);
0618:
0619: info = new OpenMBeanAttributeInfoSupport("name", "description",
0620: SimpleType.INTEGER, true, true, false, new Integer(3),
0621: new Object[] { new Integer(2), new Integer(3),
0622: new Integer(4) });
0623: assertTrue("info.toString() should contain the legal value 2",
0624: toString.indexOf(new Integer(2).toString()) != -1);
0625: assertTrue("info.toString() should contain the legal value 3",
0626: toString.indexOf(new Integer(3).toString()) != -1);
0627: assertTrue("info.toString() should contain the legal value 4",
0628: toString.indexOf(new Integer(4).toString()) != -1);
0629: }
0630:
0631: public void testSerialization() throws Exception {
0632: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0633: "name", "description", SimpleType.INTEGER, true, true,
0634: false, new Integer(3), new Integer(2), new Integer(4));
0635:
0636: // Serialize it
0637: ByteArrayOutputStream baos = new ByteArrayOutputStream();
0638: ObjectOutputStream oos = new ObjectOutputStream(baos);
0639: oos.writeObject(info);
0640:
0641: // Deserialize it
0642: ByteArrayInputStream bais = new ByteArrayInputStream(baos
0643: .toByteArray());
0644: ObjectInputStream ois = new ObjectInputStream(bais);
0645: Object result = ois.readObject();
0646:
0647: assertEquals(info, result);
0648:
0649: info = new OpenMBeanAttributeInfoSupport("name", "description",
0650: SimpleType.INTEGER, true, true, false, new Integer(3),
0651: new Object[] { new Integer(2), new Integer(3),
0652: new Integer(4) });
0653:
0654: // Serialize it
0655: baos = new ByteArrayOutputStream();
0656: oos = new ObjectOutputStream(baos);
0657: oos.writeObject(info);
0658:
0659: // Deserialize it
0660: bais = new ByteArrayInputStream(baos.toByteArray());
0661: ois = new ObjectInputStream(bais);
0662: result = ois.readObject();
0663:
0664: assertEquals(info, result);
0665: }
0666:
0667: public void testErrors1() throws Exception {
0668: boolean caught = false;
0669: try {
0670: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0671: null, "description", SimpleType.INTEGER, true,
0672: true, false);
0673: } catch (IllegalArgumentException e) {
0674: caught = true;
0675: }
0676: if (caught == false)
0677: fail("Expected IllegalArgumentException for null name");
0678:
0679: caught = false;
0680: try {
0681: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0682: "", "description", SimpleType.INTEGER, true, true,
0683: false);
0684: } catch (IllegalArgumentException e) {
0685: caught = true;
0686: }
0687: if (caught == false)
0688: fail("Expected IllegalArgumentException for an empty name");
0689:
0690: caught = false;
0691: try {
0692: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0693: "name", null, SimpleType.INTEGER, true, true, false);
0694: } catch (IllegalArgumentException e) {
0695: caught = true;
0696: }
0697: if (caught == false)
0698: fail("Expected IllegalArgumentException for null description");
0699:
0700: caught = false;
0701: try {
0702: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0703: "name", "", SimpleType.INTEGER, true, true, false);
0704: } catch (IllegalArgumentException e) {
0705: caught = true;
0706: }
0707: if (caught == false)
0708: fail("Expected IllegalArgumentException for an empty description");
0709:
0710: caught = false;
0711: try {
0712: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0713: "", "description", SimpleType.INTEGER, true, true,
0714: false);
0715: } catch (IllegalArgumentException e) {
0716: caught = true;
0717: }
0718: if (caught == false)
0719: fail("Expected IllegalArgumentException for an empty name");
0720:
0721: caught = false;
0722: try {
0723: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0724: "name", "description", null, true, true, false);
0725: } catch (IllegalArgumentException e) {
0726: caught = true;
0727: }
0728: if (caught == false)
0729: fail("Expected IllegalArgumentException for null simple type");
0730: }
0731:
0732: public void testErrors2() throws Exception {
0733: boolean caught = false;
0734: try {
0735: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0736: null, "description", SimpleType.INTEGER, true,
0737: true, false, new Integer(3));
0738: } catch (IllegalArgumentException e) {
0739: caught = true;
0740: }
0741: if (caught == false)
0742: fail("Expected IllegalArgumentException for null name");
0743:
0744: caught = false;
0745: try {
0746: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0747: "", "description", SimpleType.INTEGER, true, true,
0748: false, new Integer(3));
0749: } catch (IllegalArgumentException e) {
0750: caught = true;
0751: }
0752: if (caught == false)
0753: fail("Expected IllegalArgumentException for an empty name");
0754:
0755: caught = false;
0756: try {
0757: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0758: "name", null, SimpleType.INTEGER, true, true,
0759: false, new Integer(3));
0760: } catch (IllegalArgumentException e) {
0761: caught = true;
0762: }
0763: if (caught == false)
0764: fail("Expected IllegalArgumentException for null description");
0765:
0766: caught = false;
0767: try {
0768: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0769: "name", "", SimpleType.INTEGER, true, true, false,
0770: new Integer(3));
0771: } catch (IllegalArgumentException e) {
0772: caught = true;
0773: }
0774: if (caught == false)
0775: fail("Expected IllegalArgumentException for an empty description");
0776:
0777: caught = false;
0778: try {
0779: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0780: "", "description", SimpleType.INTEGER, true, true,
0781: false, new Integer(3));
0782: } catch (IllegalArgumentException e) {
0783: caught = true;
0784: }
0785: if (caught == false)
0786: fail("Expected IllegalArgumentException for an empty name");
0787:
0788: caught = false;
0789: try {
0790: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0791: "name", "description", null, true, true, false,
0792: new Integer(3));
0793: } catch (IllegalArgumentException e) {
0794: caught = true;
0795: }
0796: if (caught == false)
0797: fail("Expected IllegalArgumentException for null simple type");
0798:
0799: caught = false;
0800: try {
0801: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0802: "name", "description", SimpleType.STRING, true,
0803: true, false, new Integer(3));
0804: } catch (OpenDataException e) {
0805: caught = true;
0806: }
0807: if (caught == false)
0808: fail("Expected OpenDataException for wrong simple type and default value");
0809:
0810: caught = false;
0811: try {
0812: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
0813: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0814: "name", "description", arrayType, true, true,
0815: false, new String[0]);
0816: } catch (OpenDataException e) {
0817: caught = true;
0818: }
0819: if (caught == false)
0820: fail("Expected OpenDataException for array type and default value");
0821:
0822: caught = false;
0823: try {
0824: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
0825: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0826: "name", "description", arrayType, true, true,
0827: false, null);
0828: } catch (OpenDataException e) {
0829: caught = true;
0830: }
0831: if (caught == true)
0832: fail("Didn't execpt OpenDataException for array type and no default value");
0833:
0834: caught = false;
0835: try {
0836: String[] itemNames = new String[] { "name1", "name2" };
0837: String[] itemDescriptions = new String[] { "desc1", "desc2" };
0838: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0839: SimpleType.INTEGER };
0840: CompositeType rowType = new CompositeType("rowTypeName",
0841: "rowDescription", itemNames, itemDescriptions,
0842: itemTypes);
0843:
0844: String[] indexNames = new String[] { "name1", "name2" };
0845: TabularType tabularType = new TabularType("typeName",
0846: "description", rowType, indexNames);
0847: TabularDataSupport data = new TabularDataSupport(
0848: tabularType);
0849:
0850: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0851: "name", "description", tabularType, true, true,
0852: false, data);
0853: } catch (OpenDataException e) {
0854: caught = true;
0855: }
0856: if (caught == false)
0857: fail("Expected OpenDataException for tabular type and default value");
0858:
0859: caught = false;
0860: try {
0861: String[] itemNames = new String[] { "name1", "name2" };
0862: String[] itemDescriptions = new String[] { "desc1", "desc2" };
0863: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0864: SimpleType.INTEGER };
0865: CompositeType rowType = new CompositeType("rowTypeName",
0866: "rowDescription", itemNames, itemDescriptions,
0867: itemTypes);
0868:
0869: String[] indexNames = new String[] { "name1", "name2" };
0870: TabularType tabularType = new TabularType("typeName",
0871: "description", rowType, indexNames);
0872:
0873: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0874: "name", "description", tabularType, true, true,
0875: false, null);
0876: } catch (OpenDataException e) {
0877: caught = true;
0878: }
0879: if (caught == true)
0880: fail("Didn't execpt OpenDataException for tabular type and null default value");
0881: }
0882:
0883: public void testErrors3() throws Exception {
0884: boolean caught = false;
0885: try {
0886: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0887: null, "description", SimpleType.INTEGER, true,
0888: true, false, new Integer(3), new Integer[] {
0889: new Integer(3), new Integer(4) });
0890: } catch (IllegalArgumentException e) {
0891: caught = true;
0892: }
0893: if (caught == false)
0894: fail("Expected IllegalArgumentException for null name");
0895:
0896: caught = false;
0897: try {
0898: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0899: "", "description", SimpleType.INTEGER, true, true,
0900: false, new Integer(3), new Integer[] {
0901: new Integer(3), new Integer(4) });
0902: } catch (IllegalArgumentException e) {
0903: caught = true;
0904: }
0905: if (caught == false)
0906: fail("Expected IllegalArgumentException for an empty name");
0907:
0908: caught = false;
0909: try {
0910: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0911: "name", null, SimpleType.INTEGER, true, true,
0912: false, new Integer(3), new Integer[] {
0913: new Integer(3), new Integer(4) });
0914: } catch (IllegalArgumentException e) {
0915: caught = true;
0916: }
0917: if (caught == false)
0918: fail("Expected IllegalArgumentException for null description");
0919:
0920: caught = false;
0921: try {
0922: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0923: "name", "", SimpleType.INTEGER, true, true, false,
0924: new Integer(3), new Integer[] { new Integer(3),
0925: new Integer(4) });
0926: } catch (IllegalArgumentException e) {
0927: caught = true;
0928: }
0929: if (caught == false)
0930: fail("Expected IllegalArgumentException for an empty description");
0931:
0932: caught = false;
0933: try {
0934: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0935: "", "description", SimpleType.INTEGER, true, true,
0936: false, new Integer(3), new Integer[] {
0937: new Integer(3), new Integer(4) });
0938: } catch (IllegalArgumentException e) {
0939: caught = true;
0940: }
0941: if (caught == false)
0942: fail("Expected IllegalArgumentException for an empty name");
0943:
0944: caught = false;
0945: try {
0946: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0947: "name", "description", null, true, true, false,
0948: new Integer(3), new Integer[] { new Integer(3),
0949: new Integer(4) });
0950: } catch (IllegalArgumentException e) {
0951: caught = true;
0952: }
0953: if (caught == false)
0954: fail("Expected IllegalArgumentException for null simple type");
0955:
0956: caught = false;
0957: try {
0958: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0959: "name", "description", SimpleType.STRING, true,
0960: true, false, new Integer(3), new Integer[] {
0961: new Integer(3), new Integer(4) });
0962: } catch (OpenDataException e) {
0963: caught = true;
0964: }
0965: if (caught == false)
0966: fail("Expected OpenDataException for wrong simple type and default value");
0967:
0968: caught = false;
0969: try {
0970: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
0971: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0972: "name", "description", arrayType, true, true,
0973: false, new String[0], null);
0974: } catch (OpenDataException e) {
0975: caught = true;
0976: }
0977: if (caught == false)
0978: fail("Expected OpenDataException for array type and default value");
0979:
0980: caught = false;
0981: try {
0982: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
0983: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
0984: "name", "description", arrayType, true, true,
0985: false, null, null);
0986: } catch (OpenDataException e) {
0987: caught = true;
0988: }
0989: if (caught == true)
0990: fail("Didn't expect OpenDataException for array type and no default value and legals");
0991:
0992: caught = false;
0993: try {
0994: String[] itemNames = new String[] { "name1", "name2" };
0995: String[] itemDescriptions = new String[] { "desc1", "desc2" };
0996: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
0997: SimpleType.INTEGER };
0998: CompositeType rowType = new CompositeType("rowTypeName",
0999: "rowDescription", itemNames, itemDescriptions,
1000: itemTypes);
1001:
1002: String[] indexNames = new String[] { "name1", "name2" };
1003: TabularType tabularType = new TabularType("typeName",
1004: "description", rowType, indexNames);
1005: TabularDataSupport data = new TabularDataSupport(
1006: tabularType);
1007:
1008: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1009: "name", "description", tabularType, true, true,
1010: false, data, null);
1011: } catch (OpenDataException e) {
1012: caught = true;
1013: }
1014: if (caught == false)
1015: fail("Expected OpenDataException for tabular type and default value");
1016:
1017: caught = false;
1018: try {
1019: String[] itemNames = new String[] { "name1", "name2" };
1020: String[] itemDescriptions = new String[] { "desc1", "desc2" };
1021: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1022: SimpleType.INTEGER };
1023: CompositeType rowType = new CompositeType("rowTypeName",
1024: "rowDescription", itemNames, itemDescriptions,
1025: itemTypes);
1026:
1027: String[] indexNames = new String[] { "name1", "name2" };
1028: TabularType tabularType = new TabularType("typeName",
1029: "description", rowType, indexNames);
1030:
1031: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1032: "name", "description", tabularType, true, true,
1033: false, null, null);
1034: } catch (OpenDataException e) {
1035: caught = true;
1036: }
1037: if (caught == true)
1038: fail("Didn't expect OpenDataException for tabular type and null default value and legals");
1039:
1040: caught = false;
1041: try {
1042: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1043: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1044: "name", "description", arrayType, true, true,
1045: false, null, new String[] { "hello", "goodbye" });
1046: } catch (OpenDataException e) {
1047: caught = true;
1048: }
1049: if (caught == false)
1050: fail("Expected OpenDataException for array type and default value");
1051:
1052: caught = false;
1053: try {
1054: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1055: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1056: "name", "description", arrayType, true, true,
1057: false, null, new String[0]);
1058: } catch (OpenDataException e) {
1059: caught = true;
1060: }
1061: if (caught == true)
1062: fail("Didn't expect OpenDataException for array type and no default value and empty legals");
1063:
1064: caught = false;
1065: try {
1066: String[] itemNames = new String[] { "name1", "name2" };
1067: String[] itemDescriptions = new String[] { "desc1", "desc2" };
1068: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1069: SimpleType.INTEGER };
1070: CompositeType rowType = new CompositeType("rowTypeName",
1071: "rowDescription", itemNames, itemDescriptions,
1072: itemTypes);
1073:
1074: String[] indexNames = new String[] { "name1", "name2" };
1075: TabularType tabularType = new TabularType("typeName",
1076: "description", rowType, indexNames);
1077: TabularDataSupport data = new TabularDataSupport(
1078: tabularType);
1079:
1080: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1081: "name", "description", tabularType, true, true,
1082: false, null, new TabularDataSupport[] { data });
1083: } catch (OpenDataException e) {
1084: caught = true;
1085: }
1086: if (caught == false)
1087: fail("Expected OpenDataException for tabular type and legal values");
1088:
1089: caught = false;
1090: try {
1091: String[] itemNames = new String[] { "name1", "name2" };
1092: String[] itemDescriptions = new String[] { "desc1", "desc2" };
1093: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1094: SimpleType.INTEGER };
1095: CompositeType rowType = new CompositeType("rowTypeName",
1096: "rowDescription", itemNames, itemDescriptions,
1097: itemTypes);
1098:
1099: String[] indexNames = new String[] { "name1", "name2" };
1100: TabularType tabularType = new TabularType("typeName",
1101: "description", rowType, indexNames);
1102:
1103: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1104: "name", "description", tabularType, true, true,
1105: false, null, new TabularDataSupport[0]);
1106: } catch (OpenDataException e) {
1107: caught = true;
1108: }
1109: if (caught == true)
1110: fail("Didn't expect OpenDataException for tabular type and null default value and empty legals");
1111:
1112: caught = false;
1113: try {
1114: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1115: "name", "description", SimpleType.STRING, true,
1116: true, false, new Integer(3), new Integer[] {
1117: new Integer(2), new Integer(4) });
1118: } catch (OpenDataException e) {
1119: caught = true;
1120: }
1121: if (caught == false)
1122: fail("Expected OpenDataException for default value not a legal value");
1123: }
1124:
1125: public void testErrors4() throws Exception {
1126: boolean caught = false;
1127: try {
1128: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1129: null, "description", SimpleType.INTEGER, true,
1130: true, false, new Integer(3), new Integer(3),
1131: new Integer(4));
1132: } catch (IllegalArgumentException e) {
1133: caught = true;
1134: }
1135: if (caught == false)
1136: fail("Expected IllegalArgumentException for null name");
1137:
1138: caught = false;
1139: try {
1140: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1141: "", "description", SimpleType.INTEGER, true, true,
1142: false, new Integer(3), new Integer(3), new Integer(
1143: 4));
1144: } catch (IllegalArgumentException e) {
1145: caught = true;
1146: }
1147: if (caught == false)
1148: fail("Expected IllegalArgumentException for an empty name");
1149:
1150: caught = false;
1151: try {
1152: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1153: "name", null, SimpleType.INTEGER, true, true,
1154: false, new Integer(3), new Integer(3), new Integer(
1155: 4));
1156: } catch (IllegalArgumentException e) {
1157: caught = true;
1158: }
1159: if (caught == false)
1160: fail("Expected IllegalArgumentException for null description");
1161:
1162: caught = false;
1163: try {
1164: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1165: "name", "", SimpleType.INTEGER, true, true, false,
1166: new Integer(3), new Integer(3), new Integer(4));
1167: } catch (IllegalArgumentException e) {
1168: caught = true;
1169: }
1170: if (caught == false)
1171: fail("Expected IllegalArgumentException for an empty description");
1172:
1173: caught = false;
1174: try {
1175: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1176: "", "description", SimpleType.INTEGER, true, true,
1177: false, new Integer(3), new Integer(3), new Integer(
1178: 4));
1179: } catch (IllegalArgumentException e) {
1180: caught = true;
1181: }
1182: if (caught == false)
1183: fail("Expected IllegalArgumentException for an empty name");
1184:
1185: caught = false;
1186: try {
1187: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1188: "name", "description", null, true, true, false,
1189: new Integer(3), new Integer(3), new Integer(4));
1190: } catch (IllegalArgumentException e) {
1191: caught = true;
1192: }
1193: if (caught == false)
1194: fail("Expected IllegalArgumentException for null simple type");
1195:
1196: caught = false;
1197: try {
1198: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1199: "name", "description", SimpleType.STRING, true,
1200: true, false, new Integer(3), null, null);
1201: } catch (OpenDataException e) {
1202: caught = true;
1203: }
1204: if (caught == false)
1205: fail("Expected OpenDataException for wrong simple type and default value");
1206:
1207: caught = false;
1208: try {
1209: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1210: "name", "description", SimpleType.STRING, true,
1211: true, false, null, new Integer(3), null);
1212: } catch (OpenDataException e) {
1213: caught = true;
1214: }
1215: if (caught == false)
1216: fail("Expected OpenDataException for wrong simple type and minimum value");
1217:
1218: caught = false;
1219: try {
1220: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1221: "name", "description", SimpleType.STRING, true,
1222: true, false, null, null, new Integer(3));
1223: } catch (OpenDataException e) {
1224: caught = true;
1225: }
1226: if (caught == false)
1227: fail("Expected OpenDataException for wrong simple type and maximum value");
1228:
1229: caught = false;
1230: try {
1231: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1232: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1233: "name", "description", arrayType, true, true,
1234: false, new String[0], null, null);
1235: } catch (OpenDataException e) {
1236: caught = true;
1237: }
1238: if (caught == false)
1239: fail("Expected OpenDataException for array type and default value");
1240:
1241: caught = false;
1242: try {
1243: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1244: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1245: "name", "description", arrayType, true, true,
1246: false, null, null, null);
1247: } catch (OpenDataException e) {
1248: caught = true;
1249: }
1250: if (caught == true)
1251: fail("Didn't expect OpenDataException for array type and no default value");
1252:
1253: caught = false;
1254: try {
1255: String[] itemNames = new String[] { "name1", "name2" };
1256: String[] itemDescriptions = new String[] { "desc1", "desc2" };
1257: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1258: SimpleType.INTEGER };
1259: CompositeType rowType = new CompositeType("rowTypeName",
1260: "rowDescription", itemNames, itemDescriptions,
1261: itemTypes);
1262:
1263: String[] indexNames = new String[] { "name1", "name2" };
1264: TabularType tabularType = new TabularType("typeName",
1265: "description", rowType, indexNames);
1266: TabularDataSupport data = new TabularDataSupport(
1267: tabularType);
1268:
1269: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1270: "name", "description", tabularType, true, true,
1271: false, data, null, null);
1272: } catch (OpenDataException e) {
1273: caught = true;
1274: }
1275: if (caught == false)
1276: fail("Expected OpenDataException for tabular type and default value");
1277:
1278: caught = false;
1279: try {
1280: String[] itemNames = new String[] { "name1", "name2" };
1281: String[] itemDescriptions = new String[] { "desc1", "desc2" };
1282: OpenType[] itemTypes = new OpenType[] { SimpleType.STRING,
1283: SimpleType.INTEGER };
1284: CompositeType rowType = new CompositeType("rowTypeName",
1285: "rowDescription", itemNames, itemDescriptions,
1286: itemTypes);
1287:
1288: String[] indexNames = new String[] { "name1", "name2" };
1289: TabularType tabularType = new TabularType("typeName",
1290: "description", rowType, indexNames);
1291:
1292: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1293: "name", "description", tabularType, true, true,
1294: false, null, null, null);
1295: } catch (OpenDataException e) {
1296: caught = true;
1297: }
1298: if (caught == true)
1299: fail("Didn't expect OpenDataException for tabular type and null default value");
1300:
1301: caught = false;
1302: try {
1303: ArrayType arrayType = new ArrayType(1, SimpleType.STRING);
1304: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1305: "name", "description", arrayType, true, true,
1306: false, new String[] { "hello", "goodbye" }, null,
1307: null);
1308: } catch (OpenDataException e) {
1309: caught = true;
1310: }
1311: if (caught == false)
1312: fail("Expected OpenDataException for array type and default value");
1313:
1314: caught = false;
1315: try {
1316: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1317: "name", "description", SimpleType.STRING, true,
1318: true, false, new Integer(3), new Integer(4),
1319: new Integer(5));
1320: } catch (OpenDataException e) {
1321: caught = true;
1322: }
1323: if (caught == false)
1324: fail("Expected OpenDataException for default value less than minimum value");
1325:
1326: caught = false;
1327: try {
1328: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1329: "name", "description", SimpleType.INTEGER, true,
1330: true, false, new Integer(4), new Integer(4),
1331: new Integer(5));
1332: } catch (OpenDataException e) {
1333: caught = true;
1334: }
1335: if (caught == true)
1336: fail("Didn't expect OpenDataException for default value equal minimum value");
1337:
1338: caught = false;
1339: try {
1340: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1341: "name", "description", SimpleType.INTEGER, true,
1342: true, false, new Integer(6), new Integer(4),
1343: new Integer(5));
1344: } catch (OpenDataException e) {
1345: caught = true;
1346: }
1347: if (caught == false)
1348: fail("Expected OpenDataException for default value greater than maximum value");
1349:
1350: caught = false;
1351: try {
1352: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1353: "name", "description", SimpleType.INTEGER, true,
1354: true, false, new Integer(5), new Integer(4),
1355: new Integer(5));
1356: } catch (OpenDataException e) {
1357: caught = true;
1358: }
1359: if (caught == true)
1360: fail("Didn't expect OpenDataException for default value equal maximum value");
1361:
1362: caught = false;
1363: try {
1364: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1365: "name", "description", SimpleType.INTEGER, true,
1366: true, false, null, new Integer(4), new Integer(3));
1367: } catch (OpenDataException e) {
1368: caught = true;
1369: }
1370: if (caught == false)
1371: fail("Expected OpenDataException for minimum greater than maximum value");
1372:
1373: caught = false;
1374: try {
1375: OpenMBeanAttributeInfoSupport info = new OpenMBeanAttributeInfoSupport(
1376: "name", "description", SimpleType.INTEGER, true,
1377: true, false, null, new Integer(4), new Integer(4));
1378: } catch (OpenDataException e) {
1379: caught = true;
1380: }
1381: if (caught == true)
1382: fail("Didn't expect OpenDataException for minimum equal maximum value");
1383: }
1384: }
|