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.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
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() + '"',
479 "-mdexc=\"JOMC ⁑ Model" + File.pathSeparatorChar + "JOMC ⁑ Tools" + File.pathSeparatorChar
480 + "JOMC ⁑ Modlet\"", "-cp", "."
481 };
482
483 final String[] unsupportedOption = new String[]
484 {
485 "merge-modlets", "--unsupported-option"
486 };
487
488 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
489 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
490
491 assertEquals( Command.STATUS_SUCCESS, Jomc.run( args ) );
492 Modlet merged = unmarshaller.unmarshal(
493 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
494
495 assertNotNull( merged );
496 assertEquals( this.getTestModletName(), merged.getName() );
497 assertNotNull( merged.getSchemas() );
498 assertNotNull( merged.getServices() );
499 assertEquals( 2, merged.getSchemas().getSchema().size() );
500 assertEquals( 6, merged.getServices().getService().size() );
501 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/model" ) ).isEmpty() );
502 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/tools/model" ) ).isEmpty() );
503 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelProvider" ).size() );
504 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelProcessor" ).size() );
505 assertEquals( 2, merged.getServices().getServices( "org.jomc.modlet.ModelValidator" ).size() );
506
507 assertEquals( Command.STATUS_SUCCESS, Jomc.run( includeArgs ) );
508 merged = unmarshaller.unmarshal(
509 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
510
511 assertNotNull( merged );
512 assertEquals( this.getTestModletName(), merged.getName() );
513 assertNotNull( merged.getSchemas() );
514 assertNotNull( merged.getServices() );
515 assertEquals( 1, merged.getSchemas().getSchema().size() );
516 assertFalse( merged.getSchemas().getSchemasByPublicId( new URI( "http://jomc.org/model" ) ).isEmpty() );
517 assertEquals( 3, merged.getServices().getService().size() );
518 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelProvider" ).size() );
519 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelProcessor" ).size() );
520 assertEquals( 1, merged.getServices().getServices( "org.jomc.modlet.ModelValidator" ).size() );
521
522 assertEquals( Command.STATUS_SUCCESS, Jomc.run( excludeArgs ) );
523 merged = unmarshaller.unmarshal(
524 new StreamSource( this.getTestModletOutputDocument() ), Modlet.class ).getValue();
525
526 assertNotNull( merged );
527 assertEquals( this.getTestModletName(), merged.getName() );
528 assertNull( merged.getSchemas() );
529 assertNull( merged.getServices() );
530 }
531
532 @Test
533 public final void testShowModel() throws Exception
534 {
535 final File classesDirectory = new File( this.getOutputDirectory(), "jomc-test-classes" );
536
537 final String[] help = new String[]
538 {
539 "show-model", "help"
540 };
541
542 final String[] showModel = new String[]
543 {
544 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"'
545 };
546
547 final String[] writeModel = new String[]
548 {
549 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-d",
550 '"' + this.getTestShowModelOutputDocument().getAbsolutePath() + '"'
551 };
552
553 final String[] showSpecification = new String[]
554 {
555 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec=\"JOMC ⁑ CLI ⁑ Command\""
556 };
557
558 final String[] writeSpecification = new String[]
559 {
560 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec=\"JOMC ⁑ CLI ⁑ Command\"",
561 "-d", '"' + this.getTestShowSpecificationOutputDocument().getAbsolutePath() + '"'
562 };
563
564 final String[] showInstance = new String[]
565 {
566 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"',
567 "-impl=\"JOMC ⁑ CLI ⁑ Default show-model Command\""
568 };
569
570 final String[] writeInstance = new String[]
571 {
572 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"',
573 "-impl=\"JOMC ⁑ CLI ⁑ Default show-model Command\"",
574 "-d", '"' + this.getTestShowInstanceOutputDocument().getAbsolutePath() + '"'
575 };
576
577 final String[] showSpecificationAndInstance = new String[]
578 {
579 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"', "-spec=\"JOMC ⁑ CLI ⁑ Command\"",
580 "-impl=\"JOMC ⁑ CLI ⁑ Default show-model Command\""
581 };
582
583 final String[] writeSpecificationAndInstance = new String[]
584 {
585 "show-model", "-cp", '"' + classesDirectory.getAbsolutePath() + '"',
586 "-spec=\"JOMC ⁑ CLI ⁑ Command\"",
587 "-impl=\"JOMC ⁑ CLI ⁑ Default show-model Command\"", "-d",
588 '"' + this.getTestShowSpecificationAndInstanceOutputDocument().getAbsolutePath() + '"'
589 };
590
591 final String[] unsupportedOption = new String[]
592 {
593 "show-model", "--unsupported-option"
594 };
595
596 assertEquals( Command.STATUS_SUCCESS, Jomc.run( help ) );
597 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showModel ) );
598 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeModel ) );
599 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showInstance ) );
600 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeInstance ) );
601 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showSpecification ) );
602 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeSpecification ) );
603 assertEquals( Command.STATUS_SUCCESS, Jomc.run( showSpecificationAndInstance ) );
604 assertEquals( Command.STATUS_SUCCESS, Jomc.run( writeSpecificationAndInstance ) );
605 assertEquals( Command.STATUS_FAILURE, Jomc.run( unsupportedOption ) );
606 }
607
608 @Before
609 public void setUp() throws IOException
610 {
611
612 ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() );
613
614 final File f = this.getOutputDirectory();
615 if ( !f.exists() )
616 {
617 assertTrue( f.mkdirs() );
618 }
619
620 final File resourcesDirectory = this.getResourcesDirectory();
621 assertTrue( resourcesDirectory.isAbsolute() );
622 FileUtils.deleteDirectory( resourcesDirectory );
623 assertTrue( resourcesDirectory.mkdirs() );
624
625 for ( String testResourceName : TEST_RESOURCE_NAMES )
626 {
627 final URL rsrc = this.getClass().getResource( ABSOLUTE_RESOURCE_NAME_PREFIX + testResourceName );
628 assertNotNull( rsrc );
629 FileUtils.copyURLToFile( rsrc, new File( resourcesDirectory, testResourceName ) );
630 }
631
632 final File classesDirectory = this.getClassesDirectory();
633 this.unzipResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "classfiles.zip", classesDirectory );
634
635 final File templatesDirectory = this.getTemplatesDirectory();
636 this.unzipResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "templates.zip", templatesDirectory );
637 }
638
639 private void unzipResource( final String resourceName, final File targetDirectory ) throws IOException
640 {
641 assertTrue( resourceName.startsWith( "/" ) );
642 final URL resource = this.getClass().getResource( resourceName );
643 assertNotNull( "Expected '" + resourceName + "' not found.", resource );
644
645 assertTrue( targetDirectory.isAbsolute() );
646 FileUtils.deleteDirectory( targetDirectory );
647 assertTrue( targetDirectory.mkdirs() );
648
649 ZipInputStream in = null;
650 boolean suppressExceptionOnClose = true;
651
652 try
653 {
654 in = new ZipInputStream( resource.openStream() );
655 ZipEntry e;
656
657 while ( ( e = in.getNextEntry() ) != null )
658 {
659 if ( e.isDirectory() )
660 {
661 continue;
662 }
663
664 final File dest = new File( targetDirectory, e.getName() );
665 assertTrue( dest.isAbsolute() );
666
667 OutputStream out = null;
668
669 try
670 {
671 out = FileUtils.openOutputStream( dest );
672 IOUtils.copy( in, out );
673 suppressExceptionOnClose = false;
674 }
675 finally
676 {
677 try
678 {
679 if ( out != null )
680 {
681 out.close();
682 }
683
684 suppressExceptionOnClose = true;
685 }
686 catch ( final IOException ex )
687 {
688 if ( !suppressExceptionOnClose )
689 {
690 throw ex;
691 }
692 }
693 }
694
695 in.closeEntry();
696 }
697
698 suppressExceptionOnClose = false;
699 }
700 finally
701 {
702 try
703 {
704 if ( in != null )
705 {
706 in.close();
707 }
708 }
709 catch ( final IOException e )
710 {
711 if ( !suppressExceptionOnClose )
712 {
713 throw e;
714 }
715 }
716 }
717 }
718
719
720
721
722
723 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
724 public JomcTest()
725 {
726
727 super();
728
729 }
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744 @SuppressWarnings("unused")
745 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
746 private java.io.File getClassesDirectory()
747 {
748 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Classes Directory" );
749 assert _p != null : "'Classes Directory' property not found.";
750 return _p;
751 }
752
753
754
755
756
757
758
759
760 @SuppressWarnings("unused")
761 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
762 private java.io.File getResourcesDirectory()
763 {
764 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Resources Directory" );
765 assert _p != null : "'Resources Directory' property not found.";
766 return _p;
767 }
768
769
770
771
772
773
774
775
776 @SuppressWarnings("unused")
777 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
778 private java.io.File getTemplatesDirectory()
779 {
780 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Templates Directory" );
781 assert _p != null : "'Templates Directory' property not found.";
782 return _p;
783 }
784
785
786
787
788
789
790
791
792 @SuppressWarnings("unused")
793 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
794 private java.io.File getTestClassesDirectory()
795 {
796 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Classes Directory" );
797 assert _p != null : "'Test Classes Directory' property not found.";
798 return _p;
799 }
800
801
802
803
804
805
806
807
808 @SuppressWarnings("unused")
809 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
810 private java.io.File getTestModelDocument()
811 {
812 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Document" );
813 assert _p != null : "'Test Model Document' property not found.";
814 return _p;
815 }
816
817
818
819
820
821
822
823
824 @SuppressWarnings("unused")
825 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
826 private java.io.File getTestModelDocumentIllegal()
827 {
828 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Document Illegal" );
829 assert _p != null : "'Test Model Document Illegal' property not found.";
830 return _p;
831 }
832
833
834
835
836
837
838
839
840 @SuppressWarnings("unused")
841 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
842 private java.io.File getTestModelDocumentIllegalSchemaConstraints()
843 {
844 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Document Illegal Schema Constraints" );
845 assert _p != null : "'Test Model Document Illegal Schema Constraints' property not found.";
846 return _p;
847 }
848
849
850
851
852
853
854
855
856 @SuppressWarnings("unused")
857 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
858 private java.io.File getTestModelDocumentNonExistentClasses()
859 {
860 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Document Non Existent Classes" );
861 assert _p != null : "'Test Model Document Non Existent Classes' property not found.";
862 return _p;
863 }
864
865
866
867
868
869
870
871
872 @SuppressWarnings("unused")
873 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
874 private java.io.File getTestModelOutputDocument()
875 {
876 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Output Document" );
877 assert _p != null : "'Test Model Output Document' property not found.";
878 return _p;
879 }
880
881
882
883
884
885
886
887
888 @SuppressWarnings("unused")
889 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
890 private java.io.File getTestModelStylesheet()
891 {
892 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Model Stylesheet" );
893 assert _p != null : "'Test Model Stylesheet' property not found.";
894 return _p;
895 }
896
897
898
899
900
901
902
903
904 @SuppressWarnings("unused")
905 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
906 private java.lang.String getTestModletName()
907 {
908 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Modlet Name" );
909 assert _p != null : "'Test Modlet Name' property not found.";
910 return _p;
911 }
912
913
914
915
916
917
918
919
920 @SuppressWarnings("unused")
921 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
922 private java.io.File getTestModletOutputDocument()
923 {
924 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Modlet Output Document" );
925 assert _p != null : "'Test Modlet Output Document' property not found.";
926 return _p;
927 }
928
929
930
931
932
933
934
935
936 @SuppressWarnings("unused")
937 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
938 private java.io.File getTestModletStylesheet()
939 {
940 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Modlet Stylesheet" );
941 assert _p != null : "'Test Modlet Stylesheet' property not found.";
942 return _p;
943 }
944
945
946
947
948
949
950
951
952 @SuppressWarnings("unused")
953 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
954 private java.lang.String getTestModuleName()
955 {
956 final java.lang.String _p = (java.lang.String) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Module Name" );
957 assert _p != null : "'Test Module Name' property not found.";
958 return _p;
959 }
960
961
962
963
964
965
966
967
968 @SuppressWarnings("unused")
969 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
970 private java.io.File getTestResourcesDirectory()
971 {
972 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Resources Directory" );
973 assert _p != null : "'Test Resources Directory' property not found.";
974 return _p;
975 }
976
977
978
979
980
981
982
983
984 @SuppressWarnings("unused")
985 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
986 private java.io.File getTestShowInstanceOutputDocument()
987 {
988 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Show Instance Output Document" );
989 assert _p != null : "'Test Show Instance Output Document' property not found.";
990 return _p;
991 }
992
993
994
995
996
997
998
999
1000 @SuppressWarnings("unused")
1001 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
1002 private java.io.File getTestShowModelOutputDocument()
1003 {
1004 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Show Model Output Document" );
1005 assert _p != null : "'Test Show Model Output Document' property not found.";
1006 return _p;
1007 }
1008
1009
1010
1011
1012
1013
1014
1015
1016 @SuppressWarnings("unused")
1017 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
1018 private java.io.File getTestShowSpecificationAndInstanceOutputDocument()
1019 {
1020 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Show Specification And Instance Output Document" );
1021 assert _p != null : "'Test Show Specification And Instance Output Document' property not found.";
1022 return _p;
1023 }
1024
1025
1026
1027
1028
1029
1030
1031
1032 @SuppressWarnings("unused")
1033 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
1034 private java.io.File getTestShowSpecificationOutputDocument()
1035 {
1036 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Show Specification Output Document" );
1037 assert _p != null : "'Test Show Specification Output Document' property not found.";
1038 return _p;
1039 }
1040
1041
1042
1043
1044
1045
1046
1047
1048 @SuppressWarnings("unused")
1049 @javax.annotation.Generated( value = "org.jomc.tools.SourceFileProcessor 1.5", comments = "See http://www.jomc.org/jomc/1.5/jomc-tools-1.5" )
1050 private java.io.File getTestSourcesDirectory()
1051 {
1052 final java.io.File _p = (java.io.File) org.jomc.ObjectManagerFactory.getObjectManager( this.getClass().getClassLoader() ).getProperty( this, "Test Sources Directory" );
1053 assert _p != null : "'Test Sources Directory' property not found.";
1054 return _p;
1055 }
1056
1057
1058
1059
1060 }