1 23 24 27 28 package com.sun.enterprise.admin.mbeans; 29 30 import java.util.*; 31 32 import junit.framework.*; 34 import junit.textui.TestRunner; 35 36 40 public class JvmOptionsTest extends TestCase 41 { 42 public void testCreateNull() throws InvalidJvmOptionException 43 { 44 try 45 { 46 JvmOptions options = new JvmOptions(null); 47 Assert.assertTrue(false); 48 } 49 catch (IllegalArgumentException iae) 50 { 51 } 53 } 54 55 public void testZeroLength() throws InvalidJvmOptionException 56 { 57 JvmOptions options = new JvmOptions(new String [0]); 58 Assert.assertTrue(Arrays.equals(new String [0], options.getJvmOptions())); 59 } 60 61 public void testCreateJvmOptions() throws InvalidJvmOptionException 62 { 63 String [] sa = new String [] {"-x=y", "-a=b"}; 64 JvmOptions options = new JvmOptions(sa); 65 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 66 67 sa = new String [] {"-x=y -a=b", "-a=b"}; 68 options = new JvmOptions(sa); 69 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 70 71 sa = new String [] {"-x=y -x=y"}; 72 options = new JvmOptions(sa); 73 Assert.assertTrue(Arrays.equals( 74 new String [] {"-x=y"}, options.getJvmOptions())); 75 } 76 77 public void testCreateOptionNull() throws InvalidJvmOptionException 78 { 79 String [] sa = new String [] {"-x=y", null}; 80 try 81 { 82 JvmOptions options = new JvmOptions(sa); 83 Assert.assertTrue(false); 84 } 85 catch (IllegalArgumentException iae) 86 { 87 } 89 } 90 91 public void testAddJvmOptionsNull() throws InvalidJvmOptionException 92 { 93 String [] sa = new String [] {"-x=y", "-a=b"}; 94 JvmOptions options = new JvmOptions(sa); 95 try 96 { 97 options.addJvmOptions(null); 98 Assert.assertTrue(false); 99 } 100 catch (IllegalArgumentException iae) 101 { 102 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 103 } 104 } 105 106 public void testAddNullJvmOption() throws InvalidJvmOptionException 107 { 108 String [] sa = new String [] {"-x=y", "-a=b"}; 109 JvmOptions options = new JvmOptions(sa); 110 try 111 { 112 options.addJvmOptions(new String [] {null}); 113 Assert.assertTrue(false); 114 } 115 catch (IllegalArgumentException iae) 116 { 117 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 118 } 119 } 120 121 public void testAddJvmOptionsZeroLength() throws InvalidJvmOptionException 122 { 123 String [] sa = new String [] {"-x=y", "-a=b"}; 124 JvmOptions options = new JvmOptions(sa); 125 options.addJvmOptions(new String [0]); 126 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 127 } 128 129 public void testAddJvmOptions() throws InvalidJvmOptionException 130 { 131 String [] sa = new String [] {"-x=y", "-a=b"}; 132 JvmOptions options = new JvmOptions(sa); 133 String [] invalid = options.addJvmOptions(new String [] {"-c=d"}); 134 Assert.assertTrue(invalid.length == 0); 135 Assert.assertTrue(Arrays.equals(new String [] {"-x=y", "-a=b", "-c=d"}, 136 options.getJvmOptions())); 137 } 138 139 public void testAddDuplicateJvmOptions0() throws InvalidJvmOptionException 140 { 141 String [] sa = new String [] {"-x=y"}; 142 JvmOptions options = new JvmOptions(sa); 143 String [] invalid = options.addJvmOptions(new String [] {"-x=y"}); 144 Assert.assertTrue(Arrays.equals(new String [] {"-x=y"}, invalid)); 145 Assert.assertTrue(Arrays.equals(new String [] {"-x=y"}, 146 options.getJvmOptions())); 147 } 148 149 public void testAddDuplicateJvmOptions1() throws InvalidJvmOptionException 150 { 151 String [] sa = new String [] {"-x=y", "-a=b"}; 152 JvmOptions options = new JvmOptions(sa); 153 String [] invalid = options.addJvmOptions(new String [] {"-a=b"}); 154 Assert.assertTrue(Arrays.equals(new String [] {"-a=b"}, invalid)); 155 Assert.assertTrue(Arrays.equals(new String [] {"-x=y", "-a=b"}, 156 options.getJvmOptions())); 157 } 158 159 public void testAddDuplicateJvmOptions2() throws InvalidJvmOptionException 160 { 161 String [] sa = new String [] {"-x=y -a=b"}; 162 JvmOptions options = new JvmOptions(sa); 163 String [] invalid = options.addJvmOptions(new String [] {"-a=b"}); 164 Assert.assertTrue(Arrays.equals(new String [] {"-a=b"}, invalid)); 165 Assert.assertTrue(Arrays.equals(new String [] {"-x=y -a=b"}, 166 options.getJvmOptions())); 167 } 168 169 public void testAddDuplicateJvmOptions3() throws InvalidJvmOptionException 170 { 171 String [] sa = new String [] {"-x=y -a=b"}; 172 JvmOptions options = new JvmOptions(sa); 173 String [] invalid = options.addJvmOptions(new String [] {"-a=b", "-c=d"}); 174 Assert.assertTrue(Arrays.equals(new String [] {"-a=b"}, invalid)); 175 Assert.assertTrue(Arrays.equals(new String [] {"-x=y -a=b", "-c=d"}, 176 options.getJvmOptions())); 177 } 178 179 public void testAddDuplicateJvmOptions4() throws InvalidJvmOptionException 180 { 181 String [] sa = new String [] {"-x=y -a=b"}; 182 JvmOptions options = new JvmOptions(sa); 183 String [] invalid = options.addJvmOptions(new String [] {"-a=b -c=d"}); 184 Assert.assertTrue(invalid.length == 0); 185 Assert.assertTrue(Arrays.equals(new String [] {"-x=y -a=b", "-a=b -c=d"}, 186 options.getJvmOptions())); 187 } 188 189 public void testDeleteJvmOptionsNull() throws InvalidJvmOptionException 190 { 191 String [] sa = new String [] {"-x=y"}; 192 JvmOptions options = new JvmOptions(sa); 193 try 194 { 195 options.deleteJvmOptions(null); 196 } 197 catch (IllegalArgumentException iae) 198 { 199 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 200 } 201 } 202 203 public void testDeleteNullJvmOption() throws InvalidJvmOptionException 204 { 205 String [] sa = new String [] {"-x=y"}; 206 JvmOptions options = new JvmOptions(sa); 207 try 208 { 209 options.deleteJvmOptions(new String []{null}); 210 } 211 catch (IllegalArgumentException iae) 212 { 213 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 214 } 215 } 216 217 public void testDeleteJvmOptionsZeroLength() throws InvalidJvmOptionException 218 { 219 String [] sa = new String [] {"-x=y", "-a=b"}; 220 JvmOptions options = new JvmOptions(sa); 221 options.deleteJvmOptions(new String [0]); 222 Assert.assertTrue(Arrays.equals(sa, options.getJvmOptions())); 223 } 224 225 public void testDeleteJvmOptions() throws InvalidJvmOptionException 226 { 227 String [] sa = new String [] {"-x=y"}; 228 JvmOptions options = new JvmOptions(sa); 229 String [] invalid = options.deleteJvmOptions(new String []{"-x=y"}); 230 Assert.assertTrue(invalid.length == 0); 231 Assert.assertTrue(Arrays.equals( 232 new String [0], options.getJvmOptions())); 233 } 234 235 public void testDeleteJvmOptions1() throws InvalidJvmOptionException 236 { 237 String [] sa = new String [] {"-x=y", "-a=b"}; 238 JvmOptions options = new JvmOptions(sa); 239 String [] invalid = options.deleteJvmOptions(new String []{"-x=y"}); 240 Assert.assertTrue(invalid.length == 0); 241 Assert.assertTrue(Arrays.equals( 242 new String []{"-a=b"}, options.getJvmOptions())); 243 } 244 245 public void testDeleteJvmOptions2() throws InvalidJvmOptionException 246 { 247 String [] sa = new String [] {"-x=y -a=b"}; 248 JvmOptions options = new JvmOptions(sa); 249 String [] invalid = options.deleteJvmOptions(new String []{"-x=y"}); 250 Assert.assertTrue(invalid.length == 0); 251 Assert.assertTrue(Arrays.equals( 252 new String []{"-a=b"}, options.getJvmOptions())); 253 } 254 255 public void testDeleteJvmOptions3() throws InvalidJvmOptionException 256 { 257 String [] sa = new String [] {"-x=y -a=b -c=d"}; 258 JvmOptions options = new JvmOptions(sa); 259 String [] invalid = options.deleteJvmOptions(new String []{"-x=y", "-c=d"}); 260 Assert.assertTrue(invalid.length == 0); 261 Assert.assertTrue(Arrays.equals( 262 new String []{"-a=b"}, options.getJvmOptions())); 263 } 264 265 public void testDeleteJvmOptions4() throws InvalidJvmOptionException 266 { 267 String [] sa = new String [] {"-x=y -a=b", "-a=b -c=d"}; 268 JvmOptions options = new JvmOptions(sa); 269 String [] invalid = options.deleteJvmOptions(new String []{"-x=y", "-c=d"}); 270 Assert.assertTrue(invalid.length == 0); 271 Assert.assertTrue(Arrays.equals( 272 new String []{"-a=b"}, options.getJvmOptions())); 273 } 274 275 public void testDeleteJvmOptions5() throws InvalidJvmOptionException 276 { 277 String [] sa = new String [] {"-x=y"}; 278 JvmOptions options = new JvmOptions(sa); 279 String [] invalid = options.deleteJvmOptions(new String []{"-c=d"}); 280 Assert.assertTrue(Arrays.equals(invalid, new String []{"-c=d"})); 281 Assert.assertTrue(Arrays.equals( 282 new String []{"-x=y"}, options.getJvmOptions())); 283 } 284 285 public void testDeleteJvmOptions6() throws InvalidJvmOptionException 286 { 287 String [] sa = new String [] {"-x=y", "-a=b"}; 288 JvmOptions options = new JvmOptions(sa); 289 String [] invalid = options.deleteJvmOptions(new String []{"-a=b", "-c=d"}); 290 Assert.assertTrue(Arrays.equals(invalid, new String []{"-c=d"})); 291 Assert.assertTrue(Arrays.equals( 292 new String []{"-x=y"}, options.getJvmOptions())); 293 } 294 295 public void testDeleteJvmOptions7() throws InvalidJvmOptionException 296 { 297 String [] sa = new String [] {"-x=y "}; 298 JvmOptions options = new JvmOptions(sa); 299 String [] invalid = options.deleteJvmOptions(new String []{"-a=b"}); 300 Assert.assertTrue(Arrays.equals(invalid, new String []{"-a=b"})); 301 Assert.assertTrue(Arrays.equals( 302 new String []{"-x=y"}, options.getJvmOptions())); 303 } 304 305 public void testJvmOptions() throws InvalidJvmOptionException 306 { 307 String [] sa = new String [] {"-x=y"}; 308 JvmOptions options = new JvmOptions(sa); 309 310 options.addJvmOptions(new String []{"-a=b", "-c=d"}); 311 Assert.assertTrue(Arrays.equals( 312 new String []{"-x=y", "-a=b", "-c=d"}, options.getJvmOptions())); 313 314 options.addJvmOptions(new String []{"-a=b -c=d"}); 315 Assert.assertTrue(Arrays.equals( 316 new String []{"-x=y", "-a=b", "-c=d", "-a=b -c=d"}, options.getJvmOptions())); 317 String [] invalid = options.deleteJvmOptions(new String []{"-a=b"}); 318 Assert.assertTrue(invalid.length == 0); 319 } 320 321 public void testJvmOptionsElement() throws InvalidJvmOptionException 322 { 323 JvmOptionsElement e = new JvmOptionsElement("-x=y"); 324 Assert.assertFalse(e.hasNext()); 325 JvmOptionsElement next = new JvmOptionsElement("-a=b"); 326 e.setNext(next); 327 Assert.assertTrue(e.hasNext()); 328 Assert.assertEquals(next, e.next()); 329 JvmOptionsElement next1 = new JvmOptionsElement("-c=d"); 330 next.setNext(next1); 331 Assert.assertEquals(next1, e.next().next()); 332 JvmOptionsElement next2 = new JvmOptionsElement("-a=b -c=d"); 333 next1.setNext(next2); 334 335 boolean b = e.deleteJvmOption("-a=b"); 336 Assert.assertTrue(b); 337 } 338 339 public void testCreateInValidJvmOptions() 340 { 341 try 342 { 343 JvmOptions options = new JvmOptions(new String [] {"option_with_no_dash"}); 344 } 345 catch (InvalidJvmOptionException e) 346 { 347 } 349 } 350 351 public void testAddInValidJvmOptions() throws InvalidJvmOptionException 352 { 353 JvmOptions options = new JvmOptions(new String [] {"-option_with_dash"}); 354 try 355 { 356 options.addJvmOptions(new String [] {"option_with_no_dash"}); 357 } 358 catch (InvalidJvmOptionException e) 359 { 360 } 362 } 363 364 public void testDeleteInValidJvmOptions() throws InvalidJvmOptionException 365 { 366 JvmOptions options = new JvmOptions(new String [] {"-option_with_dash"}); 367 options.deleteJvmOptions(new String [] {"option_with_no_dash"}); 368 Assert.assertTrue(Arrays.equals( 369 new String [] {"-option_with_dash"}, options.getJvmOptions())); 370 } 371 372 public void testQuotedOptions() throws InvalidJvmOptionException 373 { 374 String [] options = new String [] {"-Dfile=\"a b\""}; 375 JvmOptions jvmOptions = new JvmOptions(options); 376 Assert.assertTrue(Arrays.equals(options, jvmOptions.getJvmOptions())); 377 jvmOptions.deleteJvmOptions(options); 378 379 try { 380 new JvmOptions(new String [] {"-Dfile=\""}); 381 Assert.assertTrue(false); 382 } catch (InvalidJvmOptionException e) {} 383 384 try { 385 new JvmOptions(new String [] {"-Dx=\"a\" -Dy=\"b"}); 386 Assert.assertTrue(false); 387 } catch (InvalidJvmOptionException e) {} 388 389 try { 390 new JvmOptions(new String [] {"-Dx=\"a\" -Dy=\"b"}); 391 Assert.assertTrue(false); 392 } catch (InvalidJvmOptionException e) {} 393 } 394 395 public void testAppServerJvmOptions() 396 { 397 String [] options = new String [] { 398 "-client", 399 "-Djava.endorsed.dirs=${com.sun.aas.installRoot}/lib/endorsed", 400 "-Djava.security.policy=${com.sun.aas.instanceRoot}/config/server.policy", 401 "-Djava.security.auth.login.config=${com.sun.aas.instanceRoot}/config/login.conf", 402 "-Dsun.rmi.dgc.server.gcInterval=3600000", 403 "-Dcom.sun.web.console.appbase=/${com.sun.aas.installRoot}/lib/install/applications/com_sun_web_ui", 404 "-Xmx512m", 405 "-Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks", 406 "-Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks", 407 "-Djava.ext.dirs=${com.sun.aas.javaRoot}/jre/lib/ext${path.separator}${com.sun.aas.instanceRoot}/lib/ext", 408 "-Djdbc.drivers=com.pointbase.jdbc.jdbcUniversalDriver", 409 "-Djavax.xml.transform.TransformerFactory=org.apache.xalan.xsltc.trax.TransformerFactoryImpl" 410 }; 411 try 412 { 413 JvmOptions jvmOptions = new JvmOptions(options); 414 Assert.assertTrue(Arrays.equals(options, jvmOptions.getJvmOptions())); 415 } 416 catch (InvalidJvmOptionException e) 417 { 418 Assert.assertTrue(false); 419 } 420 } 421 422 private void printOptions(JvmOptions o) 423 { 424 String [] options = o.getJvmOptions(); 425 System.out.println("============================"); 426 for (int i = 0; i < options.length; i++) 427 { 428 System.out.println("Option[" + options[i] + "]"); 429 } 430 System.out.println("============================"); 431 } 432 433 public JvmOptionsTest(String name) throws Exception 434 { 435 super(name); 436 } 437 438 protected void setUp() 439 { 440 } 441 442 protected void tearDown() 443 { 444 } 445 446 public static junit.framework.Test suite() 447 { 448 TestSuite suite = new TestSuite(JvmOptionsTest.class); 449 return suite; 450 } 451 452 public static void main(String args[]) throws Exception 453 { 454 final TestRunner runner= new TestRunner(); 455 final TestResult result = runner.doRun(JvmOptionsTest.suite(), false); 456 System.exit(result.errorCount() + result.failureCount()); 457 } 458 } | Popular Tags |