1 package org.apache.maven.plugin.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.plugin.war.stub.AarArtifactStub;
25 import org.apache.maven.plugin.war.stub.EJBArtifactStub;
26 import org.apache.maven.plugin.war.stub.EJBArtifactStubWithClassifier;
27 import org.apache.maven.plugin.war.stub.EJBClientArtifactStub;
28 import org.apache.maven.plugin.war.stub.IncludeExcludeWarArtifactStub;
29 import org.apache.maven.plugin.war.stub.JarArtifactStub;
30 import org.apache.maven.plugin.war.stub.MarArtifactStub;
31 import org.apache.maven.plugin.war.stub.MavenProjectArtifactsStub;
32 import org.apache.maven.plugin.war.stub.MavenProjectBasicStub;
33 import org.apache.maven.plugin.war.stub.PARArtifactStub;
34 import org.apache.maven.plugin.war.stub.ResourceStub;
35 import org.apache.maven.plugin.war.stub.TLDArtifactStub;
36 import org.apache.maven.plugin.war.stub.WarArtifactStub;
37 import org.apache.maven.plugin.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(), 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(), 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(), 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(), 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(), 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 public void testExplodedWarMergeWarLocalFileOverride()
274 throws Exception
275 {
276
277 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
278 WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
279
280 String testId = "testExplodedWarMergeWarLocalFileOverride";
281 File webAppDirectory = new File( getTestDirectory(), testId );
282 File webAppSource = getWebAppSource( testId );
283 File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
284 createFile( simpleJSP );
285
286 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
287 createDir( workDirectory );
288
289 File classesDir = createClassesDir( testId, true );
290
291
292 project.addArtifact( warArtifact );
293 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
294 setVariableValueToObject( mojo, "workDirectory", workDirectory );
295 mojo.execute();
296
297
298 File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
299
300 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
301 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
302
303
304 long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
305 simpleJSP.setLastModified( time );
306 expectedFile.setLastModified( time );
307
308 project.addArtifact( warArtifact );
309 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
310 setVariableValueToObject( mojo, "workDirectory", workDirectory );
311 mojo.execute();
312
313 assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
314 assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
315
316
317 expectedFile.delete();
318 }
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 public void testExplodedWar_WithEJB()
379 throws Exception
380 {
381
382 String testId = "ExplodedWar_WithEJB";
383 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
384 File webAppDirectory = new File( getTestDirectory(), testId );
385 File webAppSource = createWebAppSource( testId );
386 File classesDir = createClassesDir( testId, true );
387 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
388 File ejbFile = ejbArtifact.getFile();
389
390 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
391
392
393 project.addArtifact( ejbArtifact );
394 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
395 mojo.execute();
396
397
398 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
399 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
400
401 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
402
403
404 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
405 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
406 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
407
408
409 expectedWebSourceFile.delete();
410 expectedWebSource2File.delete();
411 expectedEJBArtifact.delete();
412 }
413
414 public void testExplodedWarWithJar()
415 throws Exception
416 {
417
418 String testId = "ExplodedWarWithJar";
419 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
420 File webAppDirectory = new File( getTestDirectory(), testId );
421 File webAppSource = createWebAppSource( testId );
422 File classesDir = createClassesDir( testId, true );
423 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
424 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
425 File jarFile = jarArtifact.getFile();
426
427 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
428
429
430 project.addArtifact( jarArtifact );
431 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
432 mojo.execute();
433
434
435 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
436 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
437
438 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" );
439
440 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
441 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
442 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
443
444
445 expectedWebSourceFile.delete();
446 expectedWebSource2File.delete();
447 expectedJarArtifact.delete();
448 }
449
450
451
452
453 public void testExplodedWar_WithEJBClient()
454 throws Exception
455 {
456
457 String testId = "ExplodedWar_WithEJB";
458 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
459 File webAppDirectory = new File( getTestDirectory(), testId );
460 File webAppSource = createWebAppSource( testId );
461 File classesDir = createClassesDir( testId, true );
462 EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() );
463 File ejbFile = ejbArtifact.getFile();
464
465 assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
466
467
468 project.addArtifact( ejbArtifact );
469 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
470 mojo.execute();
471
472
473 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
474 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
475
476 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" );
477
478 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
479 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
480 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
481
482
483 expectedWebSourceFile.delete();
484 expectedWebSource2File.delete();
485 expectedEJBArtifact.delete();
486 }
487
488
489
490
491 public void testExplodedWar_WithTLD()
492 throws Exception
493 {
494
495 String testId = "ExplodedWar_WithTLD";
496 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
497 File webAppDirectory = new File( getTestDirectory(), testId );
498 File webAppSource = createWebAppSource( testId );
499 File classesDir = createClassesDir( testId, true );
500 TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() );
501 File tldFile = tldArtifact.getFile();
502
503 assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() );
504
505
506 project.addArtifact( tldArtifact );
507 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
508 mojo.execute();
509
510
511 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
512 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
513
514 File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" );
515
516 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
517 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
518 assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() );
519
520
521 expectedWebSourceFile.delete();
522 expectedWebSource2File.delete();
523 expectedTLDArtifact.delete();
524 }
525
526
527
528
529 public void testExplodedWar_WithPAR()
530 throws Exception
531 {
532
533 String testId = "ExplodedWar_WithPAR";
534 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
535 File webAppDirectory = new File( getTestDirectory(), testId );
536 File webAppSource = createWebAppSource( testId );
537 File classesDir = createClassesDir( testId, true );
538 PARArtifactStub parartifact = new PARArtifactStub( getBasedir() );
539 File parFile = parartifact.getFile();
540
541 assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() );
542
543
544 project.addArtifact( parartifact );
545 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
546 mojo.execute();
547
548
549 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
550 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
551
552 File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-0.0-Test.jar" );
553
554 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
555 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
556 assertTrue( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() );
557
558
559 expectedWebSourceFile.delete();
560 expectedWebSource2File.delete();
561 expectedPARArtifact.delete();
562 }
563
564 public void testExplodedWarWithAar()
565 throws Exception
566 {
567
568 String testId = "ExplodedWarWithAar";
569 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
570 File webAppDirectory = new File( getTestDirectory(), testId );
571 File webAppSource = createWebAppSource( testId );
572 File classesDir = createClassesDir( testId, true );
573
574 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
575 ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler );
576 File aarFile = aarArtifact.getFile();
577
578 assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() );
579
580
581 project.addArtifact( aarArtifact );
582 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
583 mojo.execute();
584
585
586 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
587 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
588
589 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" );
590
591 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
592 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
593 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
594
595
596 expectedWebSourceFile.delete();
597 expectedWebSource2File.delete();
598 expectedJarArtifact.delete();
599 }
600
601 public void testExplodedWarWithMar()
602 throws Exception
603 {
604
605 String testId = "ExplodedWarWithMar";
606 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
607 File webAppDirectory = new File( getTestDirectory(), testId );
608 File webAppSource = createWebAppSource( testId );
609 File classesDir = createClassesDir( testId, true );
610
611 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
612 ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler );
613 File marFile = marArtifact.getFile();
614
615 assertTrue( "jar not found: " + marFile.toString(), marFile.exists() );
616
617
618 project.addArtifact( marArtifact );
619 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
620 mojo.execute();
621
622
623 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
624 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
625
626 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-0.0-Test.jar" );
627
628 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
629 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
630 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
631
632
633 expectedWebSourceFile.delete();
634 expectedWebSource2File.delete();
635 expectedJarArtifact.delete();
636 }
637
638 public void testExplodedWarWithXar()
639 throws Exception
640 {
641
642 String testId = "ExplodedWarWithXar";
643 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
644 File webAppDirectory = new File( getTestDirectory(), testId );
645 File webAppSource = createWebAppSource( testId );
646 File classesDir = createClassesDir( testId, true );
647
648 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
649 ArtifactStub xarArtifact = new XarArtifactStub( getBasedir(), artifactHandler );
650 File xarFile = xarArtifact.getFile();
651
652 assertTrue( "jar not found: " + xarFile.toString(), xarFile.exists() );
653
654
655 project.addArtifact( xarArtifact );
656 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
657 mojo.execute();
658
659
660 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
661 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
662
663 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar" );
664
665 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
666 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
667 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
668
669
670 expectedWebSourceFile.delete();
671 expectedWebSource2File.delete();
672 expectedJarArtifact.delete();
673 }
674
675
676
677
678 public void testExplodedWar_WithDuplicateDependencies()
679 throws Exception
680 {
681
682 String testId = "ExplodedWar_WithDuplicateDependencies";
683 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
684 File webAppDirectory = new File( getTestDirectory(), testId );
685 File webAppSource = createWebAppSource( testId );
686 File classesDir = createClassesDir( testId, true );
687 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
688 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
689 File ejbFile = ejbArtifact.getFile();
690
691
692 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
693
694
695 ejbArtifact.setGroupId( "org.sample.ejb" );
696 ejbArtifactDup.setGroupId( "org.dup.ejb" );
697 project.addArtifact( ejbArtifact );
698 project.addArtifact( ejbArtifactDup );
699 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
700 mojo.execute();
701
702
703 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
704 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
705
706 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" );
707 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" );
708
709 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
710 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
711 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
712 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
713 expectedEJBDupArtifact.exists() );
714
715
716 expectedWebSourceFile.delete();
717 expectedWebSource2File.delete();
718 expectedEJBArtifact.delete();
719 expectedEJBDupArtifact.delete();
720 }
721
722
723
724
725 public void testExplodedWar_DuplicateWithClassifier()
726 throws Exception
727 {
728
729 String testId = "ExplodedWar_DuplicateWithClassifier";
730 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
731 File webAppDirectory = new File( getTestDirectory(), testId );
732 File webAppSource = createWebAppSource( testId );
733 File classesDir = createClassesDir( testId, true );
734 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
735 EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
736
737 File ejbFile = ejbArtifact.getFile();
738
739
740 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
741
742
743
744 ejbArtifact.setGroupId( "org.sample.ejb" );
745 ejbArtifactDup.setGroupId( "org.sample.ejb" );
746
747 ejbArtifactDup.setClassifier( "classifier" );
748
749 project.addArtifact( ejbArtifact );
750 project.addArtifact( ejbArtifactDup );
751
752 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
753 mojo.execute();
754
755
756 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
757 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
758
759 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
760 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
761
762 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
763 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
764 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
765 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
766 expectedEJBDupArtifact.exists() );
767
768
769 expectedWebSourceFile.delete();
770 expectedWebSource2File.delete();
771 expectedEJBArtifact.delete();
772 expectedEJBDupArtifact.delete();
773 }
774
775
776
777
778 public void testExplodedWar_WithClasses()
779 throws Exception
780 {
781
782 String testId = "ExplodedWar_WithClasses";
783 MavenProjectBasicStub project = new MavenProjectBasicStub();
784 File webAppDirectory = new File( getTestDirectory(), testId );
785 File webAppSource = createWebAppSource( testId );
786 File classesDir = createClassesDir( testId, false );
787
788
789 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
790 mojo.execute();
791
792
793 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
794 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
795
796 File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
797
798 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
799 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
800 assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
801
802
803 expectedWebSourceFile.delete();
804 expectedWebSource2File.delete();
805 expectedClass.delete();
806 }
807
808 public void testExplodedWar_WithSourceIncludeExclude()
809 throws Exception
810 {
811
812 String testId = "ExplodedWar_WithSourceIncludeExclude";
813 MavenProjectBasicStub project = new MavenProjectBasicStub();
814 File webAppSource = createWebAppSource( testId );
815 File classesDir = createClassesDir( testId, true );
816 File webAppDirectory = new File( getTestDirectory(), testId );
817
818
819 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
820 setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
821 setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
822 mojo.execute();
823
824
825 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
826 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
827 File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
828 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
829
830 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
831 assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
832 assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
833 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
834
835
836 expectedWebSourceFile.delete();
837 expectedWebSource2File.delete();
838 expectedWEBXMLDir.delete();
839 expectedMETAINFDir.delete();
840 }
841
842 public void testExplodedWar_WithWarDependencyIncludeExclude()
843 throws Exception
844 {
845
846 String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
847 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
848 IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
849 File webAppDirectory = new File( getTestDirectory(), testId );
850 File webAppSource = createWebAppSource( testId );
851 File classesDir = createClassesDir( testId, true );
852 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
853 File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
854
855 assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
856
857 createDir( workDirectory );
858
859
860 project.addArtifact( includeexcludeWarArtifact );
861 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
862 setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
863 setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
864 setVariableValueToObject( mojo, "workDirectory", workDirectory );
865 mojo.execute();
866
867
868 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
869 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
870 File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
871 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
872 File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
873 File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
874
875 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
876 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
877
878 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
879 assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
880 assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
881 assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
882
883
884 expectedWebSourceFile.delete();
885 expectedWebSource2File.delete();
886 expectedManifestFile.delete();
887 expectedWEBXMLFile.delete();
888 expectedIncludedWARFile.delete();
889 expectedExcludedWarfile.delete();
890 }
891
892 public void testExplodedWarWithSourceModificationCheck()
893 throws Exception
894 {
895
896 String testId = "ExplodedWarWithSourceModificationCheck";
897 MavenProjectBasicStub project = new MavenProjectBasicStub();
898 File webAppSource = createWebAppSource( testId );
899 File classesDir = createClassesDir( testId, false );
900 File webAppDirectory = new File( getTestDirectory(), testId );
901
902
903 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
904
905
906
907 mojo.execute();
908
909
910
911 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
912 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
913 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
914 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
915
916 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
917 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
918 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
919 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
920
921
922
923 assertFalse( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
924 "error".equals( FileUtils.fileRead( expectedWebSourceFile ) ) );
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939 expectedWEBINFDir.delete();
940 expectedMETAINFDir.delete();
941 expectedWebSourceFile.delete();
942 expectedWebSource2File.delete();
943 }
944
945 public void testExplodedWarWithOutputFileNameMapping()
946 throws Exception
947 {
948
949 String testId = "ExplodedWarWithFileNameMapping";
950 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
951 File webAppDirectory = new File( getTestDirectory(), testId );
952 File webAppSource = createWebAppSource( testId );
953 File classesDir = createClassesDir( testId, true );
954 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
955 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
956 File jarFile = jarArtifact.getFile();
957
958 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
959
960
961 project.addArtifact( jarArtifact );
962 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
963 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
964 mojo.execute();
965
966
967 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
968 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
969
970 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
971
972 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
973 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
974 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
975
976
977 expectedWebSourceFile.delete();
978 expectedWebSource2File.delete();
979 expectedJarArtifact.delete();
980 }
981
982
983
984
985 public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
986 throws Exception
987 {
988
989 String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
990 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
991 File webAppDirectory = new File( getTestDirectory(), testId );
992 File webAppSource = createWebAppSource( testId );
993 File classesDir = createClassesDir( testId, true );
994 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
995 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
996 File ejbFile = ejbArtifact.getFile();
997
998
999 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
1000
1001
1002 ejbArtifact.setGroupId( "org.sample.ejb" );
1003 ejbArtifactDup.setGroupId( "org.dup.ejb" );
1004 project.addArtifact( ejbArtifact );
1005 project.addArtifact( ejbArtifactDup );
1006 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
1007 this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
1008 mojo.execute();
1009
1010
1011 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
1012 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
1013
1014 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
1015 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
1016
1017 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
1018 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
1019 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
1020 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(),
1021 expectedEJBDupArtifact.exists() );
1022
1023
1024 expectedWebSourceFile.delete();
1025 expectedWebSource2File.delete();
1026 expectedEJBArtifact.delete();
1027 expectedEJBDupArtifact.delete();
1028 }
1029
1030
1031
1032
1033
1034
1035 }