001/* 002 * Copyright (C) Christian Schulte, 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: JomcToolTest.java 4709 2013-01-02 06:17:48Z schulte $ 029 * 030 */ 031package org.jomc.tools.test; 032 033import java.io.File; 034import java.io.FileNotFoundException; 035import java.io.FileOutputStream; 036import java.io.IOException; 037import java.io.OutputStream; 038import java.net.URL; 039import java.text.ParseException; 040import java.util.Calendar; 041import java.util.Locale; 042import java.util.Properties; 043import java.util.logging.Level; 044import org.apache.commons.io.FileUtils; 045import org.jomc.model.Argument; 046import org.jomc.model.Dependency; 047import org.jomc.model.Implementation; 048import org.jomc.model.JavaIdentifier; 049import org.jomc.model.Message; 050import org.jomc.model.ModelObject; 051import org.jomc.model.Module; 052import org.jomc.model.Modules; 053import org.jomc.model.Property; 054import org.jomc.model.Specification; 055import org.jomc.model.SpecificationReference; 056import org.jomc.model.Text; 057import org.jomc.model.Texts; 058import org.jomc.model.modlet.DefaultModelProvider; 059import org.jomc.model.modlet.ModelHelper; 060import org.jomc.modlet.Model; 061import org.jomc.modlet.ModelContext; 062import org.jomc.modlet.ModelContextFactory; 063import org.jomc.modlet.ModelException; 064import org.jomc.modlet.ModelValidationReport; 065import org.jomc.tools.JomcTool; 066import org.junit.Test; 067import static org.junit.Assert.assertEquals; 068import static org.junit.Assert.assertNotNull; 069import static org.junit.Assert.assertNull; 070import static org.junit.Assert.assertTrue; 071import static org.junit.Assert.fail; 072 073/** 074 * Test cases for class {@code org.jomc.tools.JomcTool}. 075 * 076 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 077 * @version $JOMC: JomcToolTest.java 4709 2013-01-02 06:17:48Z schulte $ 078 */ 079public class JomcToolTest 080{ 081 082 /** Constant for the name of the system property holding the name of the encoding of resources backing the test. */ 083 private static final String RESOURCE_ENCODING_PROPERTY_NAME = "jomc.test.resourceEncoding"; 084 085 /** Constant for the name of the system property holding the output directory for the test. */ 086 private static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "jomc.test.outputDirectory"; 087 088 /** The {@code JomcTool} instance tests are performed with. */ 089 private JomcTool jomcTool; 090 091 /** The {@code ModelContext} of the instance. */ 092 private ModelContext modelContext; 093 094 /** The {@code Model} of the instance. */ 095 private Model model; 096 097 /** The name of the encoding to use when reading or writing resources. */ 098 private String resourceEncoding; 099 100 /** The output directory of the instance. */ 101 private File outputDirectory; 102 103 /** Serial number of next output directories. */ 104 private volatile int outputDirectoryId; 105 106 /** Creates a new {@code JomcToolTest} instance. */ 107 public JomcToolTest() 108 { 109 super(); 110 } 111 112 /** 113 * Gets the name of the encoding used when reading resources. 114 * 115 * @return The name of the encoding used when reading resources. 116 * 117 * @see #setResourceEncoding(java.lang.String) 118 */ 119 public final String getResourceEncoding() 120 { 121 if ( this.resourceEncoding == null ) 122 { 123 this.resourceEncoding = System.getProperty( RESOURCE_ENCODING_PROPERTY_NAME ); 124 assertNotNull( "Expected '" + RESOURCE_ENCODING_PROPERTY_NAME + "' system property not found.", 125 this.resourceEncoding ); 126 127 } 128 129 return this.resourceEncoding; 130 } 131 132 /** 133 * Sets the name of the encoding to use when reading resources. 134 * 135 * @param value The new name of the encoding to use when reading resources or {@code null}. 136 * 137 * @see #getResourceEncoding() 138 */ 139 public final void setResourceEncoding( final String value ) 140 { 141 this.resourceEncoding = value; 142 } 143 144 /** 145 * Gets the output directory of instance. 146 * 147 * @return The output directory of instance. 148 * 149 * @see #setOutputDirectory(java.io.File) 150 */ 151 public final File getOutputDirectory() 152 { 153 if ( this.outputDirectory == null ) 154 { 155 final String name = System.getProperty( OUTPUT_DIRECTORY_PROPERTY_NAME ); 156 assertNotNull( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property not found.", name ); 157 this.outputDirectory = new File( new File( name ), this.getClass().getSimpleName() ); 158 assertTrue( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property to hold an absolute path.", 159 this.outputDirectory.isAbsolute() ); 160 161 if ( !this.outputDirectory.exists() ) 162 { 163 assertTrue( this.outputDirectory.mkdirs() ); 164 } 165 } 166 167 return this.outputDirectory; 168 } 169 170 /** 171 * Sets the output directory of instance. 172 * 173 * @param value The new output directory of instance or {@code null}. 174 * 175 * @see #getOutputDirectory() 176 */ 177 public final void setOutputDirectory( final File value ) 178 { 179 if ( value != null ) 180 { 181 assertTrue( "Expected absolute 'outputDirectory'.", value.isAbsolute() ); 182 } 183 184 this.outputDirectory = value; 185 } 186 187 /** 188 * Gets the next output directory of the instance. 189 * 190 * @return The next output directory of the instance. 191 */ 192 public final File getNextOutputDirectory() 193 { 194 try 195 { 196 final File nextOutputDirectory = 197 new File( this.getOutputDirectory(), Integer.toString( this.outputDirectoryId++ ) ); 198 199 assertTrue( nextOutputDirectory.isAbsolute() ); 200 if ( nextOutputDirectory.exists() ) 201 { 202 FileUtils.deleteDirectory( nextOutputDirectory ); 203 } 204 205 return nextOutputDirectory; 206 } 207 catch ( final IOException e ) 208 { 209 throw new AssertionError( e ); 210 } 211 } 212 213 /** 214 * Gets the {@code JomcTool} instance tests are performed with. 215 * 216 * @return The {@code JomcTool} instance tests are performed with. 217 * 218 * @see #newJomcTool() 219 */ 220 public JomcTool getJomcTool() 221 { 222 if ( this.jomcTool == null ) 223 { 224 this.jomcTool = this.newJomcTool(); 225 this.jomcTool.setModel( this.getModel() ); 226 this.jomcTool.getListeners().add( new JomcTool.Listener() 227 { 228 229 @Override 230 public void onLog( final Level level, final String message, final Throwable throwable ) 231 { 232 super.onLog( level, message, throwable ); 233 System.out.println( "[" + level.getLocalizedName() + "] " + message ); 234 235 if ( throwable != null ) 236 { 237 throwable.printStackTrace( System.out ); 238 } 239 } 240 241 } ); 242 243 } 244 245 return this.jomcTool; 246 } 247 248 /** 249 * Creates a new {@code JomcTool} instance to test. 250 * 251 * @return A new {@code JomcTool} instance to test. 252 * 253 * @see #getJomcTool() 254 */ 255 protected JomcTool newJomcTool() 256 { 257 return new JomcTool(); 258 } 259 260 /** 261 * Gets the {@code ModelContext} instance backing the test. 262 * 263 * @return The {@code ModelContext} instance backing the test. 264 * 265 * @see #newModelContext() 266 */ 267 public ModelContext getModelContext() 268 { 269 if ( this.modelContext == null ) 270 { 271 this.modelContext = this.newModelContext(); 272 this.modelContext.getListeners().add( new ModelContext.Listener() 273 { 274 275 @Override 276 public void onLog( final Level level, String message, Throwable t ) 277 { 278 super.onLog( level, message, t ); 279 System.out.println( "[" + level.getLocalizedName() + "] " + message ); 280 281 if ( t != null ) 282 { 283 t.printStackTrace( System.out ); 284 } 285 } 286 287 } ); 288 289 } 290 291 return this.modelContext; 292 } 293 294 /** 295 * Creates a new {@code ModelContext} instance backing the test. 296 * 297 * @return A new {@code ModelContext} instance backing the test. 298 * 299 * @see #getModelContext() 300 */ 301 protected ModelContext newModelContext() 302 { 303 return ModelContextFactory.newInstance().newModelContext(); 304 } 305 306 /** 307 * Gets the {@code Model} instance backing the test. 308 * 309 * @return The {@code Model} instance backing the test. 310 * 311 * @see #newModel() 312 */ 313 public Model getModel() 314 { 315 if ( this.model == null ) 316 { 317 this.model = this.newModel(); 318 } 319 320 return this.model; 321 } 322 323 /** 324 * Creates a new {@code Model} instance backing the test. 325 * 326 * @return A new {@code Model} instance backing the test. 327 * 328 * @see #getModel() 329 */ 330 protected Model newModel() 331 { 332 try 333 { 334 DefaultModelProvider.setDefaultModuleLocation( this.getClass().getPackage().getName().replace( '.', '/' ) 335 + "/jomc.xml" ); 336 337 Model m = this.getModelContext().findModel( ModelObject.MODEL_PUBLIC_ID ); 338 339 if ( m != null ) 340 { 341 final Modules modules = ModelHelper.getModules( m ); 342 343 if ( modules != null ) 344 { 345 final Module cp = modules.getClasspathModule( Modules.getDefaultClasspathModuleName(), 346 this.getClass().getClassLoader() ); 347 348 if ( cp != null ) 349 { 350 modules.getModule().add( cp ); 351 } 352 } 353 354 m = this.getModelContext().processModel( m ); 355 356 if ( m != null ) 357 { 358 final ModelValidationReport validationReport = this.getModelContext().validateModel( m ); 359 360 for ( int i = 0, s0 = validationReport.getDetails().size(); i < s0; i++ ) 361 { 362 System.out.println( validationReport.getDetails().get( i ) ); 363 } 364 365 assertTrue( "Unexpected invalid '" + m.getIdentifier() + "' model.", 366 validationReport.isModelValid() ); 367 368 } 369 } 370 371 return m; 372 } 373 catch ( final ModelException e ) 374 { 375 throw new AssertionError( e ); 376 } 377 finally 378 { 379 DefaultModelProvider.setDefaultModuleLocation( null ); 380 } 381 } 382 383 @Test 384 @SuppressWarnings( "deprecation" ) 385 public final void testJomcToolNullPointerException() throws Exception 386 { 387 assertNotNull( this.getJomcTool() ); 388 389 try 390 { 391 this.getJomcTool().getDisplayLanguage( null ); 392 fail( "Expected NullPointerException not thrown." ); 393 } 394 catch ( final NullPointerException e ) 395 { 396 assertNullPointerException( e ); 397 } 398 399 try 400 { 401 this.getJomcTool().getImplementedJavaTypeNames( null, false ); 402 fail( "Expected NullPointerException not thrown." ); 403 } 404 catch ( final NullPointerException e ) 405 { 406 assertNullPointerException( e ); 407 } 408 409 try 410 { 411 this.getJomcTool().getJavaClasspathLocation( (Implementation) null ); 412 fail( "Expected NullPointerException not thrown." ); 413 } 414 catch ( final NullPointerException e ) 415 { 416 assertNullPointerException( e ); 417 } 418 419 try 420 { 421 this.getJomcTool().getJavaClasspathLocation( (Specification) null ); 422 fail( "Expected NullPointerException not thrown." ); 423 } 424 catch ( final NullPointerException e ) 425 { 426 assertNullPointerException( e ); 427 } 428 429 try 430 { 431 this.getJomcTool().getJavaGetterMethodName( (Dependency) null ); 432 fail( "Expected NullPointerException not thrown." ); 433 } 434 catch ( final NullPointerException e ) 435 { 436 assertNullPointerException( e ); 437 } 438 439 try 440 { 441 this.getJomcTool().getJavaGetterMethodName( (Message) null ); 442 fail( "Expected NullPointerException not thrown." ); 443 } 444 catch ( final NullPointerException e ) 445 { 446 assertNullPointerException( e ); 447 } 448 449 try 450 { 451 this.getJomcTool().getJavaGetterMethodName( (Property) null ); 452 fail( "Expected NullPointerException not thrown." ); 453 } 454 catch ( final NullPointerException e ) 455 { 456 assertNullPointerException( e ); 457 } 458 459 try 460 { 461 this.getJomcTool().getJavaMethodParameterName( (Argument) null ); 462 fail( "Expected NullPointerException not thrown." ); 463 } 464 catch ( final NullPointerException e ) 465 { 466 assertNullPointerException( e ); 467 } 468 469 try 470 { 471 this.getJomcTool().getJavaMethodParameterName( (Dependency) null ); 472 fail( "Expected NullPointerException not thrown." ); 473 } 474 catch ( final NullPointerException e ) 475 { 476 assertNullPointerException( e ); 477 } 478 479 try 480 { 481 this.getJomcTool().getJavaMethodParameterName( (Message) null ); 482 fail( "Expected NullPointerException not thrown." ); 483 } 484 catch ( final NullPointerException e ) 485 { 486 assertNullPointerException( e ); 487 } 488 489 try 490 { 491 this.getJomcTool().getJavaMethodParameterName( (Property) 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().getJavaInterfaceNames( null, false ); 502 fail( "Expected NullPointerException not thrown." ); 503 } 504 catch ( final NullPointerException e ) 505 { 506 assertNullPointerException( e ); 507 } 508 509 try 510 { 511 this.getJomcTool().getJavaModifierName( null, (Dependency) null ); 512 fail( "Expected NullPointerException not thrown." ); 513 } 514 catch ( final NullPointerException e ) 515 { 516 assertNullPointerException( e ); 517 } 518 try 519 { 520 this.getJomcTool().getJavaModifierName( new Implementation(), (Dependency) null ); 521 fail( "Expected NullPointerException not thrown." ); 522 } 523 catch ( final NullPointerException e ) 524 { 525 assertNullPointerException( e ); 526 } 527 528 try 529 { 530 this.getJomcTool().getJavaModifierName( null, (Message) null ); 531 fail( "Expected NullPointerException not thrown." ); 532 } 533 catch ( final NullPointerException e ) 534 { 535 assertNullPointerException( e ); 536 } 537 try 538 { 539 this.getJomcTool().getJavaModifierName( new Implementation(), (Message) null ); 540 fail( "Expected NullPointerException not thrown." ); 541 } 542 catch ( final NullPointerException e ) 543 { 544 assertNullPointerException( e ); 545 } 546 547 try 548 { 549 this.getJomcTool().getJavaModifierName( null, (Property) null ); 550 fail( "Expected NullPointerException not thrown." ); 551 } 552 catch ( final NullPointerException e ) 553 { 554 assertNullPointerException( e ); 555 } 556 try 557 { 558 this.getJomcTool().getJavaModifierName( new Implementation(), (Property) null ); 559 fail( "Expected NullPointerException not thrown." ); 560 } 561 catch ( final NullPointerException e ) 562 { 563 assertNullPointerException( e ); 564 } 565 566 try 567 { 568 this.getJomcTool().getJavaPackageName( (Implementation) null ); 569 fail( "Expected NullPointerException not thrown." ); 570 } 571 catch ( final NullPointerException e ) 572 { 573 assertNullPointerException( e ); 574 } 575 576 try 577 { 578 this.getJomcTool().getJavaPackageName( (Specification) null ); 579 fail( "Expected NullPointerException not thrown." ); 580 } 581 catch ( final NullPointerException e ) 582 { 583 assertNullPointerException( e ); 584 } 585 586 try 587 { 588 this.getJomcTool().getJavaPackageName( (SpecificationReference) null ); 589 fail( "Expected NullPointerException not thrown." ); 590 } 591 catch ( final NullPointerException e ) 592 { 593 assertNullPointerException( e ); 594 } 595 596 try 597 { 598 this.getJomcTool().getJavaSetterMethodName( (Dependency) null ); 599 fail( "Expected NullPointerException not thrown." ); 600 } 601 catch ( final NullPointerException e ) 602 { 603 assertNullPointerException( e ); 604 } 605 606 try 607 { 608 this.getJomcTool().getJavaSetterMethodName( (Message) null ); 609 fail( "Expected NullPointerException not thrown." ); 610 } 611 catch ( final NullPointerException e ) 612 { 613 assertNullPointerException( e ); 614 } 615 616 try 617 { 618 this.getJomcTool().getJavaSetterMethodName( (Property) null ); 619 fail( "Expected NullPointerException not thrown." ); 620 } 621 catch ( final NullPointerException e ) 622 { 623 assertNullPointerException( e ); 624 } 625 626 try 627 { 628 this.getJomcTool().getJavaTypeName( (Argument) null ); 629 fail( "Expected NullPointerException not thrown." ); 630 } 631 catch ( final NullPointerException e ) 632 { 633 assertNullPointerException( e ); 634 } 635 636 try 637 { 638 this.getJomcTool().getJavaTypeName( (Dependency) null ); 639 fail( "Expected NullPointerException not thrown." ); 640 } 641 catch ( final NullPointerException e ) 642 { 643 assertNullPointerException( e ); 644 } 645 646 try 647 { 648 this.getJomcTool().getJavaTypeName( (Implementation) null, true ); 649 fail( "Expected NullPointerException not thrown." ); 650 } 651 catch ( final NullPointerException e ) 652 { 653 assertNullPointerException( e ); 654 } 655 656 try 657 { 658 this.getJomcTool().getJavaTypeName( (Property) null, true ); 659 fail( "Expected NullPointerException not thrown." ); 660 } 661 catch ( final NullPointerException e ) 662 { 663 assertNullPointerException( e ); 664 } 665 666 try 667 { 668 this.getJomcTool().getJavaTypeName( (Specification) null, true ); 669 fail( "Expected NullPointerException not thrown." ); 670 } 671 catch ( final NullPointerException e ) 672 { 673 assertNullPointerException( e ); 674 } 675 676 try 677 { 678 this.getJomcTool().getJavaTypeName( (SpecificationReference) null, true ); 679 fail( "Expected NullPointerException not thrown." ); 680 } 681 catch ( final NullPointerException e ) 682 { 683 assertNullPointerException( e ); 684 } 685 686 try 687 { 688 this.getJomcTool().getJavadocComment( (Text) null, 0, "\n" ); 689 fail( "Expected NullPointerException not thrown." ); 690 } 691 catch ( final NullPointerException e ) 692 { 693 assertNullPointerException( e ); 694 } 695 try 696 { 697 this.getJomcTool().getJavadocComment( new Text(), 0, null ); 698 fail( "Expected NullPointerException not thrown." ); 699 } 700 catch ( final NullPointerException e ) 701 { 702 assertNullPointerException( e ); 703 } 704 try 705 { 706 this.getJomcTool().getJavadocComment( new Text(), Integer.MIN_VALUE, "\n" ); 707 fail( "Expected IllegalArgumentException not thrown." ); 708 } 709 catch ( final IllegalArgumentException e ) 710 { 711 assertIllegalArgumentException( e ); 712 } 713 714 try 715 { 716 this.getJomcTool().getJavadocComment( (Texts) null, 0, "\n" ); 717 fail( "Expected NullPointerException not thrown." ); 718 } 719 catch ( final NullPointerException e ) 720 { 721 assertNullPointerException( e ); 722 } 723 try 724 { 725 this.getJomcTool().getJavadocComment( new Texts(), 0, null ); 726 fail( "Expected NullPointerException not thrown." ); 727 } 728 catch ( final NullPointerException e ) 729 { 730 assertNullPointerException( e ); 731 } 732 try 733 { 734 this.getJomcTool().getJavadocComment( new Texts(), Integer.MIN_VALUE, "\n" ); 735 fail( "Expected IllegalArgumentException not thrown." ); 736 } 737 catch ( final IllegalArgumentException e ) 738 { 739 assertIllegalArgumentException( e ); 740 } 741 742 try 743 { 744 this.getJomcTool().getLongDate( null ); 745 fail( "Expected NullPointerException not thrown." ); 746 } 747 catch ( final NullPointerException e ) 748 { 749 assertNullPointerException( e ); 750 } 751 752 try 753 { 754 this.getJomcTool().getLongDateTime( null ); 755 fail( "Expected NullPointerException not thrown." ); 756 } 757 catch ( final NullPointerException e ) 758 { 759 assertNullPointerException( e ); 760 } 761 762 try 763 { 764 this.getJomcTool().getLongTime( null ); 765 fail( "Expected NullPointerException not thrown." ); 766 } 767 catch ( final NullPointerException e ) 768 { 769 assertNullPointerException( e ); 770 } 771 772 try 773 { 774 this.getJomcTool().getMediumDate( null ); 775 fail( "Expected NullPointerException not thrown." ); 776 } 777 catch ( final NullPointerException e ) 778 { 779 assertNullPointerException( e ); 780 } 781 782 try 783 { 784 this.getJomcTool().getMediumDateTime( null ); 785 fail( "Expected NullPointerException not thrown." ); 786 } 787 catch ( final NullPointerException e ) 788 { 789 assertNullPointerException( e ); 790 } 791 792 try 793 { 794 this.getJomcTool().getMediumTime( null ); 795 fail( "Expected NullPointerException not thrown." ); 796 } 797 catch ( final NullPointerException e ) 798 { 799 assertNullPointerException( e ); 800 } 801 802 try 803 { 804 this.getJomcTool().getShortDate( null ); 805 fail( "Expected NullPointerException not thrown." ); 806 } 807 catch ( final NullPointerException e ) 808 { 809 assertNullPointerException( e ); 810 } 811 812 try 813 { 814 this.getJomcTool().getShortDateTime( null ); 815 fail( "Expected NullPointerException not thrown." ); 816 } 817 catch ( final NullPointerException e ) 818 { 819 assertNullPointerException( e ); 820 } 821 822 try 823 { 824 this.getJomcTool().getShortTime( null ); 825 fail( "Expected NullPointerException not thrown." ); 826 } 827 catch ( final NullPointerException e ) 828 { 829 assertNullPointerException( e ); 830 } 831 832 try 833 { 834 this.getJomcTool().getVelocityTemplate( null ); 835 fail( "Expected NullPointerException not thrown." ); 836 } 837 catch ( final NullPointerException e ) 838 { 839 assertNullPointerException( e ); 840 } 841 842 try 843 { 844 this.getJomcTool().getYears( null, Calendar.getInstance() ); 845 fail( "Expected NullPointerException not thrown." ); 846 } 847 catch ( final NullPointerException e ) 848 { 849 assertNullPointerException( e ); 850 } 851 852 try 853 { 854 this.getJomcTool().getYears( Calendar.getInstance(), null ); 855 fail( "Expected NullPointerException not thrown." ); 856 } 857 catch ( final NullPointerException e ) 858 { 859 assertNullPointerException( e ); 860 } 861 862 try 863 { 864 this.getJomcTool().isJavaDefaultPackage( (Implementation) null ); 865 fail( "Expected NullPointerException not thrown." ); 866 } 867 catch ( final NullPointerException e ) 868 { 869 assertNullPointerException( e ); 870 } 871 872 try 873 { 874 this.getJomcTool().isJavaDefaultPackage( (Specification) null ); 875 fail( "Expected NullPointerException not thrown." ); 876 } 877 catch ( final NullPointerException e ) 878 { 879 assertNullPointerException( e ); 880 } 881 882 try 883 { 884 this.getJomcTool().isJavaPrimitiveType( null ); 885 fail( "Expected NullPointerException not thrown." ); 886 } 887 catch ( final NullPointerException e ) 888 { 889 assertNullPointerException( e ); 890 } 891 892 try 893 { 894 this.getJomcTool().isLoggable( null ); 895 fail( "Expected NullPointerException not thrown." ); 896 } 897 catch ( final NullPointerException e ) 898 { 899 assertNullPointerException( e ); 900 } 901 902 try 903 { 904 this.getJomcTool().getIsoDate( null ); 905 fail( "Expected NullPointerException not thrown." ); 906 } 907 catch ( final NullPointerException e ) 908 { 909 assertNullPointerException( e ); 910 } 911 912 try 913 { 914 this.getJomcTool().getIsoTime( null ); 915 fail( "Expected NullPointerException not thrown." ); 916 } 917 catch ( final NullPointerException e ) 918 { 919 assertNullPointerException( e ); 920 } 921 922 try 923 { 924 this.getJomcTool().getIsoDateTime( null ); 925 fail( "Expected NullPointerException not thrown." ); 926 } 927 catch ( final NullPointerException e ) 928 { 929 assertNullPointerException( e ); 930 } 931 932 try 933 { 934 this.getJomcTool().getTemplateEncoding( null ); 935 fail( "Expected NullPointerException not thrown." ); 936 } 937 catch ( final NullPointerException e ) 938 { 939 assertNullPointerException( e ); 940 } 941 942 try 943 { 944 this.getJomcTool().getParentTemplateProfile( null ); 945 fail( "Expected NullPointerException not thrown." ); 946 } 947 catch ( final NullPointerException e ) 948 { 949 assertNullPointerException( e ); 950 } 951 } 952 953 @Test 954 @SuppressWarnings( "deprecation" ) 955 public final void testJomcToolNotNull() throws Exception 956 { 957 final Specification specification = new Specification(); 958 specification.setClazz( "java.lang.Object" ); 959 specification.setIdentifier( "java.lang.Object" ); 960 961 final Specification defaultPackageSpecification = new Specification(); 962 defaultPackageSpecification.setClazz( "Object" ); 963 defaultPackageSpecification.setIdentifier( "Object" ); 964 965 final Implementation implementation = new Implementation(); 966 implementation.setIdentifier( "java.lang.Object" ); 967 implementation.setName( "java.lang.Object" ); 968 implementation.setClazz( "java.lang.Object" ); 969 970 final Implementation defaultPackageImplementation = new Implementation(); 971 defaultPackageImplementation.setIdentifier( "Object" ); 972 defaultPackageImplementation.setName( "Object" ); 973 defaultPackageImplementation.setClazz( "Object" ); 974 975 final Dependency d = new Dependency(); 976 d.setIdentifier( "java.util.Locale" ); 977 d.setName( "locale" ); 978 d.setImplementationName( "default" ); 979 980 final Property p = new Property(); 981 p.setName( "property" ); 982 p.setValue( "Test" ); 983 984 final Message m = new Message(); 985 m.setName( "message" ); 986 987 final Calendar now = Calendar.getInstance(); 988 final Calendar nextYear = Calendar.getInstance(); 989 nextYear.set( Calendar.YEAR, nextYear.get( Calendar.YEAR ) + 1 ); 990 991 assertNotNull( this.getJomcTool().getListeners() ); 992 assertNotNull( this.getJomcTool().getInputEncoding() ); 993 assertNotNull( this.getJomcTool().getModel() ); 994 assertNotNull( this.getJomcTool().getModules() ); 995 assertNotNull( this.getJomcTool().getOutputEncoding() ); 996 assertNotNull( this.getJomcTool().getTemplateProfile() ); 997 assertNotNull( this.getJomcTool().getTemplateEncoding() ); 998 assertNotNull( this.getJomcTool().getDefaultTemplateEncoding() ); 999 assertNotNull( this.getJomcTool().getTemplateParameters() ); 1000 assertNotNull( this.getJomcTool().getIndentation() ); 1001 assertNotNull( this.getJomcTool().getLineSeparator() ); 1002 assertNotNull( this.getJomcTool().getVelocityContext() ); 1003 assertNotNull( this.getJomcTool().getVelocityEngine() ); 1004 assertNotNull( JomcTool.getDefaultLogLevel() ); 1005 assertNotNull( this.getJomcTool().getLongDate( now ) ); 1006 assertNotNull( this.getJomcTool().getLongDateTime( now ) ); 1007 assertNotNull( this.getJomcTool().getLongTime( now ) ); 1008 assertNotNull( this.getJomcTool().getMediumDate( now ) ); 1009 assertNotNull( this.getJomcTool().getMediumDateTime( now ) ); 1010 assertNotNull( this.getJomcTool().getMediumTime( now ) ); 1011 assertNotNull( this.getJomcTool().getShortDate( now ) ); 1012 assertNotNull( this.getJomcTool().getShortDateTime( now ) ); 1013 assertNotNull( this.getJomcTool().getShortTime( now ) ); 1014 assertNotNull( this.getJomcTool().getIsoDate( now ) ); 1015 assertNotNull( this.getJomcTool().getIsoDateTime( now ) ); 1016 assertNotNull( this.getJomcTool().getIsoTime( now ) ); 1017 assertNotNull( this.getJomcTool().getYears( now, now ) ); 1018 assertNotNull( this.getJomcTool().getYears( now, nextYear ) ); 1019 assertNotNull( this.getJomcTool().getYears( nextYear, now ) ); 1020 assertNotNull( this.getJomcTool().getDisplayLanguage( "en" ) ); 1021 1022 assertEquals( this.getJomcTool().getYears( now, nextYear ), this.getJomcTool().getYears( nextYear, now ) ); 1023 assertEquals( Locale.getDefault().getDisplayLanguage(), 1024 this.getJomcTool().getDisplayLanguage( Locale.getDefault().getLanguage() ) ); 1025 1026 assertEquals( "java/lang/Object", this.getJomcTool().getJavaClasspathLocation( implementation ) ); 1027 assertEquals( "Object", this.getJomcTool().getJavaClasspathLocation( defaultPackageImplementation ) ); 1028 assertEquals( "java/lang/Object", this.getJomcTool().getJavaClasspathLocation( specification ) ); 1029 assertEquals( "Object", this.getJomcTool().getJavaClasspathLocation( defaultPackageSpecification ) ); 1030 assertEquals( "getLocale", this.getJomcTool().getJavaGetterMethodName( d ) ); 1031 assertEquals( "getMessage", this.getJomcTool().getJavaGetterMethodName( m ) ); 1032 assertEquals( "getProperty", this.getJomcTool().getJavaGetterMethodName( p ) ); 1033 assertEquals( 0, this.getJomcTool().getJavaInterfaceNames( implementation, true ).size() ); 1034 assertEquals( 0, this.getJomcTool().getImplementedJavaTypeNames( implementation, true ).size() ); 1035 assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, d ) ); 1036 assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, m ) ); 1037 assertEquals( "private", this.getJomcTool().getJavaModifierName( implementation, p ) ); 1038 assertEquals( "java.lang", this.getJomcTool().getJavaPackageName( implementation ) ); 1039 assertEquals( "", this.getJomcTool().getJavaPackageName( defaultPackageImplementation ) ); 1040 assertEquals( "java.lang", this.getJomcTool().getJavaPackageName( specification ) ); 1041 assertEquals( "", this.getJomcTool().getJavaPackageName( defaultPackageSpecification ) ); 1042 assertEquals( "java.util", this.getJomcTool().getJavaPackageName( d ) ); 1043 assertEquals( "", this.getJomcTool().getJavaString( "" ) ); 1044 assertEquals( this.getJomcTool().getIndentation(), this.getJomcTool().getIndentation( 1 ) ); 1045 assertEquals( this.getJomcTool().getDefaultTemplateEncoding(), 1046 this.getJomcTool().getTemplateEncoding( "DOES_NOT_EXIST" ) ); 1047 1048 assertEquals( this.getJomcTool().getDefaultTemplateProfile(), 1049 this.getJomcTool().getParentTemplateProfile( "DOES_NOT_EXIST" ) ); 1050 1051 } 1052 1053 @Test 1054 public final void testVelocityTemplates() throws Exception 1055 { 1056 assertNotNull( this.getJomcTool().getVelocityTemplate( "Implementation.java.vm" ) ); 1057 this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" ); 1058 assertNotNull( this.getJomcTool().getVelocityTemplate( "Implementation.java.vm" ) ); 1059 this.getJomcTool().setTemplateProfile( null ); 1060 1061 try 1062 { 1063 this.getJomcTool().getVelocityTemplate( "DOES_NOT_EXIST" ); 1064 fail( "Expected FileNotFoundException not thrown." ); 1065 } 1066 catch ( final FileNotFoundException e ) 1067 { 1068 assertNotNull( e.getMessage() ); 1069 System.out.println( e.toString() ); 1070 } 1071 1072 try 1073 { 1074 this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" ); 1075 this.getJomcTool().getVelocityTemplate( "DOES_NOT_EXIST" ); 1076 fail( "Expected FileNotFoundException not thrown." ); 1077 } 1078 catch ( final FileNotFoundException e ) 1079 { 1080 assertNotNull( e.getMessage() ); 1081 System.out.println( e.toString() ); 1082 } 1083 } 1084 1085 @Test 1086 public final void testDefaultLogLevel() throws Exception 1087 { 1088 final String testLogLevel = System.getProperty( "org.jomc.tools.JomcTool.defaultLogLevel" ); 1089 1090 assertNotNull( JomcTool.getDefaultLogLevel() ); 1091 JomcTool.setDefaultLogLevel( null ); 1092 System.setProperty( "org.jomc.tools.JomcTool.defaultLogLevel", "OFF" ); 1093 assertEquals( Level.OFF, JomcTool.getDefaultLogLevel() ); 1094 1095 if ( testLogLevel != null ) 1096 { 1097 System.setProperty( "org.jomc.tools.JomcTool.defaultLogLevel", testLogLevel ); 1098 } 1099 else 1100 { 1101 System.clearProperty( "org.jomc.tools.JomcTool.defaultLogLevel" ); 1102 } 1103 1104 JomcTool.setDefaultLogLevel( null ); 1105 } 1106 1107 @Test 1108 public final void testLogLevel() throws Exception 1109 { 1110 JomcTool.setDefaultLogLevel( null ); 1111 this.getJomcTool().setLogLevel( null ); 1112 assertNotNull( this.getJomcTool().getLogLevel() ); 1113 1114 JomcTool.setDefaultLogLevel( Level.OFF ); 1115 this.getJomcTool().setLogLevel( null ); 1116 assertEquals( Level.OFF, this.getJomcTool().getLogLevel() ); 1117 1118 JomcTool.setDefaultLogLevel( null ); 1119 this.getJomcTool().setLogLevel( null ); 1120 } 1121 1122 @Test 1123 @SuppressWarnings( "deprecation" ) 1124 public final void testDefaultTemplateProfile() throws Exception 1125 { 1126 assertNotNull( JomcTool.getDefaultTemplateProfile() ); 1127 System.setProperty( "org.jomc.tools.JomcTool.defaultTemplateProfile", "TEST" ); 1128 JomcTool.setDefaultTemplateProfile( null ); 1129 assertEquals( "TEST", JomcTool.getDefaultTemplateProfile() ); 1130 System.clearProperty( "org.jomc.tools.JomcTool.defaultTemplateProfile" ); 1131 JomcTool.setDefaultTemplateProfile( null ); 1132 } 1133 1134 @Test 1135 @SuppressWarnings( "deprecation" ) 1136 public final void testTemplateProfile() throws Exception 1137 { 1138 JomcTool.setDefaultTemplateProfile( null ); 1139 this.getJomcTool().setTemplateProfile( null ); 1140 assertNotNull( this.getJomcTool().getTemplateProfile() ); 1141 1142 JomcTool.setDefaultTemplateProfile( "TEST" ); 1143 this.getJomcTool().setTemplateProfile( null ); 1144 assertEquals( "TEST", this.getJomcTool().getTemplateProfile() ); 1145 1146 JomcTool.setDefaultTemplateProfile( null ); 1147 this.getJomcTool().setTemplateProfile( null ); 1148 } 1149 1150 @Test 1151 public final void testIndentation() throws Exception 1152 { 1153 assertEquals( "", this.getJomcTool().getIndentation( 0 ) ); 1154 assertEquals( this.getJomcTool().getIndentation(), this.getJomcTool().getIndentation( 1 ) ); 1155 1156 try 1157 { 1158 this.getJomcTool().getIndentation( Integer.MIN_VALUE ); 1159 fail( "Expected IllegalArgumentException not thrown." ); 1160 } 1161 catch ( final IllegalArgumentException e ) 1162 { 1163 assertIllegalArgumentException( e ); 1164 } 1165 1166 this.getJomcTool().setIndentation( " TEST " ); 1167 assertEquals( " TEST ", this.getJomcTool().getIndentation() ); 1168 assertEquals( " TEST ", this.getJomcTool().getIndentation( 1 ) ); 1169 this.getJomcTool().setIndentation( null ); 1170 } 1171 1172 @Test 1173 public final void testModel() throws Exception 1174 { 1175 final Model m = this.getJomcTool().getModel(); 1176 this.getJomcTool().setModel( null ); 1177 assertNotNull( this.getJomcTool().getModel() ); 1178 this.getJomcTool().setModel( m ); 1179 } 1180 1181 @Test 1182 public final void testVelocityEngine() throws Exception 1183 { 1184 this.getJomcTool().setVelocityEngine( null ); 1185 assertNotNull( this.getJomcTool().getVelocityEngine() ); 1186 this.getJomcTool().setVelocityEngine( null ); 1187 } 1188 1189 @Test 1190 public final void testVelocityContext() throws Exception 1191 { 1192 assertNotNull( this.getJomcTool().getVelocityContext() ); 1193 this.getJomcTool().setTemplateProfile( "test" ); 1194 assertNotNull( this.getJomcTool().getVelocityContext() ); 1195 assertNotNull( this.getJomcTool().getVelocityContext().get( "test-object" ) ); 1196 assertTrue( this.getJomcTool().getVelocityContext().get( "test-object" ) instanceof JomcTool ); 1197 assertNotNull( this.getJomcTool().getVelocityContext().get( "test-url" ) ); 1198 assertTrue( this.getJomcTool().getVelocityContext().get( "test-url" ) instanceof URL ); 1199 assertEquals( new URL( "file:///tmp" ), this.getJomcTool().getVelocityContext().get( "test-url" ) ); 1200 assertNotNull( this.getJomcTool().getVelocityContext().get( "test-string" ) ); 1201 assertTrue( this.getJomcTool().getVelocityContext().get( "test-string" ) instanceof String ); 1202 assertEquals( "Test", this.getJomcTool().getVelocityContext().get( "test-string" ) ); 1203 this.getJomcTool().setTemplateProfile( null ); 1204 } 1205 1206 @Test 1207 public final void testDefaultTemplateEncoding() throws Exception 1208 { 1209 this.getJomcTool().setDefaultTemplateEncoding( null ); 1210 assertNotNull( this.getJomcTool().getDefaultTemplateEncoding() ); 1211 this.getJomcTool().setDefaultTemplateEncoding( null ); 1212 } 1213 1214 @Test 1215 public final void testTemplateEncoding() throws Exception 1216 { 1217 final File templateLocation = this.getNextOutputDirectory(); 1218 File templatesDir = new File( templateLocation, "org" ); 1219 templatesDir = new File( templatesDir, "jomc" ); 1220 templatesDir = new File( templatesDir, "tools" ); 1221 templatesDir = new File( templatesDir, "templates" ); 1222 templatesDir = new File( templatesDir, "tmp" ); 1223 1224 assertTrue( templatesDir.mkdirs() ); 1225 1226 final Properties p = new Properties(); 1227 p.setProperty( "template-encoding", "ISO-8859-1" ); 1228 1229 final OutputStream profileProperties = new FileOutputStream( new File( templatesDir, "profile.properties" ) ); 1230 p.store( profileProperties, this.getClass().getName() ); 1231 profileProperties.close(); 1232 1233 this.getJomcTool().setDefaultTemplateEncoding( null ); 1234 this.getJomcTool().setTemplateLocation( templateLocation.toURI().toURL() ); 1235 1236 assertEquals( "ISO-8859-1", this.getJomcTool().getTemplateEncoding( "tmp" ) ); 1237 assertEquals( "US-ASCII", this.getJomcTool().getTemplateEncoding( "test" ) ); 1238 assertEquals( this.getJomcTool().getDefaultTemplateEncoding(), 1239 this.getJomcTool().getTemplateEncoding( "jomc-java-bundles" ) ); 1240 1241 this.getJomcTool().setTemplateLocation( null ); 1242 this.getJomcTool().setDefaultTemplateEncoding( null ); 1243 } 1244 1245 @Test 1246 public final void testInputEncoding() throws Exception 1247 { 1248 this.getJomcTool().setInputEncoding( null ); 1249 assertNotNull( this.getJomcTool().getInputEncoding() ); 1250 this.getJomcTool().setInputEncoding( null ); 1251 } 1252 1253 @Test 1254 public final void testOutputEncoding() throws Exception 1255 { 1256 this.getJomcTool().setOutputEncoding( null ); 1257 assertNotNull( this.getJomcTool().getOutputEncoding() ); 1258 this.getJomcTool().setOutputEncoding( null ); 1259 } 1260 1261 @Test 1262 public final void testLineSeparator() throws Exception 1263 { 1264 this.getJomcTool().setLineSeparator( null ); 1265 assertNotNull( this.getJomcTool().getLineSeparator() ); 1266 this.getJomcTool().setLineSeparator( null ); 1267 } 1268 1269 @Test 1270 @SuppressWarnings( "deprecation" ) 1271 public final void testJomcToolModelObjectsNotFound() throws Exception 1272 { 1273 final SpecificationReference ref = new SpecificationReference(); 1274 ref.setIdentifier( "DOES_NOT_EXIST" ); 1275 1276 final Implementation i = new Implementation(); 1277 i.setIdentifier( "DOES_NOT_EXSIST" ); 1278 1279 final Dependency d = new Dependency(); 1280 d.setIdentifier( "DOES_NOT_EXIST" ); 1281 1282 final Property p = new Property(); 1283 p.setName( "DOES_NOT_EXIST" ); 1284 1285 assertNull( this.getJomcTool().getJavaPackageName( ref ) ); 1286 assertNull( this.getJomcTool().getJavaTypeName( ref, false ) ); 1287 assertNull( this.getJomcTool().getJavaTypeName( d ) ); 1288 1289 final Model oldModel = this.getJomcTool().getModel(); 1290 this.getJomcTool().setModel( null ); 1291 assertTrue( this.getJomcTool().getImplementedJavaTypeNames( i, true ).isEmpty() ); 1292 assertEquals( "private", this.getJomcTool().getJavaModifierName( i, p ) ); 1293 this.getJomcTool().setModel( oldModel ); 1294 } 1295 1296 @Test 1297 @SuppressWarnings( "deprecation" ) 1298 public final void testJavaIdentifier() throws Exception 1299 { 1300 assertEquals( "", this.getJomcTool().getJavaIdentifier( "", true ) ); 1301 assertEquals( "", this.getJomcTool().getJavaIdentifier( "", false ) ); 1302 assertEquals( "", this.getJomcTool().getJavaIdentifier( " ", true ) ); 1303 assertEquals( "", this.getJomcTool().getJavaIdentifier( " ", false ) ); 1304 assertEquals( "testTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", false ) ); 1305 assertEquals( "testTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", false ) ); 1306 assertEquals( "TestTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", true ) ); 1307 assertEquals( "TestTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", true ) ); 1308 assertEquals( "testTestTest", this.getJomcTool().getJavaIdentifier( " Test test test ", false ) ); 1309 assertEquals( "testTestTest", this.getJomcTool().getJavaIdentifier( " Test test test ", false ) ); 1310 assertEquals( "TestTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", true ) ); 1311 assertEquals( "TestTestTest", this.getJomcTool().getJavaIdentifier( " test test test ", true ) ); 1312 } 1313 1314 @Test 1315 @SuppressWarnings( "deprecation" ) 1316 public final void testJavaConstantName() throws Exception 1317 { 1318 assertEquals( "", this.getJomcTool().getJavaConstantName( "" ) ); 1319 assertEquals( "", this.getJomcTool().getJavaConstantName( " " ) ); 1320 assertEquals( "TEST_TEST_TEST", this.getJomcTool().getJavaConstantName( " test test test " ) ); 1321 assertEquals( "TEST_TEST_TEST", this.getJomcTool().getJavaConstantName( " test test test " ) ); 1322 assertEquals( "TEST_T_EST_TE_ST_TES_T", 1323 this.getJomcTool().getJavaConstantName( " Test tEst teSt tesT " ) ); 1324 1325 } 1326 1327 @Test 1328 @SuppressWarnings( "deprecation" ) 1329 public final void testJavaFieldName() throws Exception 1330 { 1331 assertEquals( "", this.getJomcTool().getJavaFieldName( "" ) ); 1332 assertEquals( "", this.getJomcTool().getJavaFieldName( " " ) ); 1333 assertEquals( "testTestTest", this.getJomcTool().getJavaFieldName( " test test test " ) ); 1334 assertEquals( "testTestTest", this.getJomcTool().getJavaFieldName( " test test test " ) ); 1335 assertEquals( "testTEstTeStTesT", this.getJomcTool().getJavaFieldName( " Test tEst teSt tesT " ) ); 1336 assertEquals( "testTEstTeStTesT", this.getJomcTool().getJavaFieldName( " Test tEst teSt tesT " ) ); 1337 assertEquals( "_package", this.getJomcTool().getJavaFieldName( " Package " ) ); 1338 assertEquals( "_new", this.getJomcTool().getJavaFieldName( " New " ) ); 1339 } 1340 1341 @Test 1342 @SuppressWarnings( "deprecation" ) 1343 public final void testJavaMethodParameterName() throws Exception 1344 { 1345 assertEquals( "", this.getJomcTool().getJavaMethodParameterName( "" ) ); 1346 assertEquals( "", this.getJomcTool().getJavaMethodParameterName( " " ) ); 1347 assertEquals( "testTestTest", this.getJomcTool().getJavaMethodParameterName( " test test test " ) ); 1348 assertEquals( "testTEstTeStTesT", this.getJomcTool().getJavaMethodParameterName( " Test tEst teSt tesT " ) ); 1349 assertEquals( "testTEstTeStTesT", 1350 this.getJomcTool().getJavaMethodParameterName( " Test tEst teSt tesT " ) ); 1351 1352 assertEquals( "_package", this.getJomcTool().getJavaMethodParameterName( " Package " ) ); 1353 assertEquals( "_new", this.getJomcTool().getJavaMethodParameterName( " New " ) ); 1354 } 1355 1356 @Test 1357 public final void testToJavaConstantName() throws Exception 1358 { 1359 try 1360 { 1361 this.getJomcTool().toJavaConstantName( "" ); 1362 fail( "Expected 'ParseException' not thrown." ); 1363 } 1364 catch ( final ParseException e ) 1365 { 1366 System.out.println( e.toString() ); 1367 assertNotNull( e.getMessage() ); 1368 } 1369 try 1370 { 1371 this.getJomcTool().toJavaConstantName( " " ); 1372 fail( "Expected 'ParseException' not thrown." ); 1373 } 1374 catch ( final ParseException e ) 1375 { 1376 System.out.println( e.toString() ); 1377 assertNotNull( e.getMessage() ); 1378 } 1379 1380 assertEquals( JavaIdentifier.valueOf( "TEST_TEST_TEST" ), 1381 this.getJomcTool().toJavaConstantName( " test test test " ) ); 1382 1383 assertEquals( JavaIdentifier.valueOf( "TEST_TEST_TEST_TEST" ), 1384 this.getJomcTool().toJavaConstantName( " Test tEst teSt tesT " ) ); 1385 1386 assertEquals( JavaIdentifier.valueOf( "TEST_TEST_TEST_TEST" ), 1387 this.getJomcTool().toJavaConstantName( " Test tEst teSt tesT " ) ); 1388 1389 assertEquals( JavaIdentifier.valueOf( "PACKAGE" ), this.getJomcTool().toJavaConstantName( " Package " ) ); 1390 assertEquals( JavaIdentifier.valueOf( "NEW" ), this.getJomcTool().toJavaConstantName( " New " ) ); 1391 } 1392 1393 @Test 1394 public final void testToJavaMethodName() throws Exception 1395 { 1396 try 1397 { 1398 this.getJomcTool().toJavaMethodName( "" ); 1399 fail( "Expected 'ParseException' not thrown." ); 1400 } 1401 catch ( final ParseException e ) 1402 { 1403 System.out.println( e.toString() ); 1404 assertNotNull( e.getMessage() ); 1405 } 1406 try 1407 { 1408 this.getJomcTool().toJavaMethodName( " " ); 1409 fail( "Expected 'ParseException' not thrown." ); 1410 } 1411 catch ( final ParseException e ) 1412 { 1413 System.out.println( e.toString() ); 1414 assertNotNull( e.getMessage() ); 1415 } 1416 1417 assertEquals( JavaIdentifier.valueOf( "testTestTest" ), 1418 this.getJomcTool().toJavaMethodName( " test test test " ) ); 1419 1420 assertEquals( JavaIdentifier.valueOf( "testTestTestTest" ), 1421 this.getJomcTool().toJavaMethodName( " Test tEst teSt tesT " ) ); 1422 1423 assertEquals( JavaIdentifier.valueOf( "testTestTestTest" ), 1424 this.getJomcTool().toJavaMethodName( " Test tEst teSt tesT " ) ); 1425 1426 assertEquals( JavaIdentifier.valueOf( "_package" ), this.getJomcTool().toJavaMethodName( " Package " ) ); 1427 assertEquals( JavaIdentifier.valueOf( "_new" ), this.getJomcTool().toJavaMethodName( " New " ) ); 1428 } 1429 1430 @Test 1431 public final void testToJavaVariableName() throws Exception 1432 { 1433 try 1434 { 1435 this.getJomcTool().toJavaVariableName( "" ); 1436 fail( "Expected 'ParseException' not thrown." ); 1437 } 1438 catch ( final ParseException e ) 1439 { 1440 System.out.println( e.toString() ); 1441 assertNotNull( e.getMessage() ); 1442 } 1443 try 1444 { 1445 this.getJomcTool().toJavaVariableName( " " ); 1446 fail( "Expected 'ParseException' not thrown." ); 1447 } 1448 catch ( final ParseException e ) 1449 { 1450 System.out.println( e.toString() ); 1451 assertNotNull( e.getMessage() ); 1452 } 1453 1454 assertEquals( JavaIdentifier.valueOf( "testTestTest" ), 1455 this.getJomcTool().toJavaVariableName( " test test test " ) ); 1456 1457 assertEquals( JavaIdentifier.valueOf( "testTestTestTest" ), 1458 this.getJomcTool().toJavaVariableName( " Test tEst teSt tesT " ) ); 1459 1460 assertEquals( JavaIdentifier.valueOf( "testTestTestTest" ), 1461 this.getJomcTool().toJavaVariableName( " Test tEst teSt tesT " ) ); 1462 1463 assertEquals( JavaIdentifier.valueOf( "_package" ), this.getJomcTool().toJavaVariableName( " Package " ) ); 1464 assertEquals( JavaIdentifier.valueOf( "_new" ), this.getJomcTool().toJavaVariableName( " New " ) ); 1465 } 1466 1467 @Test 1468 public final void testParentTemplateProfile() throws Exception 1469 { 1470 final File templateLocation = this.getNextOutputDirectory(); 1471 File templatesDir = new File( templateLocation, "org" ); 1472 templatesDir = new File( templatesDir, "jomc" ); 1473 templatesDir = new File( templatesDir, "tools" ); 1474 templatesDir = new File( templatesDir, "templates" ); 1475 templatesDir = new File( templatesDir, "tmp" ); 1476 1477 assertTrue( templatesDir.mkdirs() ); 1478 1479 final Properties p = new Properties(); 1480 p.setProperty( "parent-template-profile", "test" ); 1481 1482 final OutputStream profileProperties = new FileOutputStream( new File( templatesDir, "profile.properties" ) ); 1483 p.store( profileProperties, this.getClass().getName() ); 1484 profileProperties.close(); 1485 1486 this.getJomcTool().setDefaultTemplateProfile( null ); 1487 this.getJomcTool().setTemplateLocation( templateLocation.toURI().toURL() ); 1488 1489 assertEquals( "test", this.getJomcTool().getParentTemplateProfile( "tmp" ) ); 1490 assertEquals( "jomc-java-bundles", this.getJomcTool().getParentTemplateProfile( "test" ) ); 1491 assertEquals( this.getJomcTool().getDefaultTemplateProfile(), 1492 this.getJomcTool().getParentTemplateProfile( "jomc-java-bundles" ) ); 1493 1494 assertNull( this.getJomcTool().getParentTemplateProfile( this.getJomcTool().getDefaultTemplateProfile() ) ); 1495 this.getJomcTool().setTemplateLocation( null ); 1496 this.getJomcTool().setDefaultTemplateEncoding( null ); 1497 } 1498 1499 @Test 1500 public final void testHtmlString() throws Exception 1501 { 1502 assertEquals( "<>"∗&", this.getJomcTool().getHtmlString( "<>\"*&" ) ); 1503 } 1504 1505 public static void assertNullPointerException( final NullPointerException e ) 1506 { 1507 assertNotNull( e ); 1508 assertNotNull( e.getMessage() ); 1509 System.out.println( e.toString() ); 1510 } 1511 1512 public static void assertIllegalArgumentException( final IllegalArgumentException e ) 1513 { 1514 assertNotNull( e ); 1515 assertNotNull( e.getMessage() ); 1516 System.out.println( e.toString() ); 1517 } 1518 1519}