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
32
33
34
35
36 package org.jomc.cli.test;
37
38 import java.io.File;
39 import java.io.IOException;
40 import java.io.OutputStream;
41 import java.net.URI;
42 import java.net.URL;
43 import java.util.zip.ZipEntry;
44 import java.util.zip.ZipInputStream;
45 import javax.xml.bind.JAXBElement;
46 import javax.xml.bind.Unmarshaller;
47 import javax.xml.transform.stream.StreamSource;
48 import javax.xml.validation.Schema;
49 import org.apache.commons.io.FileUtils;
50 import org.apache.commons.io.IOUtils;
51 import org.jomc.ObjectManagerFactory;
52 import org.jomc.cli.Command;
53 import org.jomc.cli.Jomc;
54 import org.jomc.model.ModelObject;
55 import org.jomc.model.Module;
56 import org.jomc.modlet.ModelContext;
57 import org.jomc.modlet.ModelContextFactory;
58 import org.jomc.modlet.Modlet;
59 import org.jomc.modlet.ModletObject;
60 import org.junit.Before;
61 import org.junit.Test;
62 import static org.junit.Assert.assertEquals;
63 import static org.junit.Assert.assertFalse;
64 import static org.junit.Assert.assertNotNull;
65 import static org.junit.Assert.assertNull;
66 import static org.junit.Assert.assertTrue;
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
89
90
91 public class JomcTest
92 {
93
94
95
96 private static final String ABSOLUTE_RESOURCE_NAME_PREFIX = "/org/jomc/cli/test/";
97
98
99 private static final String OUTPUT_DIRECTORY_PROPERTY_NAME = "jomc.test.outputDirectory";
100
101
102 private static final String[] TEST_RESOURCE_NAMES =
103 {
104 "model-relocations.xsl",
105 "modlet-relocations.xsl",
106 "jomc.xml",
107 "illegal-module.xml",
108 "illegal-module-document.xml",
109 "module-nonexistent-classes.xml"
110 };
111
112
113 private File outputDirectory;
114
115
116
117
118
119
120
121
122 public final File getOutputDirectory()
123 {
124 if ( this.outputDirectory == null )
125 {
126 final String name = System.getProperty( OUTPUT_DIRECTORY_PROPERTY_NAME );
127 assertNotNull( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property not found.", name );
128 this.outputDirectory = new File( new File( name ), "JomcTest" );
129 assertTrue( "Expected '" + OUTPUT_DIRECTORY_PROPERTY_NAME + "' system property to hold an absolute path.",
130 this.outputDirectory.isAbsolute() );
131
132 if ( !this.outputDirectory.exists() )
133 {
134 assertTrue( this.outputDirectory.mkdirs() );
135 }
136 }
137
138 return this.outputDirectory;
139 }
140
141
142
143
144
145
146
147
148 public final void setOutputDirectory( final File value )
149 {
150 if ( value != null )
151 {
152 assertTrue( "Expected absolute 'outputDirectory'.", value.isAbsolute() );
153 }
154
155 this.outputDirectory = value;
156 }
157
158 @Test
159 public final void testNoArguments() throws Exception
160 {
161 assertEquals( Command.STATUS_FAILURE, Jomc.run( new String[ 0 ] ) );
162 }
163
164 @Test
165 public final void testGenerateResources() throws Exception
166 {
167 final File testResourcesDirectory = this.getTestResourcesDirectory();
168 assertTrue( testResourcesDirectory.isAbsolute() );
169
170 if ( testResourcesDirectory.exists() )
171 {
172 FileUtils.deleteDirectory( testResourcesDirectory );
173 }
174
175 final String[] help = new String[]
176 {
177 "generate-resources", "help"
178 };
179
180 final String[] args = new String[]
181 {
182 "generate-resources", "-rd", '"' + this.getTestResourcesDirectory().getAbsolutePath() + '"', "-df",
183 '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-D"
184 };
185
186 final String[] unsupportedOption = new String[]
187 {
188 "generate-resources", "--unsupported-option"
189 };
190
191 final String[] failOnWarnings = new String[]
192 {
193 "generate-resources", "-rd", '"' + this.getTestResourcesDirectory().getAbsolutePath() + '"', "-df",
194 '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-mn", "DOES_NOT_EXIST", "--fail-on-warnings",
195 "-D"
196 };
197
198 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
199 assertEquals( Command.STATUS_FAILURE, Jomc.run( args ) );
200 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
201
202 assertTrue( testResourcesDirectory.mkdirs() );
203 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
204 assertEquals( Command.STATUS_FAILURE, Jomc.run( failOnWarnings ) );
205 }
206
207 @Test
208 public final void testManageSources() throws Exception
209 {
210 final File testSourcesDirectory = this.getTestSourcesDirectory();
211 assertTrue( testSourcesDirectory.isAbsolute() );
212
213 if ( testSourcesDirectory.exists() )
214 {
215 FileUtils.deleteDirectory( testSourcesDirectory );
216 }
217
218 final String[] help = new String[]
219 {
220 "manage-sources", "help"
221 };
222
223 final String[] args = new String[]
224 {
225 "manage-sources", "-sd", '"' + this.getTestSourcesDirectory().getAbsolutePath() + '"', "-df",
226 '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
227 "-D", "-ls", "\r\n", "-idt", "\t", "-tp", "jomc-cli", "-tl",
228 '"' + this.getTemplatesDirectory().getAbsolutePath() + '"'
229 };
230
231 final String[] unsupportedOption = new String[]
232 {
233 "manage-sources", "--unsupported-option"
234 };
235
236 final String[] failOnWarnings = new String[]
237 {
238 "manage-sources", "-sd", '"' + this.getTestSourcesDirectory().getAbsolutePath() + '"', "-df",
239 '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-mn", "DOES_NOT_EXIST", "--fail-on-warnings",
240 "-D", "-tp", "jomc-cli", "-tl", '"' + this.getTemplatesDirectory().getAbsolutePath() + '"'
241 };
242
243 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
244 assertEquals( Command.STATUS_FAILURE, Jomc.run( args ) );
245 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
246
247 assertTrue( testSourcesDirectory.mkdirs() );
248 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
249 assertEquals( Command.STATUS_FAILURE, Jomc.run( failOnWarnings ) );
250 }
251
252 @Test
253 public final void testCommitValidateClasses() throws Exception
254 {
255 final File testClassesDirectory = this.getTestClassesDirectory();
256 assertTrue( testClassesDirectory.isAbsolute() );
257
258 if ( testClassesDirectory.exists() )
259 {
260 FileUtils.deleteDirectory( testClassesDirectory );
261 }
262
263 final String[] commitHelp = new String[]
264 {
265 "commit-classes", "help"
266 };
267
268 final String[] validateHelp = new String[]
269 {
270 "validate-classes", "help"
271 };
272
273 final String[] commitArgs = new String[]
274 {
275 "commit-classes", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-cd",
276 '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-mn",
277 '"' + this.getTestModuleName() + '"', "-D"
278 };
279
280 final String[] commitArgsNoDirectory = new String[]
281 {
282 "commit-classes", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-cd",
283 '"' + this.getTestClassesDirectory().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
284 "-D"
285 };
286
287 final String[] validateArgs = new String[]
288 {
289 "validate-classes", "-cp", '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-D"
290 };
291
292 final String[] validateArgsNonExistentClasses = new String[]
293 {
294 "validate-classes", "-df", '"' + this.getTestModelDocumentNonExistentClasses().getAbsolutePath() + '"',
295 "-cp", '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-D"
296 };
297
298 final String[] commitUnsupportedOption = new String[]
299 {
300 "commit-classes", "--unsupported-option"
301 };
302
303 final String[] validateUnsupportedOption = new String[]
304 {
305 "validate-classes", "--unsupported-option"
306 };
307
308 final String[] commitFailOnWarnings = new String[]
309 {
310 "commit-classes", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-cd",
311 '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-mn", "DOES_NOT_EXIST", "--fail-on-warnings",
312 "-D"
313 };
314
315 final String[] validateFailOnWarnings = new String[]
316 {
317 "validate-classes", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-cp",
318 '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-mn", "DOES_NOT_EXIST", "--fail-on-warnings",
319 "-D"
320 };
321
322 final String[] commitWithStylesheet = new String[]
323 {
324 "commit-classes", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-cd",
325 '"' + this.getClassesDirectory().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
326 "-D", "-stylesheet", '"' + this.getTestModelStylesheet().getAbsolutePath() + '"'
327 };
328
329 assertEquals( Command.STATUS_SUCCESS, Jomc.run( commitHelp ) );
330 assertEquals( Command.STATUS_SUCCESS, Jomc.run( validateHelp ) );
331 assertEquals( Command.STATUS_FAILURE, Jomc.run( commitArgsNoDirectory ) );
332 assertEquals( Command.STATUS_FAILURE, Jomc.run( commitUnsupportedOption ) );
333 assertEquals( Command.STATUS_FAILURE, Jomc.run( validateUnsupportedOption ) );
334
335 assertEquals( Command.STATUS_SUCCESS, Jomc.run( commitArgs ) );
336 assertEquals( Command.STATUS_SUCCESS, Jomc.run( validateArgs ) );
337 assertEquals( Command.STATUS_SUCCESS, Jomc.run( commitWithStylesheet ) );
338 assertEquals( Command.STATUS_FAILURE, Jomc.run( commitFailOnWarnings ) );
339 assertEquals( Command.STATUS_FAILURE, Jomc.run( validateFailOnWarnings ) );
340 assertEquals( Command.STATUS_FAILURE, Jomc.run( validateArgsNonExistentClasses ) );
341 }
342
343 @Test
344 public final void testMergeModules() throws Exception
345 {
346 final ModelContext context = ModelContextFactory.newInstance().newModelContext();
347 final Unmarshaller unmarshaller = context.createUnmarshaller( ModelObject.MODEL_PUBLIC_ID );
348 final Schema schema = context.createSchema( ModelObject.MODEL_PUBLIC_ID );
349 unmarshaller.setSchema( schema );
350
351 final String[] help = new String[]
352 {
353 "merge-modules", "help"
354 };
355
356 final String[] args = new String[]
357 {
358 "merge-modules", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-xs",
359 '"' + this.getTestModelStylesheet().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
360 "-d", '"' + this.getTestModelOutputDocument().getAbsolutePath() + '"', "-D"
361 };
362
363 final String[] includesArg = new String[]
364 {
365 "merge-modules", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-xs",
366 '"' + this.getTestModelStylesheet().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
367 "-d", '"' + this.getTestModelOutputDocument().getAbsolutePath() + '"', "-minc", "\"JOMC CLI\"", "-D"
368 };
369
370 final String[] excludesArg = new String[]
371 {
372 "merge-modules", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-xs",
373 '"' + this.getTestModelStylesheet().getAbsolutePath() + '"', "-mn", '"' + this.getTestModuleName() + '"',
374 "-d", '"' + this.getTestModelOutputDocument().getAbsolutePath() + '"', "-mexc", "\"JOMC CLI\"", "-D"
375 };
376
377 final String[] unsupportedOption = new String[]
378 {
379 "merge-modules", "--unsupported-option"
380 };
381
382 final String[] illegalDoc = new String[]
383 {
384 "merge-modules", "-df", '"' + this.getTestModelDocumentIllegalSchemaConstraints().getAbsolutePath() + '"',
385 "-xs", '"' + this.getTestModelStylesheet().getAbsolutePath() + '"', "-mn",
386 '"' + this.getTestModuleName() + '"', "-d", '"' + this.getTestModelOutputDocument().getAbsolutePath() + '"',
387 "-D"
388 };
389
390 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
391 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
392
393 unmarshaller.unmarshal( new StreamSource( this.getTestModelOutputDocument() ), Module.class );
394
395 assertEquals( Command.STATUS_SUCCESS, Jomc.run( includesArg ) );
396
397 final JAXBElement<Module> includedModule =
398 unmarshaller.unmarshal( new StreamSource( this.getTestModelOutputDocument() ), Module.class );
399
400 assertNotNull( "Merged module does not contain any included specifications.",
401 includedModule.getValue().getSpecifications() );
402
403 assertNotNull( "Merged module does not contain included 'org.jomc.cli.Command' specification.",
404 includedModule.getValue().getSpecifications().getSpecification( Command.class ) );
405
406 assertEquals( Command.STATUS_SUCCESS, Jomc.run( excludesArg ) );
407
408 final JAXBElement<Module> excludedModule =
409 unmarshaller.unmarshal( new StreamSource( this.getTestModelOutputDocument() ), Module.class );
410
411 assertNull( "Merged module contains excluded specifications.",
412 excludedModule.getValue().getSpecifications() );
413
414 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
415 assertEquals( Command.STATUS_FAILURE, Jomc.run( illegalDoc ) );
416 }
417
418 @Test
419 public final void testValidateModel() throws Exception
420 {
421 final String[] help = new String[]
422 {
423 "validate-model", "help"
424 };
425
426 final String[] args = new String[]
427 {
428 "validate-model", "-df", '"' + this.getTestModelDocument().getAbsolutePath() + '"', "-D"
429 };
430
431 final String[] unsupportedOption = new String[]
432 {
433 "validate-model", "--unsupported-option"
434 };
435
436 final String[] illegalDoc = new String[]
437 {
438 "validate-model", "-df", '"' + this.getTestModelDocumentIllegal().getAbsolutePath() + '"', "-D"
439 };
440
441 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
442 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
443 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
444 assertEquals( Command.STATUS_FAILURE, Jomc.run( illegalDoc ) );
445 }
446
447 @Test
448 public final void testMergeModlets() throws Exception
449 {
450 final ModelContext context = ModelContextFactory.newInstance().newModelContext();
451 final Unmarshaller unmarshaller = context.createUnmarshaller( ModletObject.MODEL_PUBLIC_ID );
452 final Schema schema = context.createSchema( ModletObject.MODEL_PUBLIC_ID );
453 unmarshaller.setSchema( schema );
454
455 final String[] help = new String[]
456 {
457 "merge-modlets", "help"
458 };
459
460 final String[] args = new String[]
461 {
462 "merge-modlets", "-xs", '"' + this.getTestModletStylesheet().getAbsolutePath() + '"', "-mdn",
463 '"' + this.getTestModletName() + '"', "-d",
464 '"' + this.getTestModletOutputDocument().getAbsolutePath() + '"', "-cp", "."
465 };
466
467 final String[] includeArgs = new String[]
468 {
469 "merge-modlets", "-xs", '"' + this.getTestModletStylesheet().getAbsolutePath() + '"', "-mdn",
470 '"' + this.getTestModletName() + '"', "-d",
471 '"' + this.getTestModletOutputDocument().getAbsolutePath() + '"', "-mdinc", "JOMC Model", "-cp", "."
472 };
473
474 final String[] excludeArgs = new String[]
475 {
476 "merge-modlets", "-xs", '"' + this.getTestModletStylesheet().getAbsolutePath() + '"', "-mdn",
477 '"' + this.getTestModletName() + '"', "-d",
478 '"' + this.getTestModletOutputDocument().getAbsolutePath() + '"', "-mdexc",
479 "JOMC Model" + File.pathSeparatorChar + "JOMC Tools" + File.pathSeparatorChar + "JOMC Modlet", "-cp", "."
480 };
481
482 final String[] unsupportedOption = new String[]
483 {
484 "merge-modlets", "--unsupported-option"
485 };
486
487 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
488 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
489
490 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
491 Modlet merged = unmarshaller.unmarshal(
492 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
493
494 assertNotNull( merged );
495 assertEquals( this.getTestModletName(), merged.getName() );
496 assertNotNull( merged.getSchemas() );
497 assertNotNull( merged.getServices() );
498 assertEquals( 2, merged.getSchemas().getSchema().size() );
499 assertEquals( 6, merged.getServices().getService().size() );
500 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/model" ) ).isEmpty() );
501 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/tools/model" ) ).isEmpty() );
502 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelProvider" ).size() );
503 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelProcessor" ).size() );
504 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelValidator" ).size() );
505
506 assertEquals( Command.STATUS_SUCCESS, Jomc.run( includeArgs ) );
507 merged = unmarshaller.unmarshal(
508 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
509
510 assertNotNull( merged );
511 assertEquals( this.getTestModletName(), merged.getName() );
512 assertNotNull( merged.getSchemas() );
513 assertNotNull( merged.getServices() );
514 assertEquals( 1, merged.getSchemas().getSchema().size() );
515 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/model" ) ).isEmpty() );
516 assertEquals( 3, merged.getServices().getService().size() );
517 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelProvider" ).size() );
518 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelProcessor" ).size() );
519 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelValidator" ).size() );
520
521 assertEquals( Command.STATUS_SUCCESS, Jomc.run( excludeArgs ) );
522 merged = unmarshaller.unmarshal(
523 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
524
525 assertNotNull( merged );
526 assertEquals( this.getTestModletName(), merged.getName() );
527 assertNull( merged.getSchemas() );
528 assertNull( merged.getServices() );
529 }
530
531 @Test
532 public final void testShowModel() throws Exception
533 {
534 final File classesDirectory = new File( this.getOutputDirectory(), "jomc-test-classes" );
535
536 final String[] help = new String[]
537 {
538 "show-model", "help"
539 };
540
541 final String[] showModel = new String[]
542 {
543 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"'
544 };
545
546 final String[] writeModel = new String[]
547 {
548 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-d",
549 '"' + this.getTestShowModelOutputDocument().getAbsolutePath() + '"'
550 };
551
552 final String[] showSpecification = new String[]
553 {
554 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec", "JOMC CLI Command"
555 };
556
557 final String[] writeSpecification = new String[]
558 {
559 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec", "JOMC CLI Command", "-d",
560 '"' + this.getTestShowSpecificationOutputDocument().getAbsolutePath() + '"'
561 };
562
563 final String[] showInstance = new String[]
564 {
565 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-impl", "JOMC CLI show-model Command"
566 };
567
568 final String[] writeInstance = new String[]
569 {
570 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-impl", "JOMC CLI show-model Command",
571 "-d",
572 '"' + this.getTestShowInstanceOutputDocument().getAbsolutePath() + '"'
573 };
574
575 final String[] showSpecificationAndInstance = new String[]
576 {
577 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec", "JOMC CLI Command", "-impl",
578 "JOMC CLI show-model Command"
579 };
580
581 final String[] writeSpecificationAndInstance = new String[]
582 {
583 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec", "JOMC CLI Command", "-impl",
584 "JOMC CLI show-model Command", "-d",
585 '"' + this.getTestShowSpecificationAndInstanceOutputDocument().getAbsolutePath() + '"'
586 };
587
588 final String[] unsupportedOption = new String[]
589 {
590 "show-model", "--unsupported-option"
591 };
592
593 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
594 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showModel ) );
595 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeModel ) );
596 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showInstance ) );
597 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeInstance ) );
598 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showSpecification ) );
599 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeSpecification ) );
600 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showSpecificationAndInstance ) );
601 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeSpecificationAndInstance ) );
602 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
603 }
604
605 @Before
606 public void setUp() throws IOException
607 {
608
609 ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() );
610
611 final File f = this.getOutputDirectory();
612 if ( !f.exists() )
613 {
614 assertTrue( f.mkdirs() );
615 }
616
617 final File resourcesDirectory = this.getResourcesDirectory();
618 assertTrue( resourcesDirectory.isAbsolute() );
619 FileUtils.deleteDirectory( resourcesDirectory );
620 assertTrue( resourcesDirectory.mkdirs() );
621
622 for ( String testResourceName : TEST_RESOURCE_NAMES )
623 {
624 final URL rsrc = this.getClass().getResource( ABSOLUTE_RESOURCE_NAME_PREFIX + testResourceName );
625 assertNotNull( rsrc );
626 FileUtils.copyURLToFile( rsrc, new File( resourcesDirectory, testResourceName ) );
627 }
628
629 final File classesDirectory = this.getClassesDirectory();
630 this.unzipResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "classfiles.zip", classesDirectory );
631
632 final File templatesDirectory = this.getTemplatesDirectory();
633 this.unzipResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "templates.zip", templatesDirectory );
634 }
635
636 private void unzipResource( final String resourceName, final File targetDirectory ) throws IOException
637 {
638 assertTrue( resourceName.startsWith( "/" ) );
639 final URL resource = this.getClass().getResource( resourceName );
640 assertNotNull( "Expected '" + resourceName + "' not found.", resource );
641
642 assertTrue( targetDirectory.isAbsolute() );
643 FileUtils.deleteDirectory( targetDirectory );
644 assertTrue( targetDirectory.mkdirs() );
645
646 ZipInputStream in = null;
647 boolean suppressExceptionOnClose = true;
648
649 try
650 {
651 in = new ZipInputStream( resource.openStream() );
652 ZipEntry e;
653
654 while ( ( e = in.getNextEntry() ) != null )
655 {
656 if ( e.isDirectory() )
657 {
658 continue;
659 }
660
661 final File dest = new File( targetDirectory, e.getName() );
662 assertTrue( dest.isAbsolute() );
663
664 OutputStream out = null;
665
666 try
667 {
668 out = FileUtils.openOutputStream( dest );
669 IOUtils.copy( in, out );
670 suppressExceptionOnClose = false;
671 }
672 finally
673 {
674 try
675 {
676 if ( out != null )
677 {
678 out.close();
679 }
680
681 suppressExceptionOnClose = true;
682 }
683 catch ( final IOException ex )
684 {
685 if ( !suppressExceptionOnClose )
686 {
687 throw ex;
688 }
689 }
690 }
691
692 in.closeEntry();
693 }
694
695 suppressExceptionOnClose = false;
696 }
697 finally
698 {
699 try
700 {
701 if ( in != null )
702 {
703 in.close();
704 }
705 }
706 catch ( final IOException e )
707 {
708 if ( !suppressExceptionOnClose )
709 {
710 throw e;
711 }
712 }
713 }
714 }
715
716
717
718
719
720 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
721 public JomcTest()
722 {
723
724 super();
725
726 }
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
742 private java.io.File getClassesDirectory()
743 {
744 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "classesDirectory" );
745 assert _p != null : "'classesDirectory' property not found.";
746 return _p;
747 }
748
749
750
751
752
753
754
755
756 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
757 private java.io.File getResourcesDirectory()
758 {
759 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "resourcesDirectory" );
760 assert _p != null : "'resourcesDirectory' property not found.";
761 return _p;
762 }
763
764
765
766
767
768
769
770
771 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
772 private java.io.File getTemplatesDirectory()
773 {
774 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "templatesDirectory" );
775 assert _p != null : "'templatesDirectory' property not found.";
776 return _p;
777 }
778
779
780
781
782
783
784
785
786 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
787 private java.io.File getTestClassesDirectory()
788 {
789 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testClassesDirectory" );
790 assert _p != null : "'testClassesDirectory' property not found.";
791 return _p;
792 }
793
794
795
796
797
798
799
800
801 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
802 private java.io.File getTestModelDocument()
803 {
804 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelDocument" );
805 assert _p != null : "'testModelDocument' property not found.";
806 return _p;
807 }
808
809
810
811
812
813
814
815
816 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
817 private java.io.File getTestModelDocumentIllegal()
818 {
819 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelDocumentIllegal" );
820 assert _p != null : "'testModelDocumentIllegal' property not found.";
821 return _p;
822 }
823
824
825
826
827
828
829
830
831 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
832 private java.io.File getTestModelDocumentIllegalSchemaConstraints()
833 {
834 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelDocumentIllegalSchemaConstraints" );
835 assert _p != null : "'testModelDocumentIllegalSchemaConstraints' property not found.";
836 return _p;
837 }
838
839
840
841
842
843
844
845
846 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
847 private java.io.File getTestModelDocumentNonExistentClasses()
848 {
849 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelDocumentNonExistentClasses" );
850 assert _p != null : "'testModelDocumentNonExistentClasses' property not found.";
851 return _p;
852 }
853
854
855
856
857
858
859
860
861 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
862 private java.io.File getTestModelOutputDocument()
863 {
864 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelOutputDocument" );
865 assert _p != null : "'testModelOutputDocument' property not found.";
866 return _p;
867 }
868
869
870
871
872
873
874
875
876 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
877 private java.io.File getTestModelStylesheet()
878 {
879 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModelStylesheet" );
880 assert _p != null : "'testModelStylesheet' property not found.";
881 return _p;
882 }
883
884
885
886
887
888
889
890
891 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
892 private java.lang.String getTestModletName()
893 {
894 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModletName" );
895 assert _p != null : "'testModletName' property not found.";
896 return _p;
897 }
898
899
900
901
902
903
904
905
906 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
907 private java.io.File getTestModletOutputDocument()
908 {
909 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModletOutputDocument" );
910 assert _p != null : "'testModletOutputDocument' property not found.";
911 return _p;
912 }
913
914
915
916
917
918
919
920
921 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
922 private java.io.File getTestModletStylesheet()
923 {
924 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModletStylesheet" );
925 assert _p != null : "'testModletStylesheet' property not found.";
926 return _p;
927 }
928
929
930
931
932
933
934
935
936 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
937 private java.lang.String getTestModuleName()
938 {
939 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testModuleName" );
940 assert _p != null : "'testModuleName' property not found.";
941 return _p;
942 }
943
944
945
946
947
948
949
950
951 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
952 private java.io.File getTestResourcesDirectory()
953 {
954 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testResourcesDirectory" );
955 assert _p != null : "'testResourcesDirectory' property not found.";
956 return _p;
957 }
958
959
960
961
962
963
964
965
966 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
967 private java.io.File getTestShowInstanceOutputDocument()
968 {
969 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testShowInstanceOutputDocument" );
970 assert _p != null : "'testShowInstanceOutputDocument' property not found.";
971 return _p;
972 }
973
974
975
976
977
978
979
980
981 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
982 private java.io.File getTestShowModelOutputDocument()
983 {
984 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testShowModelOutputDocument" );
985 assert _p != null : "'testShowModelOutputDocument' property not found.";
986 return _p;
987 }
988
989
990
991
992
993
994
995
996 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
997 private java.io.File getTestShowSpecificationAndInstanceOutputDocument()
998 {
999 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testShowSpecificationAndInstanceOutputDocument" );
1000 assert _p != null : "'testShowSpecificationAndInstanceOutputDocument' property not found.";
1001 return _p;
1002 }
1003
1004
1005
1006
1007
1008
1009
1010
1011 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
1012 private java.io.File getTestShowSpecificationOutputDocument()
1013 {
1014 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testShowSpecificationOutputDocument" );
1015 assert _p != null : "'testShowSpecificationOutputDocument' property not found.";
1016 return _p;
1017 }
1018
1019
1020
1021
1022
1023
1024
1025
1026 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.2.2", comments = "See http://jomc.sourceforge.net/jomc/1.2/jomc-tools-1.2.2" )
1027 private java.io.File getTestSourcesDirectory()
1028 {
1029 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "testSourcesDirectory" );
1030 assert _p != null : "'testSourcesDirectory' property not found.";
1031 return _p;
1032 }
1033
1034
1035
1036
1037 }