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