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.FileInputStream;
35 import java.io.FileOutputStream;
36 import java.io.IOException;
37 import java.io.InputStream;
38 import java.io.OutputStream;
39 import org.apache.commons.io.IOUtils;
40 import org.jomc.model.Implementation;
41 import org.jomc.model.Module;
42 import org.jomc.model.Specification;
43 import org.jomc.modlet.Model;
44 import org.jomc.tools.SourceFileProcessor;
45 import org.jomc.util.SectionEditor;
46 import org.junit.Test;
47 import static org.junit.Assert.assertEquals;
48 import static org.junit.Assert.assertFalse;
49 import static org.junit.Assert.assertNotNull;
50 import static org.junit.Assert.assertNull;
51 import static org.junit.Assert.assertTrue;
52 import static org.junit.Assert.fail;
53
54
55
56
57
58
59
60 public class SourceFileProcessorTest extends JomcToolTest
61 {
62
63
64
65
66 private static final String ABSOLUTE_RESOURCE_NAME_PREFIX =
67 "/" + SourceFileProcessorTest.class.getPackage().getName().replace( '.', '/' ) + "/";
68
69
70
71
72 public SourceFileProcessorTest()
73 {
74 super();
75 }
76
77
78
79
80 @Override
81 public SourceFileProcessor getJomcTool()
82 {
83 return (SourceFileProcessor) super.getJomcTool();
84 }
85
86
87
88
89 @Override
90 protected SourceFileProcessor newJomcTool()
91 {
92 return new SourceFileProcessor();
93 }
94
95 @Test
96 @SuppressWarnings( "deprecation" )
97 public final void testSourceFileProcessorNullPointerException() throws Exception
98 {
99 try
100 {
101 this.getJomcTool().getSourceFileType( (Specification) null );
102 fail( "Expected NullPointerException not thrown." );
103 }
104 catch ( final NullPointerException e )
105 {
106 assertNullPointerException( e );
107 }
108
109 try
110 {
111 this.getJomcTool().getSourceFileType( (Implementation) null );
112 fail( "Expected NullPointerException not thrown." );
113 }
114 catch ( final NullPointerException e )
115 {
116 assertNullPointerException( e );
117 }
118
119 try
120 {
121 this.getJomcTool().getSourceFilesType( (Specification) null );
122 fail( "Expected NullPointerException not thrown." );
123 }
124 catch ( final NullPointerException e )
125 {
126 assertNullPointerException( e );
127 }
128
129 try
130 {
131 this.getJomcTool().getSourceFilesType( (Implementation) null );
132 fail( "Expected NullPointerException not thrown." );
133 }
134 catch ( final NullPointerException e )
135 {
136 assertNullPointerException( e );
137 }
138
139 try
140 {
141 this.getJomcTool().getSourceFileEditor( (Specification) null );
142 fail( "Expected NullPointerException not thrown." );
143 }
144 catch ( final NullPointerException e )
145 {
146 assertNullPointerException( e );
147 }
148
149 try
150 {
151 this.getJomcTool().getSourceFileEditor( (Implementation) null );
152 fail( "Expected NullPointerException not thrown." );
153 }
154 catch ( final NullPointerException e )
155 {
156 assertNullPointerException( e );
157 }
158
159 try
160 {
161 this.getJomcTool().manageSourceFiles( null );
162 fail( "Expected NullPointerException not thrown." );
163 }
164 catch ( final NullPointerException e )
165 {
166 assertNullPointerException( e );
167 }
168
169 try
170 {
171 this.getJomcTool().manageSourceFiles( (Implementation) null, new File( "/" ) );
172 fail( "Expected NullPointerException not thrown." );
173 }
174 catch ( final NullPointerException e )
175 {
176 assertNullPointerException( e );
177 }
178
179 try
180 {
181 this.getJomcTool().manageSourceFiles( new Implementation(), null );
182 fail( "Expected NullPointerException not thrown." );
183 }
184 catch ( final NullPointerException e )
185 {
186 assertNullPointerException( e );
187 }
188
189 try
190 {
191 this.getJomcTool().manageSourceFiles( (Module) null, new File( "/" ) );
192 fail( "Expected NullPointerException not thrown." );
193 }
194 catch ( final NullPointerException e )
195 {
196 assertNullPointerException( e );
197 }
198
199 try
200 {
201 this.getJomcTool().manageSourceFiles( new Module(), null );
202 fail( "Expected NullPointerException not thrown." );
203 }
204 catch ( final NullPointerException e )
205 {
206 assertNullPointerException( e );
207 }
208
209 try
210 {
211 this.getJomcTool().manageSourceFiles( (Specification) null, new File( "/" ) );
212 fail( "Expected NullPointerException not thrown." );
213 }
214 catch ( final NullPointerException e )
215 {
216 assertNullPointerException( e );
217 }
218
219 try
220 {
221 this.getJomcTool().manageSourceFiles( new Specification(), null );
222 fail( "Expected NullPointerException not thrown." );
223 }
224 catch ( final NullPointerException e )
225 {
226 assertNullPointerException( e );
227 }
228 }
229
230 @Test
231 public final void testSourceFileProcessorNotNull() throws Exception
232 {
233 assertNotNull( this.getJomcTool().getSourceFilesType(
234 this.getJomcTool().getModules().getImplementation( "Implementation" ) ) );
235
236 assertNotNull( this.getJomcTool().getSourceFilesType(
237 this.getJomcTool().getModules().getSpecification( "Specification" ) ) );
238
239 assertNotNull( this.getJomcTool().getSourceFileEditor() );
240 }
241
242 @Test
243 public final void testManageSources() throws Exception
244 {
245 this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
246 this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
247
248 final File nonExistingDirectory = this.getNextOutputDirectory();
249
250 try
251 {
252 this.getJomcTool().manageSourceFiles( nonExistingDirectory );
253 fail( "Expected IOException not thrown." );
254 }
255 catch ( final IOException e )
256 {
257 assertNotNull( e.getMessage() );
258 System.out.println( e );
259 }
260
261 try
262 {
263 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
264 nonExistingDirectory );
265
266 fail( "Expected IOException not thrown." );
267 }
268 catch ( final IOException e )
269 {
270 assertNotNull( e.getMessage() );
271 System.out.println( e );
272 }
273
274 try
275 {
276 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
277 nonExistingDirectory );
278
279 fail( "Expected IOException not thrown." );
280 }
281 catch ( final IOException e )
282 {
283 assertNotNull( e.getMessage() );
284 System.out.println( e );
285 }
286
287 try
288 {
289 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
290 nonExistingDirectory );
291
292 fail( "Expected IOException not thrown." );
293 }
294 catch ( final IOException e )
295 {
296 assertNotNull( e.getMessage() );
297 System.out.println( e );
298 }
299
300 File sourcesDirectory = this.getNextOutputDirectory();
301 assertTrue( sourcesDirectory.mkdirs() );
302 this.getJomcTool().manageSourceFiles( sourcesDirectory );
303 this.getJomcTool().manageSourceFiles( sourcesDirectory );
304
305 sourcesDirectory = this.getNextOutputDirectory();
306 assertTrue( sourcesDirectory.mkdirs() );
307 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
308 sourcesDirectory );
309
310 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
311 sourcesDirectory );
312
313 final File implementationDirectory = this.getNextOutputDirectory();
314 final File implementationSourceFile = new File( implementationDirectory, "Implementation.java" );
315 assertTrue( implementationDirectory.mkdirs() );
316 long implementationSourceFileLength;
317
318 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
319 implementationDirectory );
320
321 implementationSourceFileLength = implementationSourceFile.length();
322 assertTrue( implementationSourceFile.exists() );
323
324 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
325 implementationDirectory );
326
327 assertTrue( implementationSourceFile.exists() );
328 assertEquals( implementationSourceFileLength, implementationSourceFile.length() );
329
330 this.getJomcTool().getTemplateParameters().put( "with-assertions", Boolean.FALSE );
331 this.getJomcTool().getTemplateParameters().put( "with-author-copyright", Boolean.FALSE );
332 this.getJomcTool().getTemplateParameters().put( "with-editor-fold", Boolean.FALSE );
333 this.getJomcTool().getTemplateParameters().put( "with-javadoc", Boolean.FALSE );
334 this.getJomcTool().getTemplateParameters().put( "with-javadoc-author", Boolean.FALSE );
335 this.getJomcTool().getTemplateParameters().put( "with-javadoc-version", Boolean.FALSE );
336 this.getJomcTool().getTemplateParameters().put( "with-jsr-250", Boolean.FALSE );
337 this.getJomcTool().getTemplateParameters().put( "with-project-name", null );
338 this.getJomcTool().getTemplateParameters().put( "with-revision-keyword", null );
339 this.getJomcTool().getTemplateParameters().put( "with-suppress-warnings", null );
340 this.getJomcTool().getTemplateParameters().put( "with-vendor-copyright", null );
341
342 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
343 implementationDirectory );
344
345 assertTrue( implementationSourceFile.exists() );
346 assertTrue( implementationSourceFile.length() < implementationSourceFileLength );
347
348 this.getJomcTool().getTemplateParameters().clear();
349
350 this.getJomcTool().setTemplateProfile( "jomc-java-bundles" );
351
352 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
353 implementationDirectory );
354
355 this.getJomcTool().getTemplateParameters().put( "with-assertions", Boolean.FALSE );
356 this.getJomcTool().getTemplateParameters().put( "with-author-copyright", Boolean.FALSE );
357 this.getJomcTool().getTemplateParameters().put( "with-editor-fold", Boolean.FALSE );
358 this.getJomcTool().getTemplateParameters().put( "with-javadoc", Boolean.FALSE );
359 this.getJomcTool().getTemplateParameters().put( "with-javadoc-author", Boolean.FALSE );
360 this.getJomcTool().getTemplateParameters().put( "with-javadoc-version", Boolean.FALSE );
361 this.getJomcTool().getTemplateParameters().put( "with-jsr-250", Boolean.FALSE );
362 this.getJomcTool().getTemplateParameters().put( "with-project-name", null );
363 this.getJomcTool().getTemplateParameters().put( "with-revision-keyword", null );
364 this.getJomcTool().getTemplateParameters().put( "with-suppress-warnings", null );
365 this.getJomcTool().getTemplateParameters().put( "with-vendor-copyright", null );
366
367 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
368 implementationDirectory );
369
370 this.getJomcTool().getTemplateParameters().clear();
371
372 this.getJomcTool().setTemplateProfile( null );
373
374 this.getJomcTool().manageSourceFiles(
375 this.getJomcTool().getModules().getImplementation( "ImplementationWithSourceFilesModel" ),
376 implementationDirectory );
377
378 this.getJomcTool().manageSourceFiles(
379 this.getJomcTool().getModules().getImplementation( "ImplementationWithSourceFilesModel" ),
380 implementationDirectory );
381
382 final File specificationDirectory = this.getNextOutputDirectory();
383 assertTrue( specificationDirectory.mkdirs() );
384 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
385 specificationDirectory );
386
387 this.getJomcTool().getTemplateParameters().put( "with-assertions", Boolean.FALSE );
388 this.getJomcTool().getTemplateParameters().put( "with-author-copyright", Boolean.FALSE );
389 this.getJomcTool().getTemplateParameters().put( "with-editor-fold", Boolean.FALSE );
390 this.getJomcTool().getTemplateParameters().put( "with-javadoc", Boolean.FALSE );
391 this.getJomcTool().getTemplateParameters().put( "with-javadoc-author", Boolean.FALSE );
392 this.getJomcTool().getTemplateParameters().put( "with-javadoc-version", Boolean.FALSE );
393 this.getJomcTool().getTemplateParameters().put( "with-jsr-250", Boolean.FALSE );
394 this.getJomcTool().getTemplateParameters().put( "with-project-name", null );
395 this.getJomcTool().getTemplateParameters().put( "with-revision-keyword", null );
396 this.getJomcTool().getTemplateParameters().put( "with-suppress-warnings", null );
397 this.getJomcTool().getTemplateParameters().put( "with-vendor-copyright", null );
398
399 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
400 specificationDirectory );
401
402 this.getJomcTool().getTemplateParameters().clear();
403
404 this.getJomcTool().manageSourceFiles(
405 this.getJomcTool().getModules().getSpecification( "SpecificationWithSourceFilesModel" ),
406 specificationDirectory );
407
408 this.getJomcTool().manageSourceFiles(
409 this.getJomcTool().getModules().getSpecification( "SpecificationWithSourceFilesModel" ),
410 specificationDirectory );
411
412 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "IllegalImplementationSource.java.txt",
413 new File( implementationDirectory, "Implementation.java" ) );
414
415 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "IllegalSpecificationSource.java.txt",
416 new File( specificationDirectory, "Specification.java" ) );
417
418 try
419 {
420 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
421 implementationDirectory );
422
423 fail( "Expected IOException not thrown." );
424 }
425 catch ( final IOException e )
426 {
427 assertNotNull( e.getMessage() );
428 System.out.println( e.toString() );
429 }
430
431 try
432 {
433 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
434 specificationDirectory );
435
436 fail( "Expected IOException not thrown." );
437 }
438 catch ( final IOException e )
439 {
440 assertNotNull( e.getMessage() );
441 System.out.println( e.toString() );
442 }
443
444 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "EmptyImplementationSource.java.txt",
445 new File( implementationDirectory, "Implementation.java" ) );
446
447 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "EmptySpecificationSource.java.txt",
448 new File( specificationDirectory, "Specification.java" ) );
449
450 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
451 implementationDirectory );
452
453 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
454 specificationDirectory );
455
456 this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" );
457
458 sourcesDirectory = this.getNextOutputDirectory();
459 assertTrue( sourcesDirectory.mkdirs() );
460 this.getJomcTool().manageSourceFiles( sourcesDirectory );
461
462 sourcesDirectory = this.getNextOutputDirectory();
463 assertTrue( sourcesDirectory.mkdirs() );
464 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ), sourcesDirectory );
465
466 sourcesDirectory = this.getNextOutputDirectory();
467 assertTrue( sourcesDirectory.mkdirs() );
468 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
469 sourcesDirectory );
470
471 sourcesDirectory = this.getNextOutputDirectory();
472 assertTrue( sourcesDirectory.mkdirs() );
473 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
474 sourcesDirectory );
475
476 this.getJomcTool().setInputEncoding( null );
477 this.getJomcTool().setOutputEncoding( null );
478 }
479
480 @Test
481 public final void testMandatorySections() throws Exception
482 {
483 final SectionEditor editor = new SectionEditor();
484 final File specificationDirectory = this.getNextOutputDirectory();
485 final File implementationDirectory = this.getNextOutputDirectory();
486
487 assertTrue( specificationDirectory.mkdirs() );
488 assertTrue( implementationDirectory.mkdirs() );
489
490 this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
491 this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
492
493 File f = new File( implementationDirectory, "Implementation.java" );
494 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutAnnotationsSection.java.txt", f );
495 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
496 implementationDirectory );
497
498 String edited = this.toString( f );
499 editor.edit( edited );
500 assertTrue( editor.isSectionPresent( "Annotations" ) );
501
502 f = new File( implementationDirectory, "Implementation.java" );
503 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDependenciesSection.java.txt", f );
504 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
505 implementationDirectory );
506
507 edited = this.toString( f );
508 editor.edit( edited );
509 assertTrue( editor.isSectionPresent( "Dependencies" ) );
510
511 f = new File( implementationDirectory, "Implementation.java" );
512 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutMessagesSection.java.txt", f );
513 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
514 implementationDirectory );
515
516 edited = this.toString( f );
517 editor.edit( edited );
518 assertTrue( editor.isSectionPresent( "Messages" ) );
519
520 f = new File( implementationDirectory, "Implementation.java" );
521 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutPropertiesSection.java.txt", f );
522 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
523 implementationDirectory );
524
525 edited = this.toString( f );
526 editor.edit( edited );
527 assertTrue( editor.isSectionPresent( "Properties" ) );
528
529 f = new File( implementationDirectory, "ImplementationOfSpecification.java" );
530 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX
531 + "ImplementationOfSpecificationWithoutConstructorsSection.java.txt", f );
532
533 this.getJomcTool().manageSourceFiles(
534 this.getJomcTool().getModules().getImplementation( "ImplementationOfSpecification" ),
535 implementationDirectory );
536
537 edited = this.toString( f );
538 editor.edit( edited );
539 assertTrue( editor.isSectionPresent( "Constructors" ) );
540
541 f = new File( specificationDirectory, "Specification.java" );
542 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutAnnotationsSection.java.txt", f );
543 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
544 specificationDirectory );
545
546 edited = this.toString( f );
547 editor.edit( edited );
548 assertTrue( editor.isSectionPresent( "Annotations" ) );
549
550 this.getJomcTool().setInputEncoding( null );
551 this.getJomcTool().setOutputEncoding( null );
552 }
553
554 @Test
555 public final void testOptionalSections() throws Exception
556 {
557 final SectionEditor editor = new SectionEditor();
558 final File implementationDirectory = this.getNextOutputDirectory();
559 final File specificationDirectory = this.getNextOutputDirectory();
560
561 assertTrue( specificationDirectory.mkdirs() );
562 assertTrue( implementationDirectory.mkdirs() );
563
564 this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
565 this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
566
567 File f = new File( implementationDirectory, "Implementation.java" );
568 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutConstructorsSection.java.txt", f );
569 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
570 implementationDirectory );
571
572 String edited = this.toString( f );
573 editor.edit( edited );
574 assertFalse( editor.isSectionPresent( "Constructors" ) );
575 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDefaultConstructorSection.java.txt",
576 f );
577
578 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
579 implementationDirectory );
580
581 edited = this.toString( f );
582 editor.edit( edited );
583 assertTrue( editor.isSectionPresent( "Constructors" ) );
584 assertTrue( editor.isSectionPresent( "Default Constructor" ) );
585 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDocumentationSection.java.txt", f );
586 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
587 implementationDirectory );
588
589 edited = this.toString( f );
590 editor.edit( edited );
591 assertFalse( editor.isSectionPresent( "Documentation" ) );
592 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutLicenseSection.java.txt", f );
593 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
594 implementationDirectory );
595
596 edited = this.toString( f );
597 editor.edit( edited );
598 assertFalse( editor.isSectionPresent( "License Header" ) );
599
600 f = new File( specificationDirectory, "Specification.java" );
601 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutDocumentationSection.java.txt", f );
602 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
603 specificationDirectory );
604
605 edited = this.toString( f );
606 editor.edit( edited );
607 assertFalse( editor.isSectionPresent( "Documentation" ) );
608 this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutLicenseSection.java.txt", f );
609 this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
610 specificationDirectory );
611
612 edited = this.toString( f );
613 editor.edit( edited );
614 assertFalse( editor.isSectionPresent( "License Header" ) );
615
616 this.getJomcTool().setInputEncoding( null );
617 this.getJomcTool().setOutputEncoding( null );
618 }
619
620 @Test
621 public final void testSourceFileEditor() throws Exception
622 {
623 assertNotNull( this.getJomcTool().getSourceFileEditor() );
624 this.getJomcTool().setSourceFileEditor( null );
625 assertNotNull( this.getJomcTool().getSourceFileEditor() );
626 }
627
628 @Test
629 public final void testCopyConstructor() throws Exception
630 {
631 try
632 {
633 new SourceFileProcessor( null );
634 fail( "Expected NullPointerException not thrown." );
635 }
636 catch ( final NullPointerException e )
637 {
638 assertNotNull( e.getMessage() );
639 System.out.println( e.toString() );
640 }
641
642 new SourceFileProcessor( this.getJomcTool() );
643 }
644
645 @Test
646 public final void testSourceFileProcessorModelObjectsNotFound() throws Exception
647 {
648 final File tmpDir = new File( System.getProperty( "java.io.tmpdir", "/tmp" ) );
649 final Module m = new Module();
650 m.setName( "DOES_NOT_EXIST" );
651
652 final Specification s = new Specification();
653 s.setIdentifier( "DOES_NOT_EXIST)" );
654
655 final Implementation i = new Implementation();
656 i.setIdentifier( "DOES_NOT_EXIST" );
657
658 final Model oldModel = this.getJomcTool().getModel();
659 this.getJomcTool().setModel( null );
660
661 assertNull( this.getJomcTool().getSourceFilesType( s ) );
662 assertNull( this.getJomcTool().getSourceFilesType( i ) );
663
664 this.getJomcTool().manageSourceFiles( tmpDir );
665 this.getJomcTool().manageSourceFiles( m, tmpDir );
666 this.getJomcTool().manageSourceFiles( s, tmpDir );
667 this.getJomcTool().manageSourceFiles( i, tmpDir );
668
669 this.getJomcTool().setModel( oldModel );
670 }
671
672 private void copyResource( final String resourceName, final File file ) throws IOException
673 {
674 assertTrue( resourceName.startsWith( "/" ) );
675
676 InputStream in = null;
677 OutputStream out = null;
678
679 try
680 {
681 in = this.getClass().getResourceAsStream( resourceName );
682 assertNotNull( "Resource '" + resourceName + "' not found.", in );
683 out = new FileOutputStream( file );
684 IOUtils.copy( in, out );
685
686 out.close();
687 out = null;
688
689 in.close();
690 in = null;
691 }
692 finally
693 {
694 try
695 {
696 if ( out != null )
697 {
698 out.close();
699 }
700 }
701 catch ( final IOException e )
702 {
703
704 }
705 finally
706 {
707 try
708 {
709 if ( in != null )
710 {
711 in.close();
712 }
713 }
714 catch ( final IOException e )
715 {
716
717 }
718 }
719 }
720 }
721
722 private String toString( final File f ) throws IOException
723 {
724 InputStream in = null;
725
726 try
727 {
728 in = new FileInputStream( f );
729 final String str = IOUtils.toString( in, this.getResourceEncoding() );
730 in.close();
731 in = null;
732 return str;
733 }
734 finally
735 {
736 try
737 {
738 if ( in != null )
739 {
740 in.close();
741 }
742 }
743 catch ( final IOException e )
744 {
745
746 }
747 }
748 }
749
750 }