1 8 9 package test.javax.management.openmbean; 10 11 import java.util.Arrays ; 12 import java.util.HashSet ; 13 import java.util.List ; 14 import javax.management.openmbean.CompositeType ; 15 import javax.management.openmbean.OpenDataException ; 16 import javax.management.openmbean.OpenType ; 17 import javax.management.openmbean.SimpleType ; 18 import javax.management.openmbean.TabularType ; 19 20 import test.MX4JTestCase; 21 22 25 public class TabularTypeTest extends MX4JTestCase 26 { 27 private String [] itemNames = null; 28 private String [] itemDescriptions = null; 29 private OpenType [] itemTypes; 30 private String [] indexNames; 31 private CompositeType tShirtType; 32 private CompositeType wine; 33 private TabularType allTShirtTypes; 34 35 public TabularTypeTest(String s) 36 { 37 super(s); 38 } 39 40 protected void setUp() throws Exception 41 { 42 itemNames = new String []{"model", "color", "size", "price"}; 43 itemDescriptions = new String []{"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"}; 44 itemTypes = new OpenType []{SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT}; 45 indexNames = new String []{"model", "color", "size"}; 46 tShirtType = new CompositeType ("tShirt", "a TShirt", itemNames, itemDescriptions, itemTypes); 47 48 allTShirtTypes = new TabularType ("tShirts", "List of available TShirts", tShirtType, indexNames); 49 50 wine = 51 new CompositeType ("Wine", 52 "Nectar of the gods", 53 new String []{"Type", "Winery", "Vintage"}, 54 new String []{ 55 "Red, White, Rose, etc.", 56 "The wine's producer", 57 "The year the wine was made"}, 58 new OpenType []{ 59 SimpleType.STRING, 60 SimpleType.STRING, 61 SimpleType.INTEGER}); 62 } 63 64 public void testEquals() throws Exception 65 { 66 String [] itemNames2 = {"model", "color", "size", "price"}; 67 String [] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"}; 68 OpenType [] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT}; 69 String [] indexNames2 = {"model", "color", "size"}; 70 CompositeType tShirtType2 = new CompositeType ("tShirt", "a TShirt", itemNames2, itemDescriptions2, itemTypes2); 71 TabularType allTShirtTypes2 = new TabularType ("tShirts", "List of available TShirts", tShirtType2, indexNames2); 72 assertTrue(allTShirtTypes.equals(allTShirtTypes2)); 73 assertTrue(allTShirtTypes2.equals(allTShirtTypes)); 75 } 76 77 public void testNotEqual() throws Exception 78 { 79 String [] itemNames3 = {"model3", "color3", "size3", "price3"}; 80 String [] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"}; 81 OpenType [] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT}; 82 String [] indexNames3 = {"model3", "color3", "size3"}; 83 CompositeType tShirtType3 = new CompositeType ("tShirt3", "a TShirt", itemNames3, itemDescriptions3, itemTypes3); 84 TabularType allTShirtTypes3 = new TabularType ("tShirts3", "List of available TShirts", tShirtType3, indexNames3); 85 assertFalse(allTShirtTypes.equals(allTShirtTypes3)); 86 } 87 88 public void testGetRowType() 89 { 90 CompositeType test = allTShirtTypes.getRowType(); 91 assertEquals(test, tShirtType); 92 } 93 94 public void testGetIndexNames() 95 { 96 List temp = allTShirtTypes.getIndexNames(); 97 String [] tempList = (String [])temp.toArray(new String [temp.size()]); 98 99 assertEquals(tempList.length, indexNames.length); 100 for (int i = 0; i < tempList.length; i++) 102 { 103 assertTrue(tempList[i] == indexNames[i]); 104 } 105 } 106 107 public void testHashCode() throws Exception 108 { 109 String [] itemNames2 = {"model", "color", "size", "price"}; 110 String [] itemDescriptions2 = {"Manufacturer's model name", "The shirt's color", "How big is it", "How much does it cost"}; 111 OpenType [] itemTypes2 = {SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.FLOAT}; 112 String [] indexNames2 = {"model", "color", "size"}; 113 CompositeType tShirtType2 = new CompositeType ("tShirt", "a TShirt", itemNames2, itemDescriptions2, itemTypes2); 114 TabularType allTShirtTypes2 = new TabularType ("tShirts", "List of available TShirts", tShirtType2, indexNames2); 115 116 String [] itemNames3 = {"model3", "color3", "size3", "price3"}; 117 String [] itemDescriptions3 = {"TShirt's model name", "TShirt's color", "TShirt's size", "TShirt's price"}; 118 OpenType [] itemTypes3 = {SimpleType.STRING, SimpleType.BOOLEAN, SimpleType.STRING, SimpleType.FLOAT}; 119 String [] indexNames3 = {"model3", "color3", "size3"}; 120 CompositeType tShirtType3 = new CompositeType ("tShirt3", "a TShirt", itemNames3, itemDescriptions3, itemTypes3); 121 TabularType allTShirtTypes3 = new TabularType ("tShirts3", "List of available TShirts", tShirtType3, indexNames3); 122 123 int code1 = allTShirtTypes.hashCode(); 124 int code2 = allTShirtTypes2.hashCode(); 125 assertEquals(code2, "tShirts".hashCode() + tShirtType2.hashCode() + (new HashSet (Arrays.asList(indexNames))).hashCode()); 126 int code3 = allTShirtTypes3.hashCode(); 127 128 assertEquals(code1, code2); 129 assertTrue(code1 != code3); 130 } 131 132 public void testCtor() throws Exception 133 { 134 TabularType winecatalog = 135 new TabularType ("Wine Catalog", 136 "Catalog of available wines", 137 wine, 138 new String []{"Winery", "Vintage"}); 139 assertTrue("Unexpected name", 140 winecatalog.getTypeName().compareTo("Wine Catalog") == 0); 141 assertTrue("Unexpected CompositeType", 142 winecatalog.getRowType().equals(wine)); 143 List index = winecatalog.getIndexNames(); 144 assertTrue("Incorrect index size", index.size() == 2); 145 assertTrue("Unexpected index entries", 146 ((String )index.get(0)).compareTo("Winery") == 0 147 && ((String )index.get(1)).compareTo("Vintage") == 0); 148 } 149 150 public void testCtorNullName() throws Exception 151 { 152 try 153 { 154 new TabularType (null, 155 "Catalog of available wines", 156 wine, 157 new String []{"Winery", "Vintage"}); 158 fail("Expecting IllegalArgumentException"); 159 } 160 catch (IllegalArgumentException x) 161 { 162 } 163 } 164 165 public void testCtorEmptyName() throws Exception 166 { 167 try 168 { 169 new TabularType ("", 170 "Catalog of available wines", 171 wine, 172 new String []{"Winery", "Vintage"}); 173 fail("Expecting IllegalArgumentException"); 174 } 175 catch (IllegalArgumentException x) 176 { 177 } 178 } 179 180 public void testCtorNullDescriptor() throws Exception 181 { 182 try 183 { 184 new TabularType ("Wine Catalog", 185 null, 186 wine, 187 new String []{"Winery", "Vintage"}); 188 fail("Expecting IllegalArgumentException"); 189 } 190 catch (IllegalArgumentException x) 191 { 192 } 193 } 194 195 public void testCtorEmptyDescriptor() throws Exception 196 { 197 try 198 { 199 new TabularType ("Wine Catalog", 200 "", 201 wine, 202 new String []{"Winery", "Vintage"}); 203 fail("Expecting IllegalArgumentException"); 204 } 205 catch (IllegalArgumentException x) 206 { 207 } 208 } 209 210 public void testCtorNullRowType() throws Exception 211 { 212 try 213 { 214 new TabularType ("Wine Catalog", 215 "Catalog of available wines", 216 null, 217 new String []{"Winery", "Vintage"}); 218 fail("Expecting IllegalArgumentException"); 219 } 220 catch (IllegalArgumentException x) 221 { 222 } 223 } 224 225 public void testCtorNullIndex() throws Exception 226 { 227 try 228 { 229 new TabularType ("Wine Catalog", 230 "Catalog of available wines", 231 wine, 232 null); 233 fail("Expecting IllegalArgumentException"); 234 } 235 catch (IllegalArgumentException x) 236 { 237 } 238 } 239 240 public void testCtorEmptyIndex() throws Exception 241 { 242 try 243 { 244 new TabularType ("Wine Catalog", 245 "Catalog of available wines", 246 wine, 247 new String [0]); 248 fail("Expecting IllegalArgumentException"); 249 } 250 catch (IllegalArgumentException x) 251 { 252 } 253 } 254 255 public void testCtorBogusIndex() throws Exception 256 { 257 try 258 { 259 new TabularType ("Wine Catalog", 260 "Catalog of available wines", 261 wine, 262 new String []{"Region", "Vintage"}); 263 fail("Expecting OpenDataException"); 264 } 265 catch (OpenDataException x) 266 { 267 } 268 } 269 } 270 271 | Popular Tags |