View Javadoc

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