1 package org.apache.maven.plugins.war;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.artifact.handler.ArtifactHandler;
23 import org.apache.maven.plugin.testing.stubs.ArtifactStub;
24 import org.apache.maven.plugins.war.stub.AarArtifactStub;
25 import org.apache.maven.plugins.war.stub.EJBArtifactStub;
26 import org.apache.maven.plugins.war.stub.EJBArtifactStubWithClassifier;
27 import org.apache.maven.plugins.war.stub.EJBClientArtifactStub;
28 import org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub;
29 import org.apache.maven.plugins.war.stub.JarArtifactStub;
30 import org.apache.maven.plugins.war.stub.MarArtifactStub;
31 import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub;
32 import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
33 import org.apache.maven.plugins.war.stub.PARArtifactStub;
34 import org.apache.maven.plugins.war.stub.ResourceStub;
35 import org.apache.maven.plugins.war.stub.TLDArtifactStub;
36 import org.apache.maven.plugins.war.stub.WarArtifactStub;
37 import org.apache.maven.plugins.war.stub.XarArtifactStub;
38 import org.codehaus.plexus.util.FileUtils;
39
40 import java.io.File;
41 import java.text.SimpleDateFormat;
42 import java.util.LinkedList;
43 import java.util.Locale;
44
45 public class WarExplodedMojoTest
46 extends AbstractWarExplodedMojoTest
47 {
48
49 protected File getPomFile()
50 {
51 return new File( getBasedir(), "/target/test-classes/unit/warexplodedmojo/plugin-config.xml" );
52 }
53
54 protected File getTestDirectory()
55 {
56 return new File( getBasedir(), "target/test-classes/unit/warexplodedmojo/test-dir" );
57 }
58
59
60
61
62 public void testSimpleExplodedWar()
63 throws Exception
64 {
65
66 String testId = "SimpleExplodedWar";
67 MavenProjectBasicStub project = new MavenProjectBasicStub();
68 File webAppSource = createWebAppSource( testId );
69 File classesDir = createClassesDir( testId, false );
70 File webAppResource = new File( getTestDirectory(), testId + "-resources" );
71 File webAppDirectory = new File( getTestDirectory(), testId );
72 File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
73 ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
74
75 createFile( sampleResource );
76
77 assertTrue( "sampeResource not found", sampleResource.exists() );
78
79
80 resources[0].setDirectory( webAppResource.getAbsolutePath() );
81 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
82 setVariableValueToObject( mojo, "webResources", resources );
83 mojo.execute();
84
85
86 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
87 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
88 File expectedWebResourceFile = new File( webAppDirectory, "pix/panis_na.jpg" );
89 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
90 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
91
92 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
93 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
94 assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
95 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
96 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
97
98
99 expectedWebSourceFile.delete();
100 expectedWebSource2File.delete();
101 expectedWebResourceFile.delete();
102 }
103
104
105
106
107 public void testSimpleExplodedWarWTargetPath()
108 throws Exception
109 {
110
111 String testId = "SimpleExplodedWar";
112 MavenProjectBasicStub project = new MavenProjectBasicStub();
113 File webAppSource = createWebAppSource( testId );
114 File classesDir = createClassesDir( testId, false );
115 File webAppResource = new File( getTestDirectory(), "resources" );
116 File webAppDirectory = new File( getTestDirectory(), testId );
117 File sampleResource = new File( webAppResource, "pix/panis_na.jpg" );
118 ResourceStub[] resources = new ResourceStub[] { new ResourceStub() };
119
120 createFile( sampleResource );
121
122
123 resources[0].setDirectory( webAppResource.getAbsolutePath() );
124 resources[0].setTargetPath( "targetPath" );
125 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
126 setVariableValueToObject( mojo, "webResources", resources );
127 mojo.execute();
128
129
130 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
131 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
132 File expectedWebResourceFile = new File( webAppDirectory, "targetPath/pix/panis_na.jpg" );
133 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
134 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
135
136 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
137 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
138 assertTrue( "resources doesn't exist: " + expectedWebResourceFile, expectedWebResourceFile.exists() );
139 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
140 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
141
142
143 expectedWebSourceFile.delete();
144 expectedWebSource2File.delete();
145 expectedWebResourceFile.delete();
146 }
147
148
149
150
151 public void testExplodedWar_WithCustomWebXML()
152 throws Exception
153 {
154
155 String testId = "ExplodedWar_WithCustomWebXML";
156 MavenProjectBasicStub project = new MavenProjectBasicStub();
157 File webAppSource = createWebAppSource( testId );
158 File classesDir = createClassesDir( testId, true );
159 File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
160 File webAppDirectory = new File( getTestDirectory(), testId );
161
162
163 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
164 mojo.setWebXml( new File( xmlSource, "web.xml" ) );
165 mojo.execute();
166
167
168 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
169 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
170 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
171 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
172
173 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
174 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
175 assertTrue( "WEB XML not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
176 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
177 assertEquals( "WEB XML not correct", mojo.getWebXml().toString(), FileUtils.fileRead( expectedWEBXMLFile ) );
178
179
180 expectedWebSourceFile.delete();
181 expectedWebSource2File.delete();
182 expectedWEBXMLFile.delete();
183 expectedMETAINFDir.delete();
184 }
185
186
187
188
189 public void testExplodedWar_WithContainerConfigXML()
190 throws Exception
191 {
192
193 String testId = "ExplodedWar_WithContainerConfigXML";
194 MavenProjectBasicStub project = new MavenProjectBasicStub();
195 File classesDir = createClassesDir( testId, true );
196 File webAppSource = createWebAppSource( testId );
197 File xmlSource = createXMLConfigDir( testId, new String[] { "config.xml" } );
198 File webAppDirectory = new File( getTestDirectory(), testId );
199
200
201 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
202 mojo.setContainerConfigXML( new File( xmlSource, "config.xml" ) );
203 mojo.execute();
204
205
206 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
207 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
208 File expectedContainerConfigXMLFile = new File( webAppDirectory, "META-INF/config.xml" );
209 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
210
211 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
212 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
213 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
214 assertTrue( "Container Config XML not found:" + expectedContainerConfigXMLFile.toString(),
215 expectedContainerConfigXMLFile.exists() );
216
217
218 expectedWebSourceFile.delete();
219 expectedWebSource2File.delete();
220 expectedContainerConfigXMLFile.delete();
221 expectedWEBINFDir.delete();
222 }
223
224
225
226
227 public void testExplodedWar_WithSimpleExternalWARFile()
228 throws Exception
229 {
230
231 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
232 WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
233
234 String testId = "ExplodedWar_WithSimpleExternalWARFile";
235 File webAppDirectory = new File( getTestDirectory(), testId );
236 File webAppSource = createWebAppSource( testId );
237 File classesDir = createClassesDir( testId, true );
238 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
239 File simpleWarFile = warArtifact.getFile();
240
241 assertTrue( "simple war not found: " + simpleWarFile.toString(), simpleWarFile.exists() );
242
243 createDir( workDirectory );
244
245
246 project.addArtifact( warArtifact );
247 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
248 setVariableValueToObject( mojo, "workDirectory", workDirectory );
249 mojo.execute();
250
251
252 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
253 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
254 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
255 File expectedWARFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
256
257 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
258 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
259
260 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
261 assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() );
262
263
264 expectedWebSourceFile.delete();
265 expectedWebSource2File.delete();
266 expectedWEBXMLFile.delete();
267 expectedWARFile.delete();
268 }
269
270
271
272
273
274 public void testExplodedWarMergeWarLocalFileOverride()
275 throws Exception
276 {
277
278 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
279 WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
280
281 String testId = "testExplodedWarMergeWarLocalFileOverride";
282 File webAppDirectory = new File( getTestDirectory(), testId );
283 File webAppSource = getWebAppSource( testId );
284 File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
285 createFile( simpleJSP );
286
287 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
288 createDir( workDirectory );
289
290 File classesDir = createClassesDir( testId, true );
291
292
293 project.addArtifact( warArtifact );
294 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
295 setVariableValueToObject( mojo, "workDirectory", workDirectory );
296 mojo.execute();
297
298
299 File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
300
301 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
302 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
303
304
305 long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
306 simpleJSP.setLastModified( time );
307 expectedFile.setLastModified( time );
308
309 project.addArtifact( warArtifact );
310 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
311 setVariableValueToObject( mojo, "workDirectory", workDirectory );
312 mojo.execute();
313
314 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
315 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
316
317
318 expectedFile.delete();
319 }
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379 public void testExplodedWar_WithEJB()
380 throws Exception
381 {
382
383 String testId = "ExplodedWar_WithEJB";
384 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
385 File webAppDirectory = new File( getTestDirectory(), testId );
386 File webAppSource = createWebAppSource( testId );
387 File classesDir = createClassesDir( testId, true );
388 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
389 File ejbFile = ejbArtifact.getFile();
390
391 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
392
393
394 project.addArtifact( ejbArtifact );
395 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
396 mojo.execute();
397
398
399 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
400 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
401
402 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
403
404
405 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
406 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
407 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
408
409
410 expectedWebSourceFile.delete();
411 expectedWebSource2File.delete();
412 expectedEJBArtifact.delete();
413 }
414
415 public void testExplodedWarWithJar()
416 throws Exception
417 {
418
419 String testId = "ExplodedWarWithJar";
420 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
421 File webAppDirectory = new File( getTestDirectory(), testId );
422 File webAppSource = createWebAppSource( testId );
423 File classesDir = createClassesDir( testId, true );
424 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
425 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
426 File jarFile = jarArtifact.getFile();
427
428 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
429
430
431 project.addArtifact( jarArtifact );
432 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
433 mojo.execute();
434
435
436 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
437 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
438
439 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" );
440
441 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
442 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
443 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
444
445
446 expectedWebSourceFile.delete();
447 expectedWebSource2File.delete();
448 expectedJarArtifact.delete();
449 }
450
451
452
453
454 public void testExplodedWar_WithEJBClient()
455 throws Exception
456 {
457
458 String testId = "ExplodedWar_WithEJB";
459 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
460 File webAppDirectory = new File( getTestDirectory(), testId );
461 File webAppSource = createWebAppSource( testId );
462 File classesDir = createClassesDir( testId, true );
463 EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() );
464 File ejbFile = ejbArtifact.getFile();
465
466 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
467
468
469 project.addArtifact( ejbArtifact );
470 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
471 mojo.execute();
472
473
474 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
475 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
476
477 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" );
478
479 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
480 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
481 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
482
483
484 expectedWebSourceFile.delete();
485 expectedWebSource2File.delete();
486 expectedEJBArtifact.delete();
487 }
488
489
490
491
492 public void testExplodedWar_WithTLD()
493 throws Exception
494 {
495
496 String testId = "ExplodedWar_WithTLD";
497 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
498 File webAppDirectory = new File( getTestDirectory(), testId );
499 File webAppSource = createWebAppSource( testId );
500 File classesDir = createClassesDir( testId, true );
501 TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() );
502 File tldFile = tldArtifact.getFile();
503
504 assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() );
505
506
507 project.addArtifact( tldArtifact );
508 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
509 mojo.execute();
510
511
512 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
513 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
514
515 File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" );
516
517 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
518 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
519 assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() );
520
521
522 expectedWebSourceFile.delete();
523 expectedWebSource2File.delete();
524 expectedTLDArtifact.delete();
525 }
526
527
528
529
530 public void testExplodedWar_WithPAR()
531 throws Exception
532 {
533
534 String testId = "ExplodedWar_WithPAR";
535 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
536 File webAppDirectory = new File( getTestDirectory(), testId );
537 File webAppSource = createWebAppSource( testId );
538 File classesDir = createClassesDir( testId, true );
539 PARArtifactStub parartifact = new PARArtifactStub( getBasedir() );
540 File parFile = parartifact.getFile();
541
542 assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() );
543
544
545 project.addArtifact( parartifact );
546 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
547 mojo.execute();
548
549
550 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
551 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
552
553 File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar" );
554
555 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
556 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
557 assertTrue( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() );
558
559
560 expectedWebSourceFile.delete();
561 expectedWebSource2File.delete();
562 expectedPARArtifact.delete();
563 }
564
565
566
567
568 public void testExplodedWarWithAar()
569 throws Exception
570 {
571
572 String testId = "ExplodedWarWithAar";
573 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
574 File webAppDirectory = new File( getTestDirectory(), testId );
575 File webAppSource = createWebAppSource( testId );
576 File classesDir = createClassesDir( testId, true );
577
578 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
579 ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler );
580 File aarFile = aarArtifact.getFile();
581
582 assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() );
583
584
585 project.addArtifact( aarArtifact );
586 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
587 mojo.execute();
588
589
590 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
591 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
592
593 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" );
594
595 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
596 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
597 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
598
599
600 expectedWebSourceFile.delete();
601 expectedWebSource2File.delete();
602 expectedJarArtifact.delete();
603 }
604
605
606
607
608 public void testExplodedWarWithMar()
609 throws Exception
610 {
611
612 String testId = "ExplodedWarWithMar";
613 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
614 File webAppDirectory = new File( getTestDirectory(), testId );
615 File webAppSource = createWebAppSource( testId );
616 File classesDir = createClassesDir( testId, true );
617
618 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
619 ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler );
620 File marFile = marArtifact.getFile();
621
622 assertTrue( "jar not found: " + marFile.toString(), marFile.exists() );
623
624
625 project.addArtifact( marArtifact );
626 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
627 mojo.execute();
628
629
630 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
631 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
632
633 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar" );
634
635 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
636 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
637 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
638
639
640 expectedWebSourceFile.delete();
641 expectedWebSource2File.delete();
642 expectedJarArtifact.delete();
643 }
644
645
646
647
648 public void testExplodedWarWithXar()
649 throws Exception
650 {
651
652 String testId = "ExplodedWarWithXar";
653 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
654 File webAppDirectory = new File( getTestDirectory(), testId );
655 File webAppSource = createWebAppSource( testId );
656 File classesDir = createClassesDir( testId, true );
657
658 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
659 ArtifactStub xarArtifact = new XarArtifactStub( getBasedir(), artifactHandler );
660 File xarFile = xarArtifact.getFile();
661
662 assertTrue( "jar not found: " + xarFile.toString(), xarFile.exists() );
663
664
665 project.addArtifact( xarArtifact );
666 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
667 mojo.execute();
668
669
670 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
671 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
672
673 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar" );
674
675 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
676 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
677 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
678
679
680 expectedWebSourceFile.delete();
681 expectedWebSource2File.delete();
682 expectedJarArtifact.delete();
683 }
684
685
686
687
688 public void testExplodedWar_WithDuplicateDependencies()
689 throws Exception
690 {
691
692 String testId = "ExplodedWar_WithDuplicateDependencies";
693 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
694 File webAppDirectory = new File( getTestDirectory(), testId );
695 File webAppSource = createWebAppSource( testId );
696 File classesDir = createClassesDir( testId, true );
697 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
698 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
699 File ejbFile = ejbArtifact.getFile();
700
701
702 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
703
704
705 ejbArtifact.setGroupId( "org.sample.ejb" );
706 ejbArtifactDup.setGroupId( "org.dup.ejb" );
707 project.addArtifact( ejbArtifact );
708 project.addArtifact( ejbArtifactDup );
709 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
710 mojo.execute();
711
712
713 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
714 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
715
716 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" );
717 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" );
718
719 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
720 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
721 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
722 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
723
724
725 expectedWebSourceFile.delete();
726 expectedWebSource2File.delete();
727 expectedEJBArtifact.delete();
728 expectedEJBDupArtifact.delete();
729 }
730
731
732
733
734 public void testExplodedWar_DuplicateWithClassifier()
735 throws Exception
736 {
737
738 String testId = "ExplodedWar_DuplicateWithClassifier";
739 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
740 File webAppDirectory = new File( getTestDirectory(), testId );
741 File webAppSource = createWebAppSource( testId );
742 File classesDir = createClassesDir( testId, true );
743 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
744 EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
745
746 File ejbFile = ejbArtifact.getFile();
747
748
749 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
750
751
752
753 ejbArtifact.setGroupId( "org.sample.ejb" );
754 ejbArtifactDup.setGroupId( "org.sample.ejb" );
755
756 ejbArtifactDup.setClassifier( "classifier" );
757
758 project.addArtifact( ejbArtifact );
759 project.addArtifact( ejbArtifactDup );
760
761 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
762 mojo.execute();
763
764
765 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
766 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
767
768 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
769 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
770
771 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
772 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
773 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
774 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
775
776
777 expectedWebSourceFile.delete();
778 expectedWebSource2File.delete();
779 expectedEJBArtifact.delete();
780 expectedEJBDupArtifact.delete();
781 }
782
783
784
785
786 public void testExplodedWar_WithClasses()
787 throws Exception
788 {
789
790 String testId = "ExplodedWar_WithClasses";
791 MavenProjectBasicStub project = new MavenProjectBasicStub();
792 File webAppDirectory = new File( getTestDirectory(), testId );
793 File webAppSource = createWebAppSource( testId );
794 File classesDir = createClassesDir( testId, false );
795
796
797 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
798 mojo.execute();
799
800
801 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
802 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
803
804 File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
805
806 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
807 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
808 assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
809
810
811 expectedWebSourceFile.delete();
812 expectedWebSource2File.delete();
813 expectedClass.delete();
814 }
815
816
817
818
819 public void testExplodedWar_WithSourceIncludeExclude()
820 throws Exception
821 {
822
823 String testId = "ExplodedWar_WithSourceIncludeExclude";
824 MavenProjectBasicStub project = new MavenProjectBasicStub();
825 File webAppSource = createWebAppSource( testId );
826 File classesDir = createClassesDir( testId, true );
827 File webAppDirectory = new File( getTestDirectory(), testId );
828
829
830 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
831 setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
832 setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
833 mojo.execute();
834
835
836 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
837 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
838 File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
839 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
840
841 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
842 assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
843 assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
844 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
845
846
847 expectedWebSourceFile.delete();
848 expectedWebSource2File.delete();
849 expectedWEBXMLDir.delete();
850 expectedMETAINFDir.delete();
851 }
852
853
854
855
856 public void testExplodedWar_WithWarDependencyIncludeExclude()
857 throws Exception
858 {
859
860 String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
861 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
862 IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
863 File webAppDirectory = new File( getTestDirectory(), testId );
864 File webAppSource = createWebAppSource( testId );
865 File classesDir = createClassesDir( testId, true );
866 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
867 File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
868
869 assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
870
871 createDir( workDirectory );
872
873
874 project.addArtifact( includeexcludeWarArtifact );
875 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
876 setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
877 setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
878 setVariableValueToObject( mojo, "workDirectory", workDirectory );
879 mojo.execute();
880
881
882 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
883 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
884 File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
885 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
886 File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
887 File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
888
889 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
890 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
891
892 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
893 assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
894 assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
895 assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
896
897
898 expectedWebSourceFile.delete();
899 expectedWebSource2File.delete();
900 expectedManifestFile.delete();
901 expectedWEBXMLFile.delete();
902 expectedIncludedWARFile.delete();
903 expectedExcludedWarfile.delete();
904 }
905
906
907
908
909 public void testExplodedWarWithSourceModificationCheck()
910 throws Exception
911 {
912
913 String testId = "ExplodedWarWithSourceModificationCheck";
914 MavenProjectBasicStub project = new MavenProjectBasicStub();
915 File webAppSource = createWebAppSource( testId );
916 File classesDir = createClassesDir( testId, false );
917 File webAppDirectory = new File( getTestDirectory(), testId );
918
919
920 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
921
922
923
924 mojo.execute();
925
926
927
928 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
929 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
930 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
931 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
932
933 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
934 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
935 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
936 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
937
938
939
940 assertFalse( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
941 "error".equals( FileUtils.fileRead( expectedWebSourceFile ) ) );
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956 expectedWEBINFDir.delete();
957 expectedMETAINFDir.delete();
958 expectedWebSourceFile.delete();
959 expectedWebSource2File.delete();
960 }
961
962
963
964
965 public void testExplodedWarWithOutputFileNameMapping()
966 throws Exception
967 {
968
969 String testId = "ExplodedWarWithFileNameMapping";
970 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
971 File webAppDirectory = new File( getTestDirectory(), testId );
972 File webAppSource = createWebAppSource( testId );
973 File classesDir = createClassesDir( testId, true );
974 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
975 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
976 File jarFile = jarArtifact.getFile();
977
978 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
979
980
981 project.addArtifact( jarArtifact );
982 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
983 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
984 mojo.execute();
985
986
987 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
988 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
989
990 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
991
992 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
993 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
994 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
995
996
997 expectedWebSourceFile.delete();
998 expectedWebSource2File.delete();
999 expectedJarArtifact.delete();
1000 }
1001
1002
1003
1004
1005 public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
1006 throws Exception
1007 {
1008
1009 String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
1010 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
1011 File webAppDirectory = new File( getTestDirectory(), testId );
1012 File webAppSource = createWebAppSource( testId );
1013 File classesDir = createClassesDir( testId, true );
1014 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
1015 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
1016 File ejbFile = ejbArtifact.getFile();
1017
1018
1019 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
1020
1021
1022 ejbArtifact.setGroupId( "org.sample.ejb" );
1023 ejbArtifactDup.setGroupId( "org.dup.ejb" );
1024 project.addArtifact( ejbArtifact );
1025 project.addArtifact( ejbArtifactDup );
1026 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
1027 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
1028 mojo.execute();
1029
1030
1031 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
1032 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
1033
1034 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
1035 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
1036
1037 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
1038 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
1039 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
1040 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
1041
1042
1043 expectedWebSourceFile.delete();
1044 expectedWebSource2File.delete();
1045 expectedEJBArtifact.delete();
1046 expectedEJBDupArtifact.delete();
1047 }
1048
1049
1050
1051
1052
1053 }