1 8 package test.javax.management.openmbean; 9 10 13 14 import java.util.Arrays ; 15 import javax.management.MBeanOperationInfo ; 16 import javax.management.openmbean.OpenMBeanOperationInfo ; 17 import javax.management.openmbean.OpenMBeanOperationInfoSupport ; 18 import javax.management.openmbean.OpenMBeanParameterInfo ; 19 import javax.management.openmbean.OpenMBeanParameterInfoSupport ; 20 import javax.management.openmbean.SimpleType ; 21 22 import junit.framework.TestCase; 23 24 25 public class OpenMBeanOperationInfoSupportTest extends TestCase 26 { 27 OpenMBeanParameterInfo [] signature; 28 OpenMBeanParameterInfo [] params = null; 29 30 public OpenMBeanOperationInfoSupportTest(String s) 31 { 32 super(s); 33 } 34 35 protected void setUp() throws Exception 36 { 37 super.setUp(); 38 39 params = 40 new OpenMBeanParameterInfo []{ 41 42 new OpenMBeanParameterInfoSupport ("name", "The name", SimpleType.STRING) 43 }; 44 45 signature = new OpenMBeanParameterInfo []{ 46 new OpenMBeanParameterInfoSupport ("from", 47 "currency to convert from", 48 SimpleType.STRING), 49 new OpenMBeanParameterInfoSupport ("to", 50 "currency to convert to", 51 SimpleType.STRING)}; 52 } 53 54 protected void tearDown() throws Exception 55 { 56 super.tearDown(); 57 } 58 59 public void testCtor() throws Exception 60 { 61 OpenMBeanOperationInfoSupport info = 62 new OpenMBeanOperationInfoSupport ("exchangeRate", 63 "compute the exchange rate for two currencies", 64 signature, 65 SimpleType.FLOAT, 66 MBeanOperationInfo.INFO); 67 assertTrue("Null info constructed", info != null); 68 assertTrue("Unexpected name", 69 info.getName().compareTo("exchangeRate") == 0); 70 assertTrue("Unexpected description", 71 info.getDescription().compareTo("compute the exchange rate for two currencies") 72 == 0); 73 assertTrue("Unexpected return open type", 74 info.getReturnOpenType().equals(SimpleType.FLOAT)); 75 assertTrue("Unexpected signature", 76 Arrays.equals(info.getSignature(), signature)); 77 assertTrue("Unexpected impact", 78 info.getImpact() == MBeanOperationInfo.INFO); 79 } 80 81 public void testCtorNullName() throws Exception 82 { 83 try 84 { 85 OpenMBeanOperationInfoSupport info = 86 new OpenMBeanOperationInfoSupport (null, 87 "compute the exchange rate for two currencies", 88 signature, 89 SimpleType.FLOAT, 90 MBeanOperationInfo.INFO); 91 fail("Expecting IllegalArgumentException"); 92 } 93 catch (IllegalArgumentException x) 94 { 95 assertTrue(true); 96 } 97 } 98 99 public void testCtorEmptyName() throws Exception 100 { 101 try 102 { 103 OpenMBeanOperationInfoSupport info = 104 new OpenMBeanOperationInfoSupport ("", 105 "compute the exchange rate for two currencies", 106 signature, 107 SimpleType.FLOAT, 108 MBeanOperationInfo.INFO); 109 fail("Expecting IllegalArgumentException"); 110 } 111 catch (IllegalArgumentException x) 112 { 113 assertTrue(true); 114 } 115 } 116 117 public void testCtorNullDescription() throws Exception 118 { 119 try 120 { 121 OpenMBeanOperationInfoSupport info = 122 new OpenMBeanOperationInfoSupport ("exchangeRate", 123 null, 124 signature, 125 SimpleType.FLOAT, 126 MBeanOperationInfo.INFO); 127 fail("Expecting IllegalArgumentException"); 128 } 129 catch (IllegalArgumentException x) 130 { 131 assertTrue(true); 132 } 133 } 134 135 public void testCtorEmptyDescription() throws Exception 136 { 137 try 138 { 139 OpenMBeanOperationInfoSupport info = 140 new OpenMBeanOperationInfoSupport ("exchangeRate", 141 "", 142 signature, 143 SimpleType.FLOAT, 144 MBeanOperationInfo.INFO); 145 fail("Expecting IllegalArgumentException"); 146 } 147 catch (IllegalArgumentException x) 148 { 149 assertTrue(true); 150 } 151 } 152 153 public void testCtorNullSignature() throws Exception 154 { 155 OpenMBeanOperationInfoSupport info = 156 new OpenMBeanOperationInfoSupport ("exchangeRate", 157 "compute the exchange rate for two currencies", 158 null, 159 SimpleType.FLOAT, 160 MBeanOperationInfo.INFO); 161 assertTrue("Null info constructed", info != null); 162 assertTrue("Unexpected name", 163 info.getName().compareTo("exchangeRate") == 0); 164 assertTrue("Unexpected description", 165 info.getDescription().compareTo("compute the exchange rate for two currencies") 166 == 0); 167 assertTrue("Unexpected return open type", 168 info.getReturnOpenType().equals(SimpleType.FLOAT)); 169 assertTrue("Unexpected signature", 170 Arrays.equals(info.getSignature(), new OpenMBeanParameterInfo [0])); 171 assertTrue("Unexpected impact", 172 info.getImpact() == MBeanOperationInfo.INFO); 173 } 174 175 public void testCtorEmptySignature() throws Exception 176 { 177 OpenMBeanOperationInfoSupport info = 178 new OpenMBeanOperationInfoSupport ("exchangeRate", 179 "compute the exchange rate for two currencies", 180 new OpenMBeanParameterInfo [0], 181 SimpleType.FLOAT, 182 MBeanOperationInfo.INFO); 183 assertTrue("Null info constructed", info != null); 184 assertTrue("Unexpected name", 185 info.getName().compareTo("exchangeRate") == 0); 186 assertTrue("Unexpected description", 187 info.getDescription().compareTo("compute the exchange rate for two currencies") 188 == 0); 189 assertTrue("Unexpected return open type", 190 info.getReturnOpenType().equals(SimpleType.FLOAT)); 191 assertTrue("Unexpected signature", 192 Arrays.equals(info.getSignature(), new OpenMBeanParameterInfo [0])); 193 assertTrue("Unexpected impact", 194 info.getImpact() == MBeanOperationInfo.INFO); 195 } 196 197 public void testCtorNullReturnOpenType() throws Exception 198 { 199 try 200 { 201 OpenMBeanOperationInfoSupport info = 202 new OpenMBeanOperationInfoSupport ("exchangeRate", 203 "compute the exchange rate for two currencies", 204 signature, 205 null, 206 MBeanOperationInfo.INFO); 207 fail("Expecting IllegalArgumentException"); 208 } 209 catch (IllegalArgumentException x) 210 { 211 assertTrue(true); 212 } 213 } 214 215 public void testCtorBogusImpact() throws Exception 216 { 217 try 218 { 219 OpenMBeanOperationInfoSupport info = 220 new OpenMBeanOperationInfoSupport ("exchangeRate", 221 "compute the exchange rate for two currencies", 222 signature, 223 SimpleType.FLOAT, 224 42); 225 fail("Expecting IllegalArgumentException"); 226 } 227 catch (IllegalArgumentException x) 228 { 229 assertTrue(true); 230 } 231 } 232 233 public void testEquals() throws Exception 234 { 235 236 OpenMBeanOperationInfoSupport o1 = 237 new OpenMBeanOperationInfoSupport ("hello", "Say Hello", params, SimpleType.STRING, 1); 238 OpenMBeanOperationInfoSupport o2 = 239 new OpenMBeanOperationInfoSupport ("hello", "Say Hello", params, SimpleType.STRING, 1); 240 OpenMBeanOperationInfoSupport o3 = 241 new OpenMBeanOperationInfoSupport ("hello", "Say Hello", params, SimpleType.STRING, 0); 242 OpenMBeanOperationInfoSupport o4 = 243 new OpenMBeanOperationInfoSupport ("goAway", "Go Away", params, SimpleType.STRING, 1); 244 OpenMBeanOperationInfoSupport o5 = 245 new OpenMBeanOperationInfoSupport ("goAway", "Hey There", params, SimpleType.STRING, 1); 246 OpenMBeanOperationInfoSupport o6 = 247 new OpenMBeanOperationInfoSupport ("goAway", "Hey There", params, SimpleType.INTEGER, 1); 248 249 250 251 assertTrue(!o1.equals(null)); 253 assertTrue(o1.equals(o2)); 254 assertEquals(o1.hashCode(), o2.hashCode()); 255 assertTrue(!o1.equals(o3)); 256 assertTrue(o4.equals(o5)); 257 assertTrue(!o5.equals(o6)); 258 259 260 } 261 262 public void testHashCode() throws Exception 263 { 264 OpenMBeanOperationInfoSupport infoone = 265 new OpenMBeanOperationInfoSupport ("convertPrice", 266 "converts the price from one currency to another", 267 signature, 268 SimpleType.FLOAT, 269 MBeanOperationInfo.ACTION); 270 assertTrue("Unexpected hash code", infoone.hashCode() == hashCode(infoone)); 271 272 OpenMBeanOperationInfoSupport infotwo = 273 new OpenMBeanOperationInfoSupport ("convertPrice", 274 "multiply Currency by exchange rate to get TargetCurrency price", 275 signature, 276 SimpleType.FLOAT, 277 MBeanOperationInfo.ACTION); 278 assertTrue("Unexpected hash code", infotwo.hashCode() == hashCode(infoone)); 279 } 280 281 private int hashCode(OpenMBeanOperationInfo info) 282 { 283 int result = info.getName().hashCode(); 284 result += info.getReturnOpenType().hashCode(); 285 result += info.getImpact(); 286 result += java.util.Arrays.asList(info.getSignature()).hashCode(); 287 return result; 288 } 289 290 } 291 | Popular Tags |