001/* 002 * Copyright (C) Christian Schulte <cs@schulte.it>, 2005-206 003 * All rights reserved. 004 * 005 * Redistribution and use in source and binary forms, with or without 006 * modification, are permitted provided that the following conditions 007 * are met: 008 * 009 * o Redistributions of source code must retain the above copyright 010 * notice, this list of conditions and the following disclaimer. 011 * 012 * o Redistributions in binary form must reproduce the above copyright 013 * notice, this list of conditions and the following disclaimer in 014 * the documentation and/or other materials provided with the 015 * distribution. 016 * 017 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 018 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 019 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, 021 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 022 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 023 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 024 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 025 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 026 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 027 * 028 * $JOMC: ClassFileProcessorTest.java 5043 2015-05-27 07:03:39Z schulte $ 029 * 030 */ 031package org.jomc.tools.test; 032 033import java.io.File; 034import java.io.IOException; 035import java.io.InputStream; 036import java.io.OutputStream; 037import java.net.URISyntaxException; 038import java.net.URL; 039import java.net.URLClassLoader; 040import java.util.Arrays; 041import java.util.Collections; 042import java.util.List; 043import java.util.zip.ZipEntry; 044import java.util.zip.ZipInputStream; 045import javax.xml.bind.Marshaller; 046import javax.xml.bind.Unmarshaller; 047import javax.xml.transform.Transformer; 048import javax.xml.transform.TransformerConfigurationException; 049import javax.xml.transform.TransformerFactory; 050import javax.xml.transform.stream.StreamSource; 051import org.apache.bcel.classfile.ClassParser; 052import org.apache.bcel.classfile.JavaClass; 053import org.apache.commons.io.FileUtils; 054import org.apache.commons.io.IOUtils; 055import org.jomc.model.Dependency; 056import org.jomc.model.Implementation; 057import org.jomc.model.Message; 058import org.jomc.model.ModelObject; 059import org.jomc.model.Module; 060import org.jomc.model.Modules; 061import org.jomc.model.Multiplicity; 062import org.jomc.model.Property; 063import org.jomc.model.Specification; 064import org.jomc.model.modlet.DefaultModelProvider; 065import org.jomc.model.modlet.ModelHelper; 066import org.jomc.modlet.Model; 067import org.jomc.modlet.ModelContext; 068import org.jomc.modlet.ModelContextFactory; 069import org.jomc.modlet.ModelException; 070import org.jomc.modlet.ModelValidationReport; 071import org.jomc.tools.ClassFileProcessor; 072import org.jomc.tools.ResourceFileProcessor; 073import org.jomc.tools.SourceFileProcessor; 074import org.junit.Test; 075import static org.junit.Assert.assertNotNull; 076import static org.junit.Assert.assertTrue; 077import static org.junit.Assert.fail; 078 079/** 080 * Test cases for class {@code org.jomc.tools.ClassFileProcessor}. 081 * 082 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 083 * @version $JOMC: ClassFileProcessorTest.java 5043 2015-05-27 07:03:39Z schulte $ 084 */ 085public class ClassFileProcessorTest extends JomcToolTest 086{ 087 088 /** 089 * Creates a new {@code ClassFileProcessorTest} instance. 090 */ 091 public ClassFileProcessorTest() 092 { 093 super(); 094 } 095 096 /** 097 * {@inheritDoc} 098 */ 099 @Override 100 public ClassFileProcessor getJomcTool() 101 { 102 return (ClassFileProcessor) super.getJomcTool(); 103 } 104 105 /** 106 * {@inheritDoc} 107 */ 108 @Override 109 protected ClassFileProcessor newJomcTool() 110 { 111 return new ClassFileProcessor(); 112 } 113 114 /** 115 * {@inheritDoc} 116 */ 117 @Override 118 protected Model newModel() 119 { 120 try 121 { 122 DefaultModelProvider.setDefaultModuleLocation( this.getClass().getPackage().getName().replace( '.', '/' ) 123 + "/jomc-tools.xml" ); 124 125 Model m = this.getModelContext().findModel( ModelObject.MODEL_PUBLIC_ID ); 126 127 if ( m != null ) 128 { 129 final Modules modules = ModelHelper.getModules( m ); 130 131 if ( modules != null ) 132 { 133 final Module cp = modules.getClasspathModule( Modules.getDefaultClasspathModuleName(), 134 this.getClass().getClassLoader() ); 135 136 if ( cp != null ) 137 { 138 modules.getModule().add( cp ); 139 } 140 } 141 142 m = this.getModelContext().processModel( m ); 143 144 if ( m != null ) 145 { 146 final ModelValidationReport validationReport = this.getModelContext().validateModel( m ); 147 148 for ( int i = 0, s0 = validationReport.getDetails().size(); i < s0; i++ ) 149 { 150 System.out.println( validationReport.getDetails().get( i ) ); 151 } 152 153 assertTrue( "Unexpected invalid '" + m.getIdentifier() + "' model.", 154 validationReport.isModelValid() ); 155 156 } 157 } 158 159 return m; 160 } 161 catch ( final ModelException e ) 162 { 163 throw new AssertionError( e ); 164 } 165 finally 166 { 167 DefaultModelProvider.setDefaultModuleLocation( null ); 168 } 169 } 170 171 /** 172 * Gets a directory holding class files corresponding to the model of the instance. 173 * 174 * @return A directory holding class files corresponding to the model of the instance. 175 * 176 * @see #getNextOutputDirectory() 177 */ 178 public final File getNextClassesDirectory() 179 { 180 try 181 { 182 final File classesDirectory = this.getNextOutputDirectory(); 183 this.unzipResource( "classfiles.zip", classesDirectory ); 184 return classesDirectory; 185 } 186 catch ( final IOException e ) 187 { 188 throw new AssertionError( e ); 189 } 190 } 191 192 @Test 193 public final void testClassFileProcessorNullPointerException() throws Exception 194 { 195 final Marshaller marshaller = this.getModelContext().createMarshaller( ModelObject.MODEL_PUBLIC_ID ); 196 final Unmarshaller unmarshaller = this.getModelContext().createUnmarshaller( ModelObject.MODEL_PUBLIC_ID ); 197 final URL object = this.getClass().getResource( "/java/lang/Object.class" ); 198 199 InputStream in = null; 200 JavaClass objectClass = null; 201 boolean suppressExceptionOnClose = true; 202 203 try 204 { 205 in = object.openStream(); 206 objectClass = new ClassParser( in, object.toExternalForm() ).parse(); 207 suppressExceptionOnClose = false; 208 } 209 finally 210 { 211 try 212 { 213 if ( in != null ) 214 { 215 in.close(); 216 } 217 } 218 catch ( final IOException e ) 219 { 220 if ( !suppressExceptionOnClose ) 221 { 222 throw e; 223 } 224 } 225 } 226 227 try 228 { 229 this.getJomcTool().commitModelObjects( null, null ); 230 fail( "Expected NullPointerException not thrown." ); 231 } 232 catch ( final NullPointerException e ) 233 { 234 assertNullPointerException( e ); 235 } 236 try 237 { 238 this.getJomcTool().commitModelObjects( this.getModelContext(), null ); 239 fail( "Expected NullPointerException not thrown." ); 240 } 241 catch ( final NullPointerException e ) 242 { 243 assertNullPointerException( e ); 244 } 245 246 try 247 { 248 this.getJomcTool().commitModelObjects( (Implementation) null, (ModelContext) null, null ); 249 fail( "Expected NullPointerException not thrown." ); 250 } 251 catch ( final NullPointerException e ) 252 { 253 assertNullPointerException( e ); 254 } 255 try 256 { 257 this.getJomcTool().commitModelObjects( new Implementation(), (ModelContext) null, null ); 258 fail( "Expected NullPointerException not thrown." ); 259 } 260 catch ( final NullPointerException e ) 261 { 262 assertNullPointerException( e ); 263 } 264 try 265 { 266 this.getJomcTool().commitModelObjects( new Implementation(), this.getModelContext(), null ); 267 fail( "Expected NullPointerException not thrown." ); 268 } 269 catch ( final NullPointerException e ) 270 { 271 assertNullPointerException( e ); 272 } 273 274 try 275 { 276 this.getJomcTool().commitModelObjects( (Implementation) null, (Marshaller) null, null ); 277 fail( "Expected NullPointerException not thrown." ); 278 } 279 catch ( final NullPointerException e ) 280 { 281 assertNullPointerException( e ); 282 } 283 try 284 { 285 this.getJomcTool().commitModelObjects( new Implementation(), (Marshaller) null, null ); 286 fail( "Expected NullPointerException not thrown." ); 287 } 288 catch ( final NullPointerException e ) 289 { 290 assertNullPointerException( e ); 291 } 292 try 293 { 294 this.getJomcTool().commitModelObjects( new Implementation(), marshaller, null ); 295 fail( "Expected NullPointerException not thrown." ); 296 } 297 catch ( final NullPointerException e ) 298 { 299 assertNullPointerException( e ); 300 } 301 302 try 303 { 304 this.getJomcTool().commitModelObjects( (Module) null, null, null ); 305 fail( "Expected NullPointerException not thrown." ); 306 } 307 catch ( final NullPointerException e ) 308 { 309 assertNullPointerException( e ); 310 } 311 try 312 { 313 this.getJomcTool().commitModelObjects( new Module(), null, null ); 314 fail( "Expected NullPointerException not thrown." ); 315 } 316 catch ( final NullPointerException e ) 317 { 318 assertNullPointerException( e ); 319 } 320 try 321 { 322 this.getJomcTool().commitModelObjects( new Module(), this.getModelContext(), null ); 323 fail( "Expected NullPointerException not thrown." ); 324 } 325 catch ( final NullPointerException e ) 326 { 327 assertNullPointerException( e ); 328 } 329 330 try 331 { 332 this.getJomcTool().commitModelObjects( (Specification) null, (ModelContext) null, null ); 333 fail( "Expected NullPointerException not thrown." ); 334 } 335 catch ( final NullPointerException e ) 336 { 337 assertNullPointerException( e ); 338 } 339 try 340 { 341 this.getJomcTool().commitModelObjects( new Specification(), (ModelContext) null, null ); 342 fail( "Expected NullPointerException not thrown." ); 343 } 344 catch ( final NullPointerException e ) 345 { 346 assertNullPointerException( e ); 347 } 348 try 349 { 350 this.getJomcTool().commitModelObjects( new Specification(), this.getModelContext(), null ); 351 fail( "Expected NullPointerException not thrown." ); 352 } 353 catch ( final NullPointerException e ) 354 { 355 assertNullPointerException( e ); 356 } 357 358 try 359 { 360 this.getJomcTool().commitModelObjects( (Specification) null, (Marshaller) null, null ); 361 fail( "Expected NullPointerException not thrown." ); 362 } 363 catch ( final NullPointerException e ) 364 { 365 assertNullPointerException( e ); 366 } 367 try 368 { 369 this.getJomcTool().commitModelObjects( new Specification(), (Marshaller) null, null ); 370 fail( "Expected NullPointerException not thrown." ); 371 } 372 catch ( final NullPointerException e ) 373 { 374 assertNullPointerException( e ); 375 } 376 try 377 { 378 this.getJomcTool().commitModelObjects( new Specification(), marshaller, null ); 379 fail( "Expected NullPointerException not thrown." ); 380 } 381 catch ( final NullPointerException e ) 382 { 383 assertNullPointerException( e ); 384 } 385 386 try 387 { 388 this.getJomcTool().decodeModelObject( null, null, null ); 389 fail( "Expected NullPointerException not thrown." ); 390 } 391 catch ( final NullPointerException e ) 392 { 393 assertNullPointerException( e ); 394 } 395 try 396 { 397 this.getJomcTool().decodeModelObject( unmarshaller, null, null ); 398 fail( "Expected NullPointerException not thrown." ); 399 } 400 catch ( final NullPointerException e ) 401 { 402 assertNullPointerException( e ); 403 } 404 try 405 { 406 this.getJomcTool().decodeModelObject( unmarshaller, new byte[ 0 ], null ); 407 fail( "Expected NullPointerException not thrown." ); 408 } 409 catch ( final NullPointerException e ) 410 { 411 assertNullPointerException( e ); 412 } 413 414 try 415 { 416 this.getJomcTool().encodeModelObject( null, null ); 417 fail( "Expected NullPointerException not thrown." ); 418 } 419 catch ( final NullPointerException e ) 420 { 421 assertNullPointerException( e ); 422 } 423 try 424 { 425 this.getJomcTool().encodeModelObject( marshaller, null ); 426 fail( "Expected NullPointerException not thrown." ); 427 } 428 catch ( final NullPointerException e ) 429 { 430 assertNullPointerException( e ); 431 } 432 433 try 434 { 435 this.getJomcTool().getClassfileAttribute( null, null ); 436 fail( "Expected NullPointerException not thrown." ); 437 } 438 catch ( final NullPointerException e ) 439 { 440 assertNullPointerException( e ); 441 } 442 try 443 { 444 this.getJomcTool().getClassfileAttribute( objectClass, null ); 445 fail( "Expected NullPointerException not thrown." ); 446 } 447 catch ( final NullPointerException e ) 448 { 449 assertNullPointerException( e ); 450 } 451 452 try 453 { 454 this.getJomcTool().setClassfileAttribute( null, null, null ); 455 fail( "Expected NullPointerException not thrown." ); 456 } 457 catch ( final NullPointerException e ) 458 { 459 assertNullPointerException( e ); 460 } 461 try 462 { 463 this.getJomcTool().setClassfileAttribute( objectClass, null, null ); 464 fail( "Expected NullPointerException not thrown." ); 465 } 466 catch ( final NullPointerException e ) 467 { 468 assertNullPointerException( e ); 469 } 470 471 try 472 { 473 this.getJomcTool().transformModelObjects( null, null, null ); 474 fail( "Expected NullPointerException not thrown." ); 475 } 476 catch ( final NullPointerException e ) 477 { 478 assertNullPointerException( e ); 479 } 480 try 481 { 482 this.getJomcTool().transformModelObjects( this.getModelContext(), null, null ); 483 fail( "Expected NullPointerException not thrown." ); 484 } 485 catch ( final NullPointerException e ) 486 { 487 assertNullPointerException( e ); 488 } 489 try 490 { 491 this.getJomcTool().transformModelObjects( this.getModelContext(), new File( "/" ), null ); 492 fail( "Expected NullPointerException not thrown." ); 493 } 494 catch ( final NullPointerException e ) 495 { 496 assertNullPointerException( e ); 497 } 498 499 try 500 { 501 this.getJomcTool().transformModelObjects( (Module) null, null, null, null ); 502 fail( "Expected NullPointerException not thrown." ); 503 } 504 catch ( final NullPointerException e ) 505 { 506 assertNullPointerException( e ); 507 } 508 try 509 { 510 this.getJomcTool().transformModelObjects( new Module(), null, null, null ); 511 fail( "Expected NullPointerException not thrown." ); 512 } 513 catch ( final NullPointerException e ) 514 { 515 assertNullPointerException( e ); 516 } 517 try 518 { 519 this.getJomcTool().transformModelObjects( new Module(), this.getModelContext(), null, null ); 520 fail( "Expected NullPointerException not thrown." ); 521 } 522 catch ( final NullPointerException e ) 523 { 524 assertNullPointerException( e ); 525 } 526 try 527 { 528 this.getJomcTool().transformModelObjects( new Module(), this.getModelContext(), new File( "/" ), null ); 529 fail( "Expected NullPointerException not thrown." ); 530 } 531 catch ( final NullPointerException e ) 532 { 533 assertNullPointerException( e ); 534 } 535 536 try 537 { 538 this.getJomcTool().transformModelObjects( (Specification) null, null, null, null ); 539 fail( "Expected NullPointerException not thrown." ); 540 } 541 catch ( final NullPointerException e ) 542 { 543 assertNullPointerException( e ); 544 } 545 try 546 { 547 this.getJomcTool().transformModelObjects( new Specification(), null, null, null ); 548 fail( "Expected NullPointerException not thrown." ); 549 } 550 catch ( final NullPointerException e ) 551 { 552 assertNullPointerException( e ); 553 } 554 try 555 { 556 this.getJomcTool().transformModelObjects( new Specification(), this.getModelContext(), null, null ); 557 fail( "Expected NullPointerException not thrown." ); 558 } 559 catch ( final NullPointerException e ) 560 { 561 assertNullPointerException( e ); 562 } 563 try 564 { 565 this.getJomcTool().transformModelObjects( 566 new Specification(), this.getModelContext(), new File( "/" ), null ); 567 568 fail( "Expected NullPointerException not thrown." ); 569 } 570 catch ( final NullPointerException e ) 571 { 572 assertNullPointerException( e ); 573 } 574 575 try 576 { 577 this.getJomcTool().transformModelObjects( (Implementation) null, null, null, null ); 578 fail( "Expected NullPointerException not thrown." ); 579 } 580 catch ( final NullPointerException e ) 581 { 582 assertNullPointerException( e ); 583 } 584 try 585 { 586 this.getJomcTool().transformModelObjects( new Implementation(), null, null, null ); 587 fail( "Expected NullPointerException not thrown." ); 588 } 589 catch ( final NullPointerException e ) 590 { 591 assertNullPointerException( e ); 592 } 593 try 594 { 595 this.getJomcTool().transformModelObjects( new Implementation(), this.getModelContext(), null, null ); 596 fail( "Expected NullPointerException not thrown." ); 597 } 598 catch ( final NullPointerException e ) 599 { 600 assertNullPointerException( e ); 601 } 602 try 603 { 604 this.getJomcTool().transformModelObjects( 605 new Implementation(), this.getModelContext(), new File( "/" ), null ); 606 607 fail( "Expected NullPointerException not thrown." ); 608 } 609 catch ( final NullPointerException e ) 610 { 611 assertNullPointerException( e ); 612 } 613 614 try 615 { 616 this.getJomcTool().transformModelObjects( (Specification) null, null, null, null, null ); 617 fail( "Expected NullPointerException not thrown." ); 618 } 619 catch ( final NullPointerException e ) 620 { 621 assertNullPointerException( e ); 622 } 623 try 624 { 625 this.getJomcTool().transformModelObjects( new Specification(), null, null, null, null ); 626 fail( "Expected NullPointerException not thrown." ); 627 } 628 catch ( final NullPointerException e ) 629 { 630 assertNullPointerException( e ); 631 } 632 try 633 { 634 this.getJomcTool().transformModelObjects( new Specification(), marshaller, null, null, null ); 635 fail( "Expected NullPointerException not thrown." ); 636 } 637 catch ( final NullPointerException e ) 638 { 639 assertNullPointerException( e ); 640 } 641 try 642 { 643 this.getJomcTool().transformModelObjects( new Specification(), marshaller, unmarshaller, null, null ); 644 fail( "Expected NullPointerException not thrown." ); 645 } 646 catch ( final NullPointerException e ) 647 { 648 assertNullPointerException( e ); 649 } 650 try 651 { 652 this.getJomcTool().transformModelObjects( new Specification(), marshaller, unmarshaller, objectClass, null ); 653 fail( "Expected NullPointerException not thrown." ); 654 } 655 catch ( final NullPointerException e ) 656 { 657 assertNullPointerException( e ); 658 } 659 660 try 661 { 662 this.getJomcTool().transformModelObjects( (Implementation) null, null, null, null, null ); 663 fail( "Expected NullPointerException not thrown." ); 664 } 665 catch ( final NullPointerException e ) 666 { 667 assertNullPointerException( e ); 668 } 669 try 670 { 671 this.getJomcTool().transformModelObjects( new Implementation(), null, null, null, null ); 672 fail( "Expected NullPointerException not thrown." ); 673 } 674 catch ( final NullPointerException e ) 675 { 676 assertNullPointerException( e ); 677 } 678 try 679 { 680 this.getJomcTool().transformModelObjects( new Implementation(), marshaller, null, null, null ); 681 fail( "Expected NullPointerException not thrown." ); 682 } 683 catch ( final NullPointerException e ) 684 { 685 assertNullPointerException( e ); 686 } 687 try 688 { 689 this.getJomcTool().transformModelObjects( new Implementation(), marshaller, unmarshaller, null, null ); 690 fail( "Expected NullPointerException not thrown." ); 691 } 692 catch ( final NullPointerException e ) 693 { 694 assertNullPointerException( e ); 695 } 696 try 697 { 698 this.getJomcTool().transformModelObjects( new Implementation(), marshaller, unmarshaller, objectClass, 699 null ); 700 701 fail( "Expected NullPointerException not thrown." ); 702 } 703 catch ( final NullPointerException e ) 704 { 705 assertNullPointerException( e ); 706 } 707 708 try 709 { 710 this.getJomcTool().validateModelObjects( null ); 711 fail( "Expected NullPointerException not thrown." ); 712 } 713 catch ( final NullPointerException e ) 714 { 715 assertNullPointerException( e ); 716 } 717 718 try 719 { 720 this.getJomcTool().validateModelObjects( null, (File) null ); 721 fail( "Expected NullPointerException not thrown." ); 722 } 723 catch ( final NullPointerException e ) 724 { 725 assertNullPointerException( e ); 726 } 727 try 728 { 729 this.getJomcTool().validateModelObjects( this.getModelContext(), (File) null ); 730 fail( "Expected NullPointerException not thrown." ); 731 } 732 catch ( final NullPointerException e ) 733 { 734 assertNullPointerException( e ); 735 } 736 737 try 738 { 739 this.getJomcTool().validateModelObjects( (Module) null, null ); 740 fail( "Expected NullPointerException not thrown." ); 741 } 742 catch ( final NullPointerException e ) 743 { 744 assertNullPointerException( e ); 745 } 746 try 747 { 748 this.getJomcTool().validateModelObjects( new Module(), null ); 749 fail( "Expected NullPointerException not thrown." ); 750 } 751 catch ( final NullPointerException e ) 752 { 753 assertNullPointerException( e ); 754 } 755 756 try 757 { 758 this.getJomcTool().validateModelObjects( (Module) null, null, (File) null ); 759 fail( "Expected NullPointerException not thrown." ); 760 } 761 catch ( final NullPointerException e ) 762 { 763 assertNullPointerException( e ); 764 } 765 try 766 { 767 this.getJomcTool().validateModelObjects( new Module(), null, (File) null ); 768 fail( "Expected NullPointerException not thrown." ); 769 } 770 catch ( final NullPointerException e ) 771 { 772 assertNullPointerException( e ); 773 } 774 try 775 { 776 this.getJomcTool().validateModelObjects( new Module(), this.getModelContext(), (File) null ); 777 fail( "Expected NullPointerException not thrown." ); 778 } 779 catch ( final NullPointerException e ) 780 { 781 assertNullPointerException( e ); 782 } 783 784 try 785 { 786 this.getJomcTool().validateModelObjects( (Specification) null, null ); 787 fail( "Expected NullPointerException not thrown." ); 788 } 789 catch ( final NullPointerException e ) 790 { 791 assertNullPointerException( e ); 792 } 793 try 794 { 795 this.getJomcTool().validateModelObjects( new Specification(), null ); 796 fail( "Expected NullPointerException not thrown." ); 797 } 798 catch ( final NullPointerException e ) 799 { 800 assertNullPointerException( e ); 801 } 802 803 try 804 { 805 this.getJomcTool().validateModelObjects( (Specification) null, (ModelContext) null, null ); 806 fail( "Expected NullPointerException not thrown." ); 807 } 808 catch ( final NullPointerException e ) 809 { 810 assertNullPointerException( e ); 811 } 812 try 813 { 814 this.getJomcTool().validateModelObjects( new Specification(), (ModelContext) null, null ); 815 fail( "Expected NullPointerException not thrown." ); 816 } 817 catch ( final NullPointerException e ) 818 { 819 assertNullPointerException( e ); 820 } 821 try 822 { 823 this.getJomcTool().validateModelObjects( new Specification(), this.getModelContext(), null ); 824 fail( "Expected NullPointerException not thrown." ); 825 } 826 catch ( final NullPointerException e ) 827 { 828 assertNullPointerException( e ); 829 } 830 831 try 832 { 833 this.getJomcTool().validateModelObjects( (Implementation) null, null ); 834 fail( "Expected NullPointerException not thrown." ); 835 } 836 catch ( final NullPointerException e ) 837 { 838 assertNullPointerException( e ); 839 } 840 try 841 { 842 this.getJomcTool().validateModelObjects( new Implementation(), null ); 843 fail( "Expected NullPointerException not thrown." ); 844 } 845 catch ( final NullPointerException e ) 846 { 847 assertNullPointerException( e ); 848 } 849 850 try 851 { 852 this.getJomcTool().validateModelObjects( (Implementation) null, (ModelContext) null, null ); 853 fail( "Expected NullPointerException not thrown." ); 854 } 855 catch ( final NullPointerException e ) 856 { 857 assertNullPointerException( e ); 858 } 859 try 860 { 861 this.getJomcTool().validateModelObjects( new Implementation(), (ModelContext) null, null ); 862 fail( "Expected NullPointerException not thrown." ); 863 } 864 catch ( final NullPointerException e ) 865 { 866 assertNullPointerException( e ); 867 } 868 try 869 { 870 this.getJomcTool().validateModelObjects( new Implementation(), this.getModelContext(), null ); 871 fail( "Expected NullPointerException not thrown." ); 872 } 873 catch ( final NullPointerException e ) 874 { 875 assertNullPointerException( e ); 876 } 877 878 try 879 { 880 this.getJomcTool().validateModelObjects( (Specification) null, (Unmarshaller) null, null ); 881 fail( "Expected NullPointerException not thrown." ); 882 } 883 catch ( final NullPointerException e ) 884 { 885 assertNullPointerException( e ); 886 } 887 try 888 { 889 this.getJomcTool().validateModelObjects( new Specification(), (Unmarshaller) null, null ); 890 fail( "Expected NullPointerException not thrown." ); 891 } 892 catch ( final NullPointerException e ) 893 { 894 assertNullPointerException( e ); 895 } 896 try 897 { 898 this.getJomcTool().validateModelObjects( new Specification(), unmarshaller, null ); 899 fail( "Expected NullPointerException not thrown." ); 900 } 901 catch ( final NullPointerException e ) 902 { 903 assertNullPointerException( e ); 904 } 905 906 try 907 { 908 this.getJomcTool().validateModelObjects( (Implementation) null, (Unmarshaller) null, null ); 909 fail( "Expected NullPointerException not thrown." ); 910 } 911 catch ( final NullPointerException e ) 912 { 913 assertNullPointerException( e ); 914 } 915 try 916 { 917 this.getJomcTool().validateModelObjects( new Implementation(), (Unmarshaller) null, null ); 918 fail( "Expected NullPointerException not thrown." ); 919 } 920 catch ( final NullPointerException e ) 921 { 922 assertNullPointerException( e ); 923 } 924 try 925 { 926 this.getJomcTool().validateModelObjects( new Implementation(), unmarshaller, null ); 927 fail( "Expected NullPointerException not thrown." ); 928 } 929 catch ( final NullPointerException e ) 930 { 931 assertNullPointerException( e ); 932 } 933 } 934 935 @Test 936 public final void testCommitTransformValidateClasses() throws Exception 937 { 938 final File nonExistentDirectory = this.getNextOutputDirectory(); 939 final File emptyDirectory = this.getNextOutputDirectory(); 940 assertTrue( emptyDirectory.mkdirs() ); 941 942 final File allClasses = this.getNextClassesDirectory(); 943 final ClassLoader allClassesLoader = new URLClassLoader( new URL[] 944 { 945 allClasses.toURI().toURL() 946 } ); 947 948 final File moduleClasses = this.getNextClassesDirectory(); 949 final ClassLoader moduleClassesLoader = new URLClassLoader( new URL[] 950 { 951 moduleClasses.toURI().toURL() 952 } ); 953 954 final File implementationClasses = this.getNextClassesDirectory(); 955 final ClassLoader implementationClassesLoader = new URLClassLoader( new URL[] 956 { 957 implementationClasses.toURI().toURL() 958 } ); 959 960 final File specificationClasses = this.getNextClassesDirectory(); 961 final ClassLoader specificationClassesLoader = new URLClassLoader( new URL[] 962 { 963 specificationClasses.toURI().toURL() 964 } ); 965 966 final File uncommittedClasses = this.getNextClassesDirectory(); 967 final ClassLoader uncommittedClassesLoader = new URLClassLoader( new URL[] 968 { 969 uncommittedClasses.toURI().toURL() 970 } ); 971 972 final Module m = this.getJomcTool().getModules().getModule( "JOMC Tools" ); 973 final Specification s = this.getJomcTool().getModules().getSpecification( "org.jomc.tools.ClassFileProcessor" ); 974 final Implementation i = 975 this.getJomcTool().getModules().getImplementation( "org.jomc.tools.ClassFileProcessor" ); 976 977 assertNotNull( m ); 978 assertNotNull( s ); 979 assertNotNull( i ); 980 981 final List<Transformer> transformers = Arrays.asList( new Transformer[] 982 { 983 this.getTransformer( "no-op.xsl" ) 984 } ); 985 986 final List<Transformer> illegalSpecificationTransformers = Arrays.asList( new Transformer[] 987 { 988 this.getTransformer( "illegal-specification-transformation.xsl" ) 989 } ); 990 991 final List<Transformer> illegalSpecificationsTransformers = Arrays.asList( new Transformer[] 992 { 993 this.getTransformer( "illegal-specifications-transformation.xsl" ) 994 } ); 995 996 final List<Transformer> illegalDependenciesTransformers = Arrays.asList( new Transformer[] 997 { 998 this.getTransformer( "illegal-dependencies-transformation.xsl" ) 999 } ); 1000 1001 final List<Transformer> illegalMessagesTransformers = Arrays.asList( new Transformer[] 1002 { 1003 this.getTransformer( "illegal-messages-transformation.xsl" ) 1004 } ); 1005 1006 final List<Transformer> illegalPropertiesTransformers = Arrays.asList( new Transformer[] 1007 { 1008 this.getTransformer( "illegal-properties-transformation.xsl" ) 1009 } ); 1010 1011 try 1012 { 1013 this.getJomcTool().commitModelObjects( this.getModelContext(), nonExistentDirectory ); 1014 fail( "Expected IOException not thrown." ); 1015 } 1016 catch ( final IOException e ) 1017 { 1018 assertNotNull( e.getMessage() ); 1019 System.out.println( e ); 1020 } 1021 try 1022 { 1023 this.getJomcTool().commitModelObjects( this.getModelContext(), emptyDirectory ); 1024 fail( "Expected IOException not thrown." ); 1025 } 1026 catch ( final IOException e ) 1027 { 1028 assertNotNull( e.getMessage() ); 1029 System.out.println( e ); 1030 } 1031 1032 try 1033 { 1034 this.getJomcTool().commitModelObjects( m, this.getModelContext(), nonExistentDirectory ); 1035 fail( "Expected IOException not thrown." ); 1036 } 1037 catch ( final IOException e ) 1038 { 1039 assertNotNull( e.getMessage() ); 1040 System.out.println( e ); 1041 } 1042 try 1043 { 1044 this.getJomcTool().commitModelObjects( m, this.getModelContext(), emptyDirectory ); 1045 fail( "Expected IOException not thrown." ); 1046 } 1047 catch ( final IOException e ) 1048 { 1049 assertNotNull( e.getMessage() ); 1050 System.out.println( e ); 1051 } 1052 1053 try 1054 { 1055 this.getJomcTool().commitModelObjects( s, this.getModelContext(), nonExistentDirectory ); 1056 fail( "Expected IOException not thrown." ); 1057 } 1058 catch ( final IOException e ) 1059 { 1060 assertNotNull( e.getMessage() ); 1061 System.out.println( e ); 1062 } 1063 try 1064 { 1065 this.getJomcTool().commitModelObjects( s, this.getModelContext(), emptyDirectory ); 1066 fail( "Expected IOException not thrown." ); 1067 } 1068 catch ( final IOException e ) 1069 { 1070 assertNotNull( e.getMessage() ); 1071 System.out.println( e ); 1072 } 1073 1074 try 1075 { 1076 this.getJomcTool().commitModelObjects( i, this.getModelContext(), nonExistentDirectory ); 1077 fail( "Expected IOException not thrown." ); 1078 } 1079 catch ( final IOException e ) 1080 { 1081 assertNotNull( e.getMessage() ); 1082 System.out.println( e ); 1083 } 1084 try 1085 { 1086 this.getJomcTool().commitModelObjects( i, this.getModelContext(), emptyDirectory ); 1087 fail( "Expected IOException not thrown." ); 1088 } 1089 catch ( final IOException e ) 1090 { 1091 assertNotNull( e.getMessage() ); 1092 System.out.println( e ); 1093 } 1094 1095 try 1096 { 1097 this.getJomcTool().transformModelObjects( this.getModelContext(), nonExistentDirectory, transformers ); 1098 fail( "Expected IOException not thrown." ); 1099 } 1100 catch ( final IOException e ) 1101 { 1102 assertNotNull( e.getMessage() ); 1103 System.out.println( e ); 1104 } 1105 try 1106 { 1107 this.getJomcTool().transformModelObjects( this.getModelContext(), emptyDirectory, transformers ); 1108 fail( "Expected IOException not thrown." ); 1109 } 1110 catch ( final IOException e ) 1111 { 1112 assertNotNull( e.getMessage() ); 1113 System.out.println( e ); 1114 } 1115 1116 try 1117 { 1118 this.getJomcTool().transformModelObjects( m, this.getModelContext(), nonExistentDirectory, transformers ); 1119 fail( "Expected IOException not thrown." ); 1120 } 1121 catch ( final IOException e ) 1122 { 1123 assertNotNull( e.getMessage() ); 1124 System.out.println( e ); 1125 } 1126 try 1127 { 1128 this.getJomcTool().transformModelObjects( m, this.getModelContext(), emptyDirectory, transformers ); 1129 fail( "Expected IOException not thrown." ); 1130 } 1131 catch ( final IOException e ) 1132 { 1133 assertNotNull( e.getMessage() ); 1134 System.out.println( e ); 1135 } 1136 1137 try 1138 { 1139 this.getJomcTool().transformModelObjects( s, this.getModelContext(), nonExistentDirectory, transformers ); 1140 fail( "Expected IOException not thrown." ); 1141 } 1142 catch ( final IOException e ) 1143 { 1144 assertNotNull( e.getMessage() ); 1145 System.out.println( e ); 1146 } 1147 try 1148 { 1149 this.getJomcTool().transformModelObjects( s, this.getModelContext(), emptyDirectory, transformers ); 1150 fail( "Expected IOException not thrown." ); 1151 } 1152 catch ( final IOException e ) 1153 { 1154 assertNotNull( e.getMessage() ); 1155 System.out.println( e ); 1156 } 1157 1158 try 1159 { 1160 this.getJomcTool().transformModelObjects( i, this.getModelContext(), nonExistentDirectory, transformers ); 1161 fail( "Expected IOException not thrown." ); 1162 } 1163 catch ( final IOException e ) 1164 { 1165 assertNotNull( e.getMessage() ); 1166 System.out.println( e ); 1167 } 1168 try 1169 { 1170 this.getJomcTool().transformModelObjects( i, this.getModelContext(), emptyDirectory, transformers ); 1171 fail( "Expected IOException not thrown." ); 1172 } 1173 catch ( final IOException e ) 1174 { 1175 assertNotNull( e.getMessage() ); 1176 System.out.println( e ); 1177 } 1178 1179 try 1180 { 1181 this.getJomcTool().validateModelObjects( this.getModelContext(), nonExistentDirectory ); 1182 fail( "Expected IOException not thrown." ); 1183 } 1184 catch ( final IOException e ) 1185 { 1186 assertNotNull( e.getMessage() ); 1187 System.out.println( e ); 1188 } 1189 try 1190 { 1191 this.getJomcTool().validateModelObjects( this.getModelContext(), emptyDirectory ); 1192 fail( "Expected IOException not thrown." ); 1193 } 1194 catch ( final IOException e ) 1195 { 1196 assertNotNull( e.getMessage() ); 1197 System.out.println( e ); 1198 } 1199 1200 try 1201 { 1202 this.getJomcTool().validateModelObjects( m, this.getModelContext(), nonExistentDirectory ); 1203 fail( "Expected IOException not thrown." ); 1204 } 1205 catch ( final IOException e ) 1206 { 1207 assertNotNull( e.getMessage() ); 1208 System.out.println( e ); 1209 } 1210 try 1211 { 1212 this.getJomcTool().validateModelObjects( m, this.getModelContext(), emptyDirectory ); 1213 fail( "Expected IOException not thrown." ); 1214 } 1215 catch ( final IOException e ) 1216 { 1217 assertNotNull( e.getMessage() ); 1218 System.out.println( e ); 1219 } 1220 1221 try 1222 { 1223 this.getJomcTool().validateModelObjects( s, this.getModelContext(), nonExistentDirectory ); 1224 fail( "Expected IOException not thrown." ); 1225 } 1226 catch ( final IOException e ) 1227 { 1228 assertNotNull( e.getMessage() ); 1229 System.out.println( e ); 1230 } 1231 try 1232 { 1233 this.getJomcTool().validateModelObjects( s, this.getModelContext(), emptyDirectory ); 1234 fail( "Expected IOException not thrown." ); 1235 } 1236 catch ( final IOException e ) 1237 { 1238 assertNotNull( e.getMessage() ); 1239 System.out.println( e ); 1240 } 1241 1242 try 1243 { 1244 this.getJomcTool().validateModelObjects( i, this.getModelContext(), nonExistentDirectory ); 1245 fail( "Expected IOException not thrown." ); 1246 } 1247 catch ( final IOException e ) 1248 { 1249 assertNotNull( e.getMessage() ); 1250 System.out.println( e ); 1251 } 1252 try 1253 { 1254 this.getJomcTool().validateModelObjects( i, this.getModelContext(), emptyDirectory ); 1255 fail( "Expected IOException not thrown." ); 1256 } 1257 catch ( final IOException e ) 1258 { 1259 assertNotNull( e.getMessage() ); 1260 System.out.println( e ); 1261 } 1262 1263 this.getJomcTool().commitModelObjects( this.getModelContext(), allClasses ); 1264 this.getJomcTool().commitModelObjects( m, this.getModelContext(), moduleClasses ); 1265 this.getJomcTool().commitModelObjects( s, this.getModelContext(), specificationClasses ); 1266 this.getJomcTool().commitModelObjects( i, this.getModelContext(), implementationClasses ); 1267 1268 try 1269 { 1270 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, 1271 illegalSpecificationTransformers ); 1272 1273 fail( "Expected IOException not thrown." ); 1274 } 1275 catch ( final IOException e ) 1276 { 1277 assertNotNull( e.getMessage() ); 1278 System.out.println( e ); 1279 } 1280 try 1281 { 1282 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, 1283 illegalSpecificationsTransformers ); 1284 1285 fail( "Expected IOException not thrown." ); 1286 } 1287 catch ( final IOException e ) 1288 { 1289 assertNotNull( e.getMessage() ); 1290 System.out.println( e ); 1291 } 1292 try 1293 { 1294 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, 1295 illegalDependenciesTransformers ); 1296 1297 fail( "Expected IOException not thrown." ); 1298 } 1299 catch ( final IOException e ) 1300 { 1301 assertNotNull( e.getMessage() ); 1302 System.out.println( e ); 1303 } 1304 try 1305 { 1306 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, 1307 illegalMessagesTransformers ); 1308 1309 fail( "Expected IOException not thrown." ); 1310 } 1311 catch ( final IOException e ) 1312 { 1313 assertNotNull( e.getMessage() ); 1314 System.out.println( e ); 1315 } 1316 try 1317 { 1318 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, 1319 illegalPropertiesTransformers ); 1320 1321 fail( "Expected IOException not thrown." ); 1322 } 1323 catch ( final IOException e ) 1324 { 1325 assertNotNull( e.getMessage() ); 1326 System.out.println( e ); 1327 } 1328 1329 try 1330 { 1331 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, 1332 illegalSpecificationTransformers ); 1333 1334 fail( "Expected IOException not thrown." ); 1335 } 1336 catch ( final IOException e ) 1337 { 1338 assertNotNull( e.getMessage() ); 1339 System.out.println( e ); 1340 } 1341 try 1342 { 1343 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, 1344 illegalSpecificationsTransformers ); 1345 1346 fail( "Expected IOException not thrown." ); 1347 } 1348 catch ( final IOException e ) 1349 { 1350 assertNotNull( e.getMessage() ); 1351 System.out.println( e ); 1352 } 1353 try 1354 { 1355 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, 1356 illegalDependenciesTransformers ); 1357 1358 fail( "Expected IOException not thrown." ); 1359 } 1360 catch ( final IOException e ) 1361 { 1362 assertNotNull( e.getMessage() ); 1363 System.out.println( e ); 1364 } 1365 try 1366 { 1367 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, 1368 illegalMessagesTransformers ); 1369 1370 fail( "Expected IOException not thrown." ); 1371 } 1372 catch ( final IOException e ) 1373 { 1374 assertNotNull( e.getMessage() ); 1375 System.out.println( e ); 1376 } 1377 try 1378 { 1379 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, 1380 illegalPropertiesTransformers ); 1381 1382 fail( "Expected IOException not thrown." ); 1383 } 1384 catch ( final IOException e ) 1385 { 1386 assertNotNull( e.getMessage() ); 1387 System.out.println( e ); 1388 } 1389 1390 try 1391 { 1392 this.getJomcTool().transformModelObjects( s, this.getModelContext(), specificationClasses, 1393 illegalSpecificationTransformers ); 1394 1395 fail( "Expected IOException not thrown." ); 1396 } 1397 catch ( final IOException e ) 1398 { 1399 assertNotNull( e.getMessage() ); 1400 System.out.println( e ); 1401 } 1402 1403 try 1404 { 1405 this.getJomcTool().transformModelObjects( i, this.getModelContext(), implementationClasses, 1406 illegalSpecificationsTransformers ); 1407 1408 fail( "Expected IOException not thrown." ); 1409 } 1410 catch ( final IOException e ) 1411 { 1412 assertNotNull( e.getMessage() ); 1413 System.out.println( e ); 1414 } 1415 try 1416 { 1417 this.getJomcTool().transformModelObjects( i, this.getModelContext(), implementationClasses, 1418 illegalDependenciesTransformers ); 1419 1420 fail( "Expected IOException not thrown." ); 1421 } 1422 catch ( final IOException e ) 1423 { 1424 assertNotNull( e.getMessage() ); 1425 System.out.println( e ); 1426 } 1427 try 1428 { 1429 this.getJomcTool().transformModelObjects( i, this.getModelContext(), implementationClasses, 1430 illegalMessagesTransformers ); 1431 1432 fail( "Expected IOException not thrown." ); 1433 } 1434 catch ( final IOException e ) 1435 { 1436 assertNotNull( e.getMessage() ); 1437 System.out.println( e ); 1438 } 1439 try 1440 { 1441 this.getJomcTool().transformModelObjects( i, this.getModelContext(), implementationClasses, 1442 illegalPropertiesTransformers ); 1443 1444 fail( "Expected IOException not thrown." ); 1445 } 1446 catch ( final IOException e ) 1447 { 1448 assertNotNull( e.getMessage() ); 1449 System.out.println( e ); 1450 } 1451 1452 this.getJomcTool().transformModelObjects( this.getModelContext(), allClasses, transformers ); 1453 this.getJomcTool().transformModelObjects( m, this.getModelContext(), moduleClasses, transformers ); 1454 this.getJomcTool().transformModelObjects( s, this.getModelContext(), specificationClasses, transformers ); 1455 this.getJomcTool().transformModelObjects( i, this.getModelContext(), implementationClasses, transformers ); 1456 1457 this.getJomcTool().validateModelObjects( 1458 ModelContextFactory.newInstance().newModelContext( allClassesLoader ) ); 1459 1460 this.getJomcTool().validateModelObjects( 1461 m, ModelContextFactory.newInstance().newModelContext( moduleClassesLoader ) ); 1462 1463 this.getJomcTool().validateModelObjects( 1464 s, ModelContextFactory.newInstance().newModelContext( specificationClassesLoader ) ); 1465 1466 this.getJomcTool().validateModelObjects( 1467 i, ModelContextFactory.newInstance().newModelContext( implementationClassesLoader ) ); 1468 1469 this.getJomcTool().validateModelObjects( this.getModelContext(), allClasses ); 1470 this.getJomcTool().validateModelObjects( m, this.getModelContext(), moduleClasses ); 1471 this.getJomcTool().validateModelObjects( s, this.getModelContext(), specificationClasses ); 1472 this.getJomcTool().validateModelObjects( i, this.getModelContext(), implementationClasses ); 1473 1474 this.getJomcTool().validateModelObjects( 1475 ModelContextFactory.newInstance().newModelContext( uncommittedClassesLoader ) ); 1476 1477 this.getJomcTool().validateModelObjects( this.getModelContext(), uncommittedClasses ); 1478 1479 final Model model = this.getJomcTool().getModel(); 1480 final Model copy = model.clone(); 1481 final Modules modules = ModelHelper.getModules( copy ); 1482 final Module testModule = modules.getModule( "JOMC Tools" ); 1483 assertNotNull( testModule ); 1484 1485 final Specification classFileProcessor = 1486 testModule.getSpecifications().getSpecification( ClassFileProcessor.class.getName() ); 1487 1488 final Specification resourceFileProcessor = 1489 testModule.getSpecifications().getSpecification( ResourceFileProcessor.class.getName() ); 1490 1491 final Specification sourceFileProcessor = 1492 testModule.getSpecifications().getSpecification( SourceFileProcessor.class.getName() ); 1493 1494 final Implementation classFileProcessorImpl = 1495 testModule.getImplementations().getImplementation( ClassFileProcessor.class.getName() ); 1496 1497 final Implementation resourceFileProcessorImpl = 1498 testModule.getImplementations().getImplementation( ResourceFileProcessor.class.getName() ); 1499 1500 final Implementation sourceFileProcessorImpl = 1501 testModule.getImplementations().getImplementation( SourceFileProcessor.class.getName() ); 1502 1503 assertNotNull( classFileProcessor ); 1504 assertNotNull( resourceFileProcessor ); 1505 assertNotNull( sourceFileProcessor ); 1506 assertNotNull( classFileProcessorImpl ); 1507 assertNotNull( resourceFileProcessorImpl ); 1508 assertNotNull( sourceFileProcessorImpl ); 1509 1510 classFileProcessor.setMultiplicity( Multiplicity.ONE ); 1511 classFileProcessor.setScope( "TEST" ); 1512 resourceFileProcessor.setMultiplicity( Multiplicity.ONE ); 1513 resourceFileProcessor.setScope( "TEST" ); 1514 sourceFileProcessor.setMultiplicity( Multiplicity.ONE ); 1515 sourceFileProcessor.setScope( "TEST" ); 1516 1517 Property p = classFileProcessorImpl.getProperties().getProperty( "TestStringProperty" ); 1518 assertNotNull( p ); 1519 assertNotNull( classFileProcessorImpl.getProperties().getProperty().remove( p ) ); 1520 1521 p = classFileProcessorImpl.getProperties().getProperty( "TestPrimitiveProperty" ); 1522 assertNotNull( p ); 1523 p.setType( null ); 1524 1525 p = resourceFileProcessorImpl.getProperties().getProperty( "TestStringProperty" ); 1526 assertNotNull( p ); 1527 assertNotNull( resourceFileProcessorImpl.getProperties().getProperty().remove( p ) ); 1528 1529 p = resourceFileProcessorImpl.getProperties().getProperty( "TestPrimitiveProperty" ); 1530 assertNotNull( p ); 1531 p.setType( null ); 1532 1533 p = sourceFileProcessorImpl.getProperties().getProperty( "TestStringProperty" ); 1534 assertNotNull( p ); 1535 assertNotNull( sourceFileProcessorImpl.getProperties().getProperty().remove( p ) ); 1536 1537 p = sourceFileProcessorImpl.getProperties().getProperty( "TestPrimitiveProperty" ); 1538 assertNotNull( p ); 1539 p.setType( null ); 1540 1541 Message message = classFileProcessorImpl.getMessages().getMessage( "TestMessage" ); 1542 assertNotNull( message ); 1543 assertNotNull( classFileProcessorImpl.getMessages().getMessage().remove( message ) ); 1544 1545 message = resourceFileProcessorImpl.getMessages().getMessage( "TestMessage" ); 1546 assertNotNull( message ); 1547 assertNotNull( resourceFileProcessorImpl.getMessages().getMessage().remove( message ) ); 1548 1549 message = sourceFileProcessorImpl.getMessages().getMessage( "TestMessage" ); 1550 assertNotNull( message ); 1551 assertNotNull( sourceFileProcessorImpl.getMessages().getMessage().remove( message ) ); 1552 1553 Dependency dependency = classFileProcessorImpl.getDependencies().getDependency( "Locale" ); 1554 assertNotNull( dependency ); 1555 dependency.setImplementationName( null ); 1556 dependency.setVersion( Integer.toString( Integer.MAX_VALUE ) ); 1557 1558 dependency = classFileProcessorImpl.getDependencies().getDependency( "ClassFileProcessor" ); 1559 assertNotNull( dependency ); 1560 assertNotNull( classFileProcessorImpl.getDependencies().getDependency().remove( dependency ) ); 1561 1562 dependency = resourceFileProcessorImpl.getDependencies().getDependency( "Locale" ); 1563 assertNotNull( dependency ); 1564 dependency.setImplementationName( null ); 1565 dependency.setVersion( Integer.toString( Integer.MAX_VALUE ) ); 1566 1567 dependency = resourceFileProcessorImpl.getDependencies().getDependency( "ResourceFileProcessor" ); 1568 assertNotNull( dependency ); 1569 assertNotNull( resourceFileProcessorImpl.getDependencies().getDependency().remove( dependency ) ); 1570 1571 dependency = sourceFileProcessorImpl.getDependencies().getDependency( "Locale" ); 1572 assertNotNull( dependency ); 1573 dependency.setImplementationName( null ); 1574 dependency.setVersion( Integer.toString( Integer.MAX_VALUE ) ); 1575 1576 dependency = sourceFileProcessorImpl.getDependencies().getDependency( "SourceFileProcessor" ); 1577 assertNotNull( dependency ); 1578 assertNotNull( sourceFileProcessorImpl.getDependencies().getDependency().remove( dependency ) ); 1579 1580 this.getJomcTool().setModel( copy ); 1581 1582 this.getJomcTool().validateModelObjects( 1583 ModelContextFactory.newInstance().newModelContext( allClassesLoader ) ); 1584 1585 this.getJomcTool().validateModelObjects( 1586 testModule, ModelContextFactory.newInstance().newModelContext( moduleClassesLoader ) ); 1587 1588 this.getJomcTool().validateModelObjects( 1589 classFileProcessor, ModelContextFactory.newInstance().newModelContext( specificationClassesLoader ) ); 1590 1591 this.getJomcTool().validateModelObjects( 1592 classFileProcessorImpl, ModelContextFactory.newInstance().newModelContext( implementationClassesLoader ) ); 1593 1594 this.getJomcTool().validateModelObjects( this.getModelContext(), allClasses ); 1595 this.getJomcTool().validateModelObjects( testModule, this.getModelContext(), moduleClasses ); 1596 this.getJomcTool().validateModelObjects( classFileProcessor, this.getModelContext(), specificationClasses ); 1597 this.getJomcTool().validateModelObjects( classFileProcessorImpl, this.getModelContext(), 1598 implementationClasses ); 1599 1600 this.getJomcTool().validateModelObjects( 1601 ModelContextFactory.newInstance().newModelContext( uncommittedClassesLoader ) ); 1602 1603 this.getJomcTool().validateModelObjects( this.getModelContext(), uncommittedClasses ); 1604 1605 classFileProcessor.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1606 classFileProcessorImpl.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1607 resourceFileProcessor.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1608 resourceFileProcessorImpl.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1609 sourceFileProcessor.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1610 sourceFileProcessorImpl.setClazz( this.getClass().getPackage().getName() + ".DoesNotExist" ); 1611 1612 try 1613 { 1614 this.getJomcTool().validateModelObjects( 1615 ModelContextFactory.newInstance().newModelContext( allClassesLoader ) ); 1616 1617 fail( "Expected IOException not thrown." ); 1618 } 1619 catch ( final IOException e ) 1620 { 1621 assertNotNull( e.getMessage() ); 1622 System.out.println( e ); 1623 } 1624 1625 try 1626 { 1627 this.getJomcTool().validateModelObjects( 1628 testModule, ModelContextFactory.newInstance().newModelContext( moduleClassesLoader ) ); 1629 1630 fail( "Expected IOException not thrown." ); 1631 } 1632 catch ( final IOException e ) 1633 { 1634 assertNotNull( e.getMessage() ); 1635 System.out.println( e ); 1636 } 1637 1638 try 1639 { 1640 this.getJomcTool().validateModelObjects( 1641 classFileProcessor, ModelContextFactory.newInstance().newModelContext( specificationClassesLoader ) ); 1642 1643 fail( "Expected IOException not thrown." ); 1644 } 1645 catch ( final IOException e ) 1646 { 1647 assertNotNull( e.getMessage() ); 1648 System.out.println( e ); 1649 } 1650 1651 try 1652 { 1653 this.getJomcTool().validateModelObjects( classFileProcessorImpl, ModelContextFactory.newInstance(). 1654 newModelContext( implementationClassesLoader ) ); 1655 1656 fail( "Expected IOException not thrown." ); 1657 } 1658 catch ( final IOException e ) 1659 { 1660 assertNotNull( e.getMessage() ); 1661 System.out.println( e ); 1662 } 1663 1664 try 1665 { 1666 this.getJomcTool().validateModelObjects( this.getModelContext(), allClasses ); 1667 fail( "Expected IOException not thrown." ); 1668 } 1669 catch ( final IOException e ) 1670 { 1671 assertNotNull( e.getMessage() ); 1672 System.out.println( e ); 1673 } 1674 1675 try 1676 { 1677 this.getJomcTool().validateModelObjects( testModule, this.getModelContext(), moduleClasses ); 1678 fail( "Expected IOException not thrown." ); 1679 } 1680 catch ( final IOException e ) 1681 { 1682 assertNotNull( e.getMessage() ); 1683 System.out.println( e ); 1684 } 1685 1686 try 1687 { 1688 this.getJomcTool().validateModelObjects( classFileProcessor, this.getModelContext(), specificationClasses ); 1689 fail( "Expected IOException not thrown." ); 1690 } 1691 catch ( final IOException e ) 1692 { 1693 assertNotNull( e.getMessage() ); 1694 System.out.println( e ); 1695 } 1696 1697 try 1698 { 1699 this.getJomcTool().validateModelObjects( classFileProcessorImpl, 1700 this.getModelContext(), implementationClasses ); 1701 1702 fail( "Expected IOException not thrown." ); 1703 } 1704 catch ( final IOException e ) 1705 { 1706 assertNotNull( e.getMessage() ); 1707 System.out.println( e ); 1708 } 1709 1710 try 1711 { 1712 this.getJomcTool().validateModelObjects( 1713 ModelContextFactory.newInstance().newModelContext( uncommittedClassesLoader ) ); 1714 1715 fail( "Expected IOException not thrown." ); 1716 } 1717 catch ( final IOException e ) 1718 { 1719 assertNotNull( e.getMessage() ); 1720 System.out.println( e ); 1721 } 1722 1723 try 1724 { 1725 this.getJomcTool().validateModelObjects( this.getModelContext(), uncommittedClasses ); 1726 fail( "Expected IOException not thrown." ); 1727 } 1728 catch ( final IOException e ) 1729 { 1730 assertNotNull( e.getMessage() ); 1731 System.out.println( e ); 1732 } 1733 1734 this.getJomcTool().setModel( model ); 1735 } 1736 1737 @Test 1738 public final void testCopyConstructor() throws Exception 1739 { 1740 try 1741 { 1742 new ClassFileProcessor( null ); 1743 fail( "Expected NullPointerException not thrown." ); 1744 } 1745 catch ( final NullPointerException e ) 1746 { 1747 assertNotNull( e.getMessage() ); 1748 System.out.println( e.toString() ); 1749 } 1750 1751 new ClassFileProcessor( this.getJomcTool() ); 1752 } 1753 1754 @Test 1755 public final void testClassFileProcessorModelObjectsNotFound() throws Exception 1756 { 1757 final File tmpDir = new File( System.getProperty( "java.io.tmpdir", "/tmp" ) ); 1758 final JavaClass object = new ClassParser( 1759 ClassLoader.getSystemResourceAsStream( "java/lang/Object.class" ), "Object.class" ).parse(); 1760 1761 final Module m = new Module(); 1762 m.setName( "DOES_NOT_EXIST" ); 1763 1764 final Specification s = new Specification(); 1765 s.setIdentifier( "DOES_NOT_EXIST)" ); 1766 1767 final Implementation i = new Implementation(); 1768 i.setIdentifier( "DOES_NOT_EXIST" ); 1769 1770 final Model oldModel = this.getJomcTool().getModel(); 1771 this.getJomcTool().setModel( null ); 1772 1773 this.getJomcTool().commitModelObjects( this.getModelContext(), tmpDir ); 1774 this.getJomcTool().commitModelObjects( m, this.getModelContext(), tmpDir ); 1775 this.getJomcTool().commitModelObjects( s, this.getModelContext(), tmpDir ); 1776 this.getJomcTool().commitModelObjects( i, this.getModelContext(), tmpDir ); 1777 1778 this.getJomcTool().commitModelObjects( 1779 s, this.getModelContext().createMarshaller( ModelObject.MODEL_PUBLIC_ID ), object ); 1780 1781 this.getJomcTool().commitModelObjects( 1782 i, this.getModelContext().createMarshaller( ModelObject.MODEL_PUBLIC_ID ), object ); 1783 1784 this.getJomcTool().validateModelObjects( this.getModelContext() ); 1785 this.getJomcTool().validateModelObjects( m, this.getModelContext() ); 1786 this.getJomcTool().validateModelObjects( s, this.getModelContext() ); 1787 this.getJomcTool().validateModelObjects( i, this.getModelContext() ); 1788 1789 this.getJomcTool().validateModelObjects( this.getModelContext(), tmpDir ); 1790 this.getJomcTool().validateModelObjects( m, this.getModelContext(), tmpDir ); 1791 this.getJomcTool().validateModelObjects( s, this.getModelContext(), tmpDir ); 1792 this.getJomcTool().validateModelObjects( i, this.getModelContext(), tmpDir ); 1793 1794 this.getJomcTool().validateModelObjects( 1795 s, this.getModelContext().createUnmarshaller( ModelObject.MODEL_PUBLIC_ID ), object ); 1796 1797 this.getJomcTool().validateModelObjects( 1798 i, this.getModelContext().createUnmarshaller( ModelObject.MODEL_PUBLIC_ID ), object ); 1799 1800 this.getJomcTool().transformModelObjects( this.getModelContext(), tmpDir, 1801 Collections.<Transformer>emptyList() ); 1802 1803 this.getJomcTool().transformModelObjects( m, this.getModelContext(), tmpDir, 1804 Collections.<Transformer>emptyList() ); 1805 1806 this.getJomcTool().transformModelObjects( s, this.getModelContext(), tmpDir, 1807 Collections.<Transformer>emptyList() ); 1808 1809 this.getJomcTool().transformModelObjects( i, this.getModelContext(), tmpDir, 1810 Collections.<Transformer>emptyList() ); 1811 1812 this.getJomcTool().transformModelObjects( 1813 s, this.getModelContext().createMarshaller( ModelObject.MODEL_PUBLIC_ID ), 1814 this.getModelContext().createUnmarshaller( ModelObject.MODEL_PUBLIC_ID ), object, 1815 Collections.<Transformer>emptyList() ); 1816 1817 this.getJomcTool().transformModelObjects( 1818 i, this.getModelContext().createMarshaller( ModelObject.MODEL_PUBLIC_ID ), 1819 this.getModelContext().createUnmarshaller( ModelObject.MODEL_PUBLIC_ID ), object, 1820 Collections.<Transformer>emptyList() ); 1821 1822 this.getJomcTool().setModel( oldModel ); 1823 } 1824 1825 private Transformer getTransformer( final String resource ) 1826 throws URISyntaxException, TransformerConfigurationException 1827 { 1828 final TransformerFactory transformerFactory = TransformerFactory.newInstance(); 1829 final URL url = this.getClass().getResource( resource ); 1830 assertNotNull( url ); 1831 1832 final Transformer transformer = 1833 transformerFactory.newTransformer( new StreamSource( url.toURI().toASCIIString() ) ); 1834 1835 return transformer; 1836 } 1837 1838 private void unzipResource( final String resourceName, final File targetDirectory ) throws IOException 1839 { 1840 final URL resource = this.getClass().getResource( resourceName ); 1841 assertNotNull( "Expected '" + resourceName + "' not found.", resource ); 1842 1843 assertTrue( targetDirectory.isAbsolute() ); 1844 FileUtils.deleteDirectory( targetDirectory ); 1845 assertTrue( targetDirectory.mkdirs() ); 1846 1847 ZipInputStream in = null; 1848 boolean suppressExceptionOnClose = true; 1849 1850 try 1851 { 1852 in = new ZipInputStream( resource.openStream() ); 1853 ZipEntry e; 1854 1855 while ( ( e = in.getNextEntry() ) != null ) 1856 { 1857 if ( e.isDirectory() ) 1858 { 1859 continue; 1860 } 1861 1862 final File dest = new File( targetDirectory, e.getName() ); 1863 assertTrue( dest.isAbsolute() ); 1864 OutputStream out = null; 1865 1866 try 1867 { 1868 out = FileUtils.openOutputStream( dest ); 1869 IOUtils.copy( in, out ); 1870 suppressExceptionOnClose = false; 1871 } 1872 finally 1873 { 1874 try 1875 { 1876 if ( out != null ) 1877 { 1878 out.close(); 1879 } 1880 1881 suppressExceptionOnClose = true; 1882 } 1883 catch ( final IOException ex ) 1884 { 1885 if ( !suppressExceptionOnClose ) 1886 { 1887 throw ex; 1888 } 1889 } 1890 } 1891 1892 in.closeEntry(); 1893 } 1894 1895 suppressExceptionOnClose = false; 1896 } 1897 finally 1898 { 1899 try 1900 { 1901 if ( in != null ) 1902 { 1903 in.close(); 1904 } 1905 } 1906 catch ( final IOException e ) 1907 { 1908 if ( !suppressExceptionOnClose ) 1909 { 1910 throw e; 1911 } 1912 } 1913 } 1914 } 1915 1916}