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