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