1 8 9 package test.javax.management.openmbean; 10 11 import java.util.Arrays ; 12 import java.util.Set ; 13 import javax.management.openmbean.OpenMBeanConstructorInfo ; 14 import javax.management.openmbean.OpenMBeanConstructorInfoSupport ; 15 import javax.management.openmbean.OpenMBeanParameterInfo ; 16 import javax.management.openmbean.OpenMBeanParameterInfoSupport ; 17 import javax.management.openmbean.OpenType ; 18 import javax.management.openmbean.SimpleType ; 19 20 import junit.framework.TestCase; 21 import junit.textui.TestRunner; 22 23 25 public class OpenMBeanConstructorInfoSupportTest extends TestCase 26 { 27 private static class MyMBeanParameterInfo implements OpenMBeanParameterInfo 28 { 29 public boolean equals(Object o) 30 { 31 return false; 32 } 33 34 public Object getDefaultValue() 35 { 36 return null; 37 } 38 39 public String getDescription() 40 { 41 return null; 42 } 43 44 public Set getLegalValues() 45 { 46 return null; 47 } 48 49 public Comparable getMaxValue() 50 { 51 return null; 52 } 53 54 public Comparable getMinValue() 55 { 56 return null; 57 } 58 59 public String getName() 60 { 61 return null; 62 } 63 64 public OpenType getOpenType() 65 { 66 return null; 67 } 68 69 public boolean hasDefaultValue() 70 { 71 return false; 72 } 73 74 public boolean hasLegalValues() 75 { 76 return false; 77 } 78 79 public boolean hasMinValue() 80 { 81 return false; 82 } 83 84 public boolean hasMaxValue() 85 { 86 return false; 87 } 88 89 public boolean isValue(Object o) 90 { 91 return false; 92 } 93 94 public String toString() 95 { 96 return null; 97 } 98 } 99 100 private OpenMBeanParameterInfo [] signature; 101 102 public static void main(String [] args) 103 { 104 TestRunner.run(OpenMBeanConstructorInfoSupportTest.class); 105 } 106 107 public void testCtor() throws Exception 108 { 109 OpenMBeanConstructorInfoSupport info = 110 new OpenMBeanConstructorInfoSupport ("wine", 111 "Non-default constructor", 112 signature); 113 assertTrue("Null info constructed", info != null); 114 assertTrue("Unexpected name", info.getName().compareTo("wine") == 0); 115 assertTrue("Unexpected description", 116 info.getDescription().compareTo("Non-default constructor") == 0); 117 assertTrue("Unexpected signature", 118 Arrays.equals(info.getSignature(), signature)); 119 120 info = 121 new OpenMBeanConstructorInfoSupport ("wine", 122 "Non-default constructor", 123 null); 124 assertTrue("Null info constructed", info != null); 125 assertTrue("Unexpected name", info.getName().compareTo("wine") == 0); 126 assertTrue("Unexpected description", 127 info.getDescription().compareTo("Non-default constructor") == 0); 128 assertTrue("Unexpected signature", info.getSignature() == null || info.getSignature().length == 0); 129 130 info = 131 new OpenMBeanConstructorInfoSupport ("wine", 132 "Non-default constructor", 133 new OpenMBeanParameterInfoSupport [0]); 134 assertTrue("Null info constructed", info != null); 135 assertTrue("Unexpected name", info.getName().compareTo("wine") == 0); 136 assertTrue("Unexpected description", 137 info.getDescription().compareTo("Non-default constructor") == 0); 138 assertTrue("Unexpected signature", info.getSignature().length == 0); 139 } 140 141 public void testCtorNullName() throws Exception 142 { 143 try 144 { 145 OpenMBeanConstructorInfoSupport info = 146 new OpenMBeanConstructorInfoSupport (null, 147 "Non-default constructor", 148 signature); 149 fail("Expecting IllegalArgumentException"); 150 } 151 catch (IllegalArgumentException x) 152 { 153 assertTrue(true); 154 } 155 } 156 157 public void testCtorEmptyName() throws Exception 158 { 159 try 160 { 161 OpenMBeanConstructorInfoSupport info = 162 new OpenMBeanConstructorInfoSupport ("", 163 "Non-default constructor", 164 signature); 165 fail("Expecting IllegalArgumentException"); 166 } 167 catch (IllegalArgumentException x) 168 { 169 assertTrue(true); 170 } 171 } 172 173 public void testCtorNullDescription() throws Exception 174 { 175 try 176 { 177 OpenMBeanConstructorInfoSupport info = 178 new OpenMBeanConstructorInfoSupport ("wine", null, signature); 179 fail("Expecting IllegalArgumentException"); 180 } 181 catch (IllegalArgumentException x) 182 { 183 assertTrue(true); 184 } 185 } 186 187 public void testCtorEmptyDescription() throws Exception 188 { 189 try 190 { 191 OpenMBeanConstructorInfoSupport info = 192 new OpenMBeanConstructorInfoSupport ("wine", "", signature); 193 fail("Expecting IllegalArgumentException"); 194 } 195 catch (IllegalArgumentException x) 196 { 197 assertTrue(true); 198 } 199 } 200 201 public void testCtorBogusSignature() throws Exception 202 { 203 try 204 { 205 MyMBeanParameterInfo[] bogusig = 206 { 207 new MyMBeanParameterInfo(), 208 new MyMBeanParameterInfo(), 209 new MyMBeanParameterInfo()}; 210 211 OpenMBeanConstructorInfoSupport info = 212 new OpenMBeanConstructorInfoSupport ("wine", 213 "Non-default constructor", 214 bogusig); 215 fail("Expecting ArrayStoreException"); 216 } 217 catch (ArrayStoreException x) 218 { 219 assertTrue(true); 220 } 221 } 222 223 public void testEquals() throws Exception 224 { 225 OpenMBeanConstructorInfo infoone = 226 new OpenMBeanConstructorInfoSupport ("wine", "Vino", signature); 227 assertTrue("Null infoone constructed", infoone != null); 228 229 OpenMBeanConstructorInfo infotwo = 230 new OpenMBeanConstructorInfoSupport ("wine", 231 "Nectar of the gods", 232 signature); 233 assertTrue("Null infotwo constructed", infotwo != null); 234 235 assertTrue("Expected equality", infoone.equals(infotwo)); 236 237 OpenMBeanConstructorInfo infothree = 238 new OpenMBeanConstructorInfoSupport ("Vino", "Vino", signature); 239 assertTrue("Null infothree constructed", infothree != null); 240 241 assertFalse("Expected inequality based on name", 242 infothree.equals(infoone)); 243 244 OpenMBeanConstructorInfo infofour = 245 new OpenMBeanConstructorInfoSupport ("wine", 246 "Vino", 247 new OpenMBeanParameterInfoSupport [0]); 248 assertTrue("Null infofour constructed", infofour != null); 249 250 assertFalse("Expected inequality based on signature", 251 infofour.equals(infoone)); 252 } 253 254 public void testHashCode() throws Exception 255 { 256 OpenMBeanConstructorInfo infoone = 257 new OpenMBeanConstructorInfoSupport ("wine", "Vino", signature); 258 assertTrue("Null infoone constructed", infoone != null); 259 260 assertTrue("Unexpected hash code", 261 infoone.hashCode() == hashCode(infoone)); 262 263 OpenMBeanConstructorInfo infotwo = 264 new OpenMBeanConstructorInfoSupport ("wine", 265 "Nectar of the gods", 266 signature); 267 assertTrue("Null infotwo constructed", infotwo != null); 268 269 assertTrue("Expecting equal hash codes", 270 infoone.hashCode() == infotwo.hashCode()); 271 } 272 273 protected void setUp() 274 { 275 try 276 { 277 signature = 278 new OpenMBeanParameterInfoSupport []{ 279 new OpenMBeanParameterInfoSupport ("type", 280 "type of wine", 281 SimpleType.STRING, 282 "Red", 283 new String []{"Red", "White", "Rose"}), 284 new OpenMBeanParameterInfoSupport ("winery", 285 "who produced the wine", 286 SimpleType.STRING), 287 new OpenMBeanParameterInfoSupport ("vintage", 288 "when the wine was produced", 289 SimpleType.INTEGER, 290 null, 291 new Integer (1900), 292 new Integer (2000)) 293 }; 294 } 295 catch (Exception x) 296 { 297 fail(x.toString()); 298 } 299 } 300 301 protected void tearDown() 302 { 303 } 304 305 private int hashCode(OpenMBeanConstructorInfo info) 306 { 307 int result = info.getName().hashCode(); 308 result += Arrays.asList(info.getSignature()).hashCode(); 309 return result; 310 } 311 } 312 | Popular Tags |