1 8 package test.javax.management.openmbean; 9 10 13 14 import javax.management.openmbean.ArrayType ; 15 import javax.management.openmbean.CompositeData ; 16 import javax.management.openmbean.CompositeDataSupport ; 17 import javax.management.openmbean.CompositeType ; 18 import javax.management.openmbean.OpenType ; 19 import javax.management.openmbean.SimpleType ; 20 21 import junit.framework.TestCase; 22 23 24 public class ArrayTypeTest extends TestCase 25 { 26 public ArrayTypeTest(String s) 27 { 28 super(s); 29 } 30 31 protected void setUp() throws Exception 32 { 33 super.setUp(); 34 } 35 36 protected void tearDown() throws Exception 37 { 38 super.tearDown(); 39 } 40 41 public void testIsValue() throws Exception 42 { 43 ArrayType simple = new ArrayType (1, SimpleType.STRING); 44 45 String [] stringarray = {"do", "re", "mi"}; 46 assertTrue("Expecting equality for array of strings", simple.isValue(stringarray)); 47 assertFalse("Expecting inequality for array of ints", simple.isValue(new int[]{1, 2, 3, 4})); 48 assertFalse("Expecting inequality for null", simple.isValue(null)); 49 assertFalse("Expecting inequality for string", simple.isValue("fa")); 50 51 String [] items = {"type", "winery", "vintage"}; 52 String [] descriptions = {"Type of wine", "Wine producer", "Year produced"}; 53 OpenType [] types = {SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER}; 54 CompositeType wine = new CompositeType ("wine", "nectar of the gods", items, descriptions, types); 55 56 items = new String []{"type", "brewery"}; 57 descriptions = new String []{"Type of beer", "Beer producer"}; 58 types = new OpenType []{SimpleType.STRING, SimpleType.STRING}; 59 CompositeType beer = new CompositeType ("beer", "a meal in a glass", items, descriptions, types); 60 61 ArrayType composite = new ArrayType (1, wine); 62 63 CompositeDataSupport amarone = 64 new CompositeDataSupport (wine, 65 new String []{"type", "winery", "vintage"}, 66 new Object []{"red", "Allegrini", new Integer (1996)}); 67 CompositeDataSupport orvieto = 68 new CompositeDataSupport (wine, 69 new String []{"type", "winery", "vintage"}, 70 new Object []{"white", "Ruffino", new Integer (2002)}); 71 CompositeData [] winecellar = {amarone, orvieto}; 72 CompositeData [] sparsewines = {amarone, null, orvieto}; 73 74 CompositeDataSupport stout = 75 new CompositeDataSupport (beer, 76 new String []{"type", "brewery"}, 77 new Object []{"stout", "Guiness"}); 78 CompositeData [] beerlist = {stout}; 79 80 CompositeData [] mixer = {amarone, stout, orvieto}; 81 82 assertTrue("Expecting equality for array of wines", composite.isValue(winecellar)); 83 assertTrue("Expecting equality for sparse array of wines", composite.isValue(sparsewines)); 84 assertFalse("Expecting inequality for array of beer", composite.isValue(beerlist)); 85 assertFalse("Expecting inequality for mixed array", composite.isValue(mixer)); 86 assertFalse("Expecting inequality for single wine", composite.isValue(orvieto)); 87 88 ArrayType winematrix = new ArrayType (2, wine); 89 90 CompositeData [][] matrix = {{amarone, orvieto}, {orvieto, amarone}}; 91 assertTrue("Expecting equality for wine matrix", winematrix.isValue(matrix)); 92 assertFalse("Expecting inequality for wine vector", winematrix.isValue(winecellar)); 93 94 winematrix = new ArrayType (2, wine); 95 CompositeData [][] matrix2 = new CompositeData [1][1]; 96 assertTrue("Expecting equality for wine matrix", winematrix.isValue(matrix2)); 97 } 98 99 public void testEquals() throws Exception 100 { 101 ArrayType a1 = new ArrayType (1, SimpleType.LONG); 102 ArrayType a2 = new ArrayType (1, SimpleType.LONG); 103 ArrayType a3 = new ArrayType (2, SimpleType.LONG); 104 ArrayType a4 = new ArrayType (2, SimpleType.STRING); 105 106 assertTrue(a1.equals(a2)); 107 assertTrue(!a1.equals(a3)); 108 assertTrue(!a1.equals(a4)); 109 110 111 } 112 113 public void testCompositeEquals() throws Exception 114 { 115 String [] items = {"type", "winery", "vintage"}; 116 String [] descriptions = {"Type of wine", "Wine producer", "Year produced"}; 117 OpenType [] types = {SimpleType.STRING, SimpleType.STRING, SimpleType.DATE}; 118 CompositeType californiaWine = new CompositeType ("California", "Vino", items, descriptions, types); 119 ArrayType aone = new ArrayType (2, californiaWine); 120 ArrayType atwo = new ArrayType (2, californiaWine); 121 assertTrue("Expecting equality for identical composite types", aone.equals(atwo)); 122 123 CompositeType italianWine = new CompositeType ("Italia", "Vino", items, descriptions, types); 124 atwo = new ArrayType (2, italianWine); 125 assertFalse("Expecting inequality for different composite types", aone.equals(atwo)); 126 } 127 128 public void testClassName() throws Exception 129 { 130 ArrayType a1 = new ArrayType (2, SimpleType.STRING); 131 assertEquals(a1.getClassName(), "[[Ljava.lang.String;"); 132 assertEquals(a1.getTypeName(), "[[Ljava.lang.String;"); 133 134 } 135 136 public void testHashCode() throws Exception 137 { 138 139 140 ArrayType a1 = new ArrayType (2, SimpleType.STRING); 141 ArrayType a2 = new ArrayType (2, SimpleType.STRING); 142 143 assertTrue(a1.hashCode() == a2.hashCode()); 144 145 } 146 147 public void testBadSize() throws Exception 148 { 149 try 150 { 151 ArrayType t = new ArrayType (0, SimpleType.STRING); 152 } 153 catch (IllegalArgumentException x) 154 { 155 assertTrue(true); } 157 } 158 } 159 | Popular Tags |