1 7 package com.inversoft.config.test; 8 9 10 import java.io.File ; 11 import java.io.FileInputStream ; 12 import java.io.FileNotFoundException ; 13 import java.io.FileReader ; 14 import java.io.InputStream ; 15 import java.net.MalformedURLException ; 16 import java.net.URL ; 17 18 import junit.framework.TestCase; 19 20 import org.jdom.Document; 21 import org.jdom.Element; 22 import org.xml.sax.InputSource ; 23 24 import com.inversoft.config.ConfigFactoryRegistry; 25 import com.inversoft.config.ConfigMediator; 26 import com.inversoft.util.FileTools; 27 28 29 38 public class ConfigMediatorTest extends TestCase { 39 40 43 public ConfigMediatorTest(String name) { 44 super(name); 45 } 46 47 48 51 public void testSingle() { 52 53 Element rootElement = new Element("test"); 54 Document document = new Document(rootElement); 55 56 TestConfigFactory factory = new TestConfigFactory(); 57 ConfigFactoryRegistry.register("test", factory); 58 ConfigMediator mediator = null; 59 60 mediator = new ConfigMediator(); 61 TestConfigFactory.createBuilder = true; 62 TestConfigFactory.createRegistry = false; 63 TestConfigFactory.nullRegistry = false; 64 TestConfigBuilder.built = false; 65 TestConfigBuilder.commited = false; 66 try { 67 mediator.mediate(new Document [] {document}); 68 assertTrue("Should have called built", TestConfigBuilder.built && 69 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 70 } catch (Exception e) { 71 fail(e.toString()); 72 } 73 74 mediator = new ConfigMediator(); 75 TestConfigFactory.createBuilder = false; 76 TestConfigFactory.createRegistry = true; 77 TestConfigFactory.nullRegistry = false; 78 TestConfigBuilder.built = false; 79 TestConfigBuilder.commited = false; 80 try { 81 mediator.mediate(new Document [] {document}); 82 assertTrue("Should have called built", TestConfigBuilder.built && 83 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 84 } catch (Exception e) { 85 fail(e.toString()); 86 } 87 88 mediator = new ConfigMediator(); 89 TestConfigFactory.createBuilder = false; 90 TestConfigFactory.createRegistry = false; 91 TestConfigFactory.nullRegistry = true; 92 TestConfigBuilder.built = false; 93 TestConfigBuilder.commited = false; 94 try { 95 mediator.mediate(new Document [] {document}); 96 assertTrue("Should have called built", TestConfigBuilder.built && 97 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 98 } catch (Exception e) { 99 e.printStackTrace(); 100 fail(e.toString()); 101 } 102 } 103 104 108 public void testMultiple() { 109 110 Element rootElement = new Element("test"); 111 Document document = new Document(rootElement); 112 Element rootElement2 = new Element("test2"); 113 Document document2 = new Document(rootElement2); 114 115 TestConfigFactory factory = new TestConfigFactory(); 116 TestConfigFactory2 factory2 = new TestConfigFactory2(); 117 118 ConfigFactoryRegistry.register("test", factory); 119 ConfigFactoryRegistry.register("test2", factory2); 120 ConfigMediator mediator = null; 121 122 mediator = new ConfigMediator(); 123 TestConfigFactory.createBuilder = true; 124 TestConfigFactory.createRegistry = false; 125 TestConfigFactory.nullRegistry = false; 126 TestConfigFactory2.createBuilder = false; 127 TestConfigFactory2.createRegistry = false; 128 TestConfigFactory2.nullRegistry = true; 129 TestConfigBuilder.built = false; 130 TestConfigBuilder2.built = false; 131 TestConfigBuilder.commited = false; 132 TestConfigBuilder2.commited = false; 133 try { 134 mediator.mediate(new Document [] {document, document2}); 135 assertTrue("Should have called built", TestConfigBuilder.built && 136 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 137 assertTrue("Should have called built2", TestConfigBuilder2.built && 138 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 139 } catch (Exception e) { 140 fail(e.toString()); 141 } 142 143 mediator = new ConfigMediator(); 144 TestConfigFactory.createBuilder = false; 145 TestConfigFactory.createRegistry = true; 146 TestConfigFactory.nullRegistry = false; 147 TestConfigFactory2.createBuilder = true; 148 TestConfigFactory2.createRegistry = false; 149 TestConfigFactory2.nullRegistry = false; 150 TestConfigBuilder.built = false; 151 TestConfigBuilder2.built = false; 152 TestConfigBuilder.commited = false; 153 TestConfigBuilder2.commited = false; 154 try { 155 mediator.mediate(new Document [] {document, document2}); 156 assertTrue("Should have called built", TestConfigBuilder.built && 157 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 158 assertTrue("Should have called built2", TestConfigBuilder2.built && 159 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 160 } catch (Exception e) { 161 fail(e.toString()); 162 } 163 164 mediator = new ConfigMediator(); 165 TestConfigFactory.createBuilder = false; 166 TestConfigFactory.createRegistry = false; 167 TestConfigFactory.nullRegistry = true; 168 TestConfigFactory2.createBuilder = false; 169 TestConfigFactory2.createRegistry = true; 170 TestConfigFactory2.nullRegistry = true; 171 TestConfigBuilder.built = false; 172 TestConfigBuilder2.built = false; 173 TestConfigBuilder.commited = false; 174 TestConfigBuilder2.commited = false; 175 try { 176 mediator.mediate(new Document [] {document, document2}); 177 assertTrue("Should have called built", TestConfigBuilder.built && 178 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 179 assertTrue("Should have called built2", TestConfigBuilder2.built && 180 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 181 } catch (Exception e) { 182 fail(e.toString()); 183 } 184 } 185 186 190 public void testMultipleSame() { 191 192 Element rootElement = new Element("test"); 193 Document document = new Document(rootElement); 194 Element rootElement2 = new Element("test2"); 195 Document document2 = new Document(rootElement2); 196 197 TestConfigFactory factory = new TestConfigFactory(); 198 TestConfigFactory factory2 = new TestConfigFactory(); 199 200 ConfigFactoryRegistry.register("test", factory); 201 ConfigFactoryRegistry.register("test2", factory2); 202 ConfigMediator mediator = null; 203 204 mediator = new ConfigMediator(); 205 TestConfigFactory.createBuilder = true; 206 TestConfigFactory.createRegistry = false; 207 TestConfigFactory.nullRegistry = false; 208 TestConfigFactory2.createBuilder = false; 209 TestConfigFactory2.createRegistry = false; 210 TestConfigFactory2.nullRegistry = true; 211 TestConfigBuilder.built = false; 212 TestConfigBuilder2.built = false; 213 TestConfigBuilder.commited = false; 214 TestConfigBuilder2.commited = false; 215 try { 216 mediator.mediate(new Document [] {document, document2}); 217 assertTrue("Should have called built", TestConfigBuilder.built && 218 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 219 assertTrue("Should not have called built2", !TestConfigBuilder2.built && 220 !TestConfigBuilder2.rebuilt && !TestConfigBuilder2.commited); 221 } catch (Exception e) { 222 fail(e.toString()); 223 } 224 225 mediator = new ConfigMediator(); 226 TestConfigFactory.createBuilder = false; 227 TestConfigFactory.createRegistry = true; 228 TestConfigFactory.nullRegistry = false; 229 TestConfigFactory2.createBuilder = true; 230 TestConfigFactory2.createRegistry = false; 231 TestConfigFactory2.nullRegistry = false; 232 TestConfigBuilder.built = false; 233 TestConfigBuilder2.built = false; 234 TestConfigBuilder.commited = false; 235 TestConfigBuilder2.commited = false; 236 try { 237 mediator.mediate(new Document [] {document, document2}); 238 assertTrue("Should have called built", TestConfigBuilder.built && 239 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 240 assertTrue("Should not have called built2", !TestConfigBuilder2.built && 241 !TestConfigBuilder2.rebuilt && !TestConfigBuilder2.commited); 242 } catch (Exception e) { 243 fail(e.toString()); 244 } 245 246 mediator = new ConfigMediator(); 247 TestConfigFactory.createBuilder = false; 248 TestConfigFactory.createRegistry = false; 249 TestConfigFactory.nullRegistry = true; 250 TestConfigFactory2.createBuilder = false; 251 TestConfigFactory2.createRegistry = true; 252 TestConfigFactory2.nullRegistry = true; 253 TestConfigBuilder.built = false; 254 TestConfigBuilder2.built = false; 255 TestConfigBuilder.commited = false; 256 TestConfigBuilder2.commited = false; 257 try { 258 mediator.mediate(new Document [] {document, document2}); 259 assertTrue("Should have called built", TestConfigBuilder.built && 260 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 261 assertTrue("Should not have called built2", !TestConfigBuilder2.built && 262 !TestConfigBuilder2.rebuilt && !TestConfigBuilder2.commited); 263 } catch (Exception e) { 264 fail(e.toString()); 265 } 266 } 267 268 271 public void testFailure() { 272 273 Element rootElement = new Element("failuretest"); 274 Document document = new Document(rootElement); 275 276 TestConfigFactory factory = new TestConfigFactory(); 277 278 ConfigFactoryRegistry.register("notCorrect", factory); 279 ConfigMediator mediator = null; 280 281 mediator = new ConfigMediator(); 282 TestConfigFactory.createBuilder = true; 283 TestConfigFactory.createRegistry = false; 284 TestConfigFactory.nullRegistry = false; 285 try { 286 mediator.mediate(new Document [] {document}); 287 fail("Should have errored out"); 288 } catch (Exception e) { 289 System.out.println(e.toString()); 290 } 291 } 292 293 297 public void testMultipleRebuild() { 298 299 Element rootElement = new Element("test"); 300 Document document = new Document(rootElement); 301 Element rootElement2 = new Element("test2"); 302 Document document2 = new Document(rootElement2); 303 304 TestConfigFactory factory = new TestConfigFactory(); 305 TestConfigFactory2 factory2 = new TestConfigFactory2(); 306 307 ConfigFactoryRegistry.register("test", factory); 308 ConfigFactoryRegistry.register("test2", factory2); 309 ConfigMediator mediator = null; 310 311 mediator = new ConfigMediator(); 312 TestConfigFactory.createBuilder = true; 313 TestConfigFactory.createRegistry = false; 314 TestConfigFactory.nullRegistry = false; 315 TestConfigFactory2.createBuilder = false; 316 TestConfigFactory2.createRegistry = false; 317 TestConfigFactory2.nullRegistry = true; 318 TestConfigBuilder.built = false; 319 TestConfigBuilder2.built = false; 320 TestConfigBuilder.rebuilt = false; 321 TestConfigBuilder2.rebuilt = false; 322 TestConfigBuilder.commited = false; 323 TestConfigBuilder2.commited = false; 324 try { 325 mediator.mediate(new Document [] {document, document2}); 326 assertTrue("Should have called built", TestConfigBuilder.built && 327 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 328 assertTrue("Should have called built2", TestConfigBuilder2.built && 329 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 330 mediator.rebuild(new Document [] {document, document2}); 331 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 332 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 333 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 334 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 335 } catch (Exception e) { 336 fail(e.toString()); 337 } 338 339 mediator = new ConfigMediator(); 340 TestConfigFactory.createBuilder = false; 341 TestConfigFactory.createRegistry = true; 342 TestConfigFactory.nullRegistry = false; 343 TestConfigFactory2.createBuilder = true; 344 TestConfigFactory2.createRegistry = false; 345 TestConfigFactory2.nullRegistry = false; 346 TestConfigBuilder.built = false; 347 TestConfigBuilder2.built = false; 348 TestConfigBuilder.rebuilt = false; 349 TestConfigBuilder2.rebuilt = false; 350 TestConfigBuilder.commited = false; 351 TestConfigBuilder2.commited = false; 352 try { 353 mediator.mediate(new Document [] {document, document2}); 354 assertTrue("Should have called built", TestConfigBuilder.built && 355 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 356 assertTrue("Should have called built2", TestConfigBuilder2.built && 357 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 358 mediator.rebuild(new Document [] {document, document2}); 359 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 360 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 361 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 362 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 363 } catch (Exception e) { 364 fail(e.toString()); 365 } 366 367 mediator = new ConfigMediator(); 368 TestConfigFactory.createBuilder = false; 369 TestConfigFactory.createRegistry = false; 370 TestConfigFactory.nullRegistry = true; 371 TestConfigFactory2.createBuilder = false; 372 TestConfigFactory2.createRegistry = true; 373 TestConfigFactory2.nullRegistry = true; 374 TestConfigBuilder.built = false; 375 TestConfigBuilder2.built = false; 376 TestConfigBuilder.rebuilt = false; 377 TestConfigBuilder2.rebuilt = false; 378 TestConfigBuilder.commited = false; 379 TestConfigBuilder2.commited = false; 380 try { 381 mediator.mediate(new Document [] {document, document2}); 382 assertTrue("Should have called built", TestConfigBuilder.built && 383 !TestConfigBuilder.rebuilt && TestConfigBuilder2.commited); 384 assertTrue("Should have called built2", TestConfigBuilder2.built && 385 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 386 mediator.rebuild(new Document [] {document, document2}); 387 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 388 TestConfigBuilder.rebuilt&& TestConfigBuilder.commited); 389 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 390 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 391 } catch (Exception e) { 392 fail(e.toString()); 393 } 394 } 395 396 399 public void testURLs() { 400 401 URL [] urls = new URL [2]; 402 File file = new File (FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 403 File file2 = new File (FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 404 405 try { 406 urls[0] = file.toURL(); 407 urls[1] = file2.toURL(); 408 } catch (MalformedURLException e) { 409 fail(e.toString()); 410 } 411 412 TestConfigFactory factory = new TestConfigFactory(); 413 TestConfigFactory2 factory2 = new TestConfigFactory2(); 414 415 ConfigFactoryRegistry.register("test", factory); 416 ConfigFactoryRegistry.register("test2", factory2); 417 ConfigMediator mediator = null; 418 419 mediator = new ConfigMediator(); 420 TestConfigFactory.createBuilder = true; 421 TestConfigFactory.createRegistry = false; 422 TestConfigFactory.nullRegistry = false; 423 TestConfigFactory2.createBuilder = false; 424 TestConfigFactory2.createRegistry = false; 425 TestConfigFactory2.nullRegistry = true; 426 TestConfigBuilder.built = false; 427 TestConfigBuilder2.built = false; 428 TestConfigBuilder.rebuilt = false; 429 TestConfigBuilder2.rebuilt = false; 430 TestConfigBuilder.commited = false; 431 TestConfigBuilder2.commited = false; 432 try { 433 mediator.mediate(urls); 434 assertTrue("Should have called built", TestConfigBuilder.built && 435 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 436 assertTrue("Should have called built2", TestConfigBuilder2.built && 437 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 438 mediator.rebuild(urls); 439 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 440 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 441 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 442 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 443 } catch (Exception e) { 444 fail(e.toString()); 445 } 446 } 447 448 451 public void testInputStreams() { 452 453 InputStream [] streams = new InputStream [2]; 454 try { 455 streams[0] = new FileInputStream ( 456 FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 457 streams[1] = new FileInputStream ( 458 FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 459 } catch (FileNotFoundException e) { 460 fail(e.toString()); 461 } 462 463 TestConfigFactory factory = new TestConfigFactory(); 464 TestConfigFactory2 factory2 = new TestConfigFactory2(); 465 466 ConfigFactoryRegistry.register("test", factory); 467 ConfigFactoryRegistry.register("test2", factory2); 468 ConfigMediator mediator = null; 469 470 mediator = new ConfigMediator(); 471 TestConfigFactory.createBuilder = true; 472 TestConfigFactory.createRegistry = false; 473 TestConfigFactory.nullRegistry = false; 474 TestConfigFactory2.createBuilder = false; 475 TestConfigFactory2.createRegistry = false; 476 TestConfigFactory2.nullRegistry = true; 477 TestConfigBuilder.built = false; 478 TestConfigBuilder2.built = false; 479 TestConfigBuilder.rebuilt = false; 480 TestConfigBuilder2.rebuilt = false; 481 TestConfigBuilder.commited = false; 482 TestConfigBuilder2.commited = false; 483 try { 484 mediator.mediate(streams); 485 assertTrue("Should have called built", TestConfigBuilder.built && 486 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 487 assertTrue("Should have called built2", TestConfigBuilder2.built && 488 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 489 490 try { 491 streams[0] = new FileInputStream ( 492 FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 493 streams[1] = new FileInputStream ( 494 FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 495 } catch (FileNotFoundException e) { 496 fail(e.toString()); 497 } 498 mediator.rebuild(streams); 499 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 500 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 501 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 502 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 503 } catch (Exception e) { 504 fail(e.toString()); 505 } 506 } 507 508 511 public void testReaders() { 512 513 FileReader [] files = new FileReader [2]; 514 try { 515 files[0] = new FileReader ( 516 FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 517 files[1] = new FileReader ( 518 FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 519 } catch (FileNotFoundException e) { 520 fail(e.toString()); 521 } 522 523 TestConfigFactory factory = new TestConfigFactory(); 524 TestConfigFactory2 factory2 = new TestConfigFactory2(); 525 526 ConfigFactoryRegistry.register("test", factory); 527 ConfigFactoryRegistry.register("test2", factory2); 528 ConfigMediator mediator = null; 529 530 mediator = new ConfigMediator(); 531 TestConfigFactory.createBuilder = true; 532 TestConfigFactory.createRegistry = false; 533 TestConfigFactory.nullRegistry = false; 534 TestConfigFactory2.createBuilder = false; 535 TestConfigFactory2.createRegistry = false; 536 TestConfigFactory2.nullRegistry = true; 537 TestConfigBuilder.built = false; 538 TestConfigBuilder2.built = false; 539 TestConfigBuilder.rebuilt = false; 540 TestConfigBuilder2.rebuilt = false; 541 TestConfigBuilder.commited = false; 542 TestConfigBuilder2.commited = false; 543 try { 544 mediator.mediate(files); 545 assertTrue("Should have called built", TestConfigBuilder.built && 546 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 547 assertTrue("Should have called built2", TestConfigBuilder2.built && 548 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 549 550 try { 551 files[0] = new FileReader ( 552 FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 553 files[1] = new FileReader ( 554 FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 555 } catch (FileNotFoundException e) { 556 fail(e.toString()); 557 } 558 mediator.rebuild(files); 559 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 560 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 561 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 562 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 563 } catch (Exception e) { 564 fail(e.toString()); 565 } 566 } 567 568 571 public void testInputSources() { 572 573 InputSource [] sources = new InputSource [2]; 574 try { 575 sources[0] = new InputSource (new FileInputStream ( 576 FileTools.convertPath("src/com/inversoft/config/test/config.xml"))); 577 sources[1] = new InputSource (new FileInputStream ( 578 FileTools.convertPath("src/com/inversoft/config/test/config2.xml"))); 579 } catch (FileNotFoundException e) { 580 fail(e.toString()); 581 } 582 583 TestConfigFactory factory = new TestConfigFactory(); 584 TestConfigFactory2 factory2 = new TestConfigFactory2(); 585 586 ConfigFactoryRegistry.register("test", factory); 587 ConfigFactoryRegistry.register("test2", factory2); 588 ConfigMediator mediator = null; 589 590 mediator = new ConfigMediator(); 591 TestConfigFactory.createBuilder = true; 592 TestConfigFactory.createRegistry = false; 593 TestConfigFactory.nullRegistry = false; 594 TestConfigFactory2.createBuilder = false; 595 TestConfigFactory2.createRegistry = false; 596 TestConfigFactory2.nullRegistry = true; 597 TestConfigBuilder.built = false; 598 TestConfigBuilder2.built = false; 599 TestConfigBuilder.rebuilt = false; 600 TestConfigBuilder2.rebuilt = false; 601 TestConfigBuilder.commited = false; 602 TestConfigBuilder2.commited = false; 603 try { 604 mediator.mediate(sources); 605 assertTrue("Should have called built", TestConfigBuilder.built && 606 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 607 assertTrue("Should have called built2", TestConfigBuilder2.built && 608 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 609 610 try { 611 sources[0] = new InputSource (new FileInputStream ( 612 FileTools.convertPath("src/com/inversoft/config/test/config.xml"))); 613 sources[1] = new InputSource (new FileInputStream ( 614 FileTools.convertPath("src/com/inversoft/config/test/config2.xml"))); 615 } catch (FileNotFoundException e) { 616 fail(e.toString()); 617 } 618 mediator.rebuild(sources); 619 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 620 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 621 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 622 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 623 } catch (Exception e) { 624 fail(e.toString()); 625 } 626 } 627 628 631 public void testFiles() { 632 633 File [] files = new File [2]; 634 files[0] = new File (FileTools.convertPath("src/com/inversoft/config/test/config.xml")); 635 files[1] = new File (FileTools.convertPath("src/com/inversoft/config/test/config2.xml")); 636 637 TestConfigFactory factory = new TestConfigFactory(); 638 TestConfigFactory2 factory2 = new TestConfigFactory2(); 639 640 ConfigFactoryRegistry.register("test", factory); 641 ConfigFactoryRegistry.register("test2", factory2); 642 ConfigMediator mediator = null; 643 644 mediator = new ConfigMediator(); 645 TestConfigFactory.createBuilder = true; 646 TestConfigFactory.createRegistry = false; 647 TestConfigFactory.nullRegistry = false; 648 TestConfigFactory2.createBuilder = false; 649 TestConfigFactory2.createRegistry = false; 650 TestConfigFactory2.nullRegistry = true; 651 TestConfigBuilder.built = false; 652 TestConfigBuilder2.built = false; 653 TestConfigBuilder.rebuilt = false; 654 TestConfigBuilder2.rebuilt = false; 655 TestConfigBuilder.commited = false; 656 TestConfigBuilder2.commited = false; 657 try { 658 mediator.mediate(files); 659 assertTrue("Should have called built", TestConfigBuilder.built && 660 !TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 661 assertTrue("Should have called built2", TestConfigBuilder2.built && 662 !TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 663 mediator.rebuild(files); 664 assertTrue("Should have called built and rebuilt", TestConfigBuilder.built && 665 TestConfigBuilder.rebuilt && TestConfigBuilder.commited); 666 assertTrue("Should have called built2 and rebuilt2", TestConfigBuilder2.built && 667 TestConfigBuilder2.rebuilt && TestConfigBuilder2.commited); 668 } catch (Exception e) { 669 fail(e.toString()); 670 } 671 } 672 } | Popular Tags |