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