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<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 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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<String>(), 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(), expectedEJBDupArtifact.exists() );
713
714
715 expectedWebSourceFile.delete();
716 expectedWebSource2File.delete();
717 expectedEJBArtifact.delete();
718 expectedEJBDupArtifact.delete();
719 }
720
721
722
723
724 public void testExplodedWar_DuplicateWithClassifier()
725 throws Exception
726 {
727
728 String testId = "ExplodedWar_DuplicateWithClassifier";
729 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
730 File webAppDirectory = new File( getTestDirectory(), testId );
731 File webAppSource = createWebAppSource( testId );
732 File classesDir = createClassesDir( testId, true );
733 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
734 EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
735
736 File ejbFile = ejbArtifact.getFile();
737
738
739 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
740
741
742
743 ejbArtifact.setGroupId( "org.sample.ejb" );
744 ejbArtifactDup.setGroupId( "org.sample.ejb" );
745
746 ejbArtifactDup.setClassifier( "classifier" );
747
748 project.addArtifact( ejbArtifact );
749 project.addArtifact( ejbArtifactDup );
750
751 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
752 mojo.execute();
753
754
755 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
756 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
757
758 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
759 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
760
761 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
762 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
763 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
764 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
765
766
767 expectedWebSourceFile.delete();
768 expectedWebSource2File.delete();
769 expectedEJBArtifact.delete();
770 expectedEJBDupArtifact.delete();
771 }
772
773
774
775
776 public void testExplodedWar_WithClasses()
777 throws Exception
778 {
779
780 String testId = "ExplodedWar_WithClasses";
781 MavenProjectBasicStub project = new MavenProjectBasicStub();
782 File webAppDirectory = new File( getTestDirectory(), testId );
783 File webAppSource = createWebAppSource( testId );
784 File classesDir = createClassesDir( testId, false );
785
786
787 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
788 mojo.execute();
789
790
791 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
792 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
793
794 File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
795
796 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
797 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
798 assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
799
800
801 expectedWebSourceFile.delete();
802 expectedWebSource2File.delete();
803 expectedClass.delete();
804 }
805
806 public void testExplodedWar_WithSourceIncludeExclude()
807 throws Exception
808 {
809
810 String testId = "ExplodedWar_WithSourceIncludeExclude";
811 MavenProjectBasicStub project = new MavenProjectBasicStub();
812 File webAppSource = createWebAppSource( testId );
813 File classesDir = createClassesDir( testId, true );
814 File webAppDirectory = new File( getTestDirectory(), testId );
815
816
817 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
818 setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
819 setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
820 mojo.execute();
821
822
823 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
824 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
825 File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
826 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
827
828 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
829 assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
830 assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
831 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
832
833
834 expectedWebSourceFile.delete();
835 expectedWebSource2File.delete();
836 expectedWEBXMLDir.delete();
837 expectedMETAINFDir.delete();
838 }
839
840 public void testExplodedWar_WithWarDependencyIncludeExclude()
841 throws Exception
842 {
843
844 String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
845 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
846 IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
847 File webAppDirectory = new File( getTestDirectory(), testId );
848 File webAppSource = createWebAppSource( testId );
849 File classesDir = createClassesDir( testId, true );
850 File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
851 File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
852
853 assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
854
855 createDir( workDirectory );
856
857
858 project.addArtifact( includeexcludeWarArtifact );
859 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
860 setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
861 setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
862 setVariableValueToObject( mojo, "workDirectory", workDirectory );
863 mojo.execute();
864
865
866 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
867 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
868 File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
869 File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
870 File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
871 File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
872
873 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
874 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
875
876 assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
877 assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
878 assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
879 assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
880
881
882 expectedWebSourceFile.delete();
883 expectedWebSource2File.delete();
884 expectedManifestFile.delete();
885 expectedWEBXMLFile.delete();
886 expectedIncludedWARFile.delete();
887 expectedExcludedWarfile.delete();
888 }
889
890 public void testExplodedWarWithSourceModificationCheck()
891 throws Exception
892 {
893
894 String testId = "ExplodedWarWithSourceModificationCheck";
895 MavenProjectBasicStub project = new MavenProjectBasicStub();
896 File webAppSource = createWebAppSource( testId );
897 File classesDir = createClassesDir( testId, false );
898 File webAppDirectory = new File( getTestDirectory(), testId );
899
900
901 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
902
903
904
905 mojo.execute();
906
907
908
909 File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
910 File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
911 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
912 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
913
914 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
915 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
916 assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
917 assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
918
919
920
921 assertFalse( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
922 "error".equals( FileUtils.fileRead( expectedWebSourceFile ) ) );
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937 expectedWEBINFDir.delete();
938 expectedMETAINFDir.delete();
939 expectedWebSourceFile.delete();
940 expectedWebSource2File.delete();
941 }
942
943 public void testExplodedWarWithOutputFileNameMapping()
944 throws Exception
945 {
946
947 String testId = "ExplodedWarWithFileNameMapping";
948 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
949 File webAppDirectory = new File( getTestDirectory(), testId );
950 File webAppSource = createWebAppSource( testId );
951 File classesDir = createClassesDir( testId, true );
952 ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
953 ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
954 File jarFile = jarArtifact.getFile();
955
956 assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
957
958
959 project.addArtifact( jarArtifact );
960 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
961 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
962 mojo.execute();
963
964
965 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
966 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
967
968 File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
969
970 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
971 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
972 assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
973
974
975 expectedWebSourceFile.delete();
976 expectedWebSource2File.delete();
977 expectedJarArtifact.delete();
978 }
979
980
981
982
983 public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
984 throws Exception
985 {
986
987 String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
988 MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
989 File webAppDirectory = new File( getTestDirectory(), testId );
990 File webAppSource = createWebAppSource( testId );
991 File classesDir = createClassesDir( testId, true );
992 EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
993 EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
994 File ejbFile = ejbArtifact.getFile();
995
996
997 assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
998
999
1000 ejbArtifact.setGroupId( "org.sample.ejb" );
1001 ejbArtifactDup.setGroupId( "org.dup.ejb" );
1002 project.addArtifact( ejbArtifact );
1003 project.addArtifact( ejbArtifactDup );
1004 mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
1005 this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
1006 mojo.execute();
1007
1008
1009 File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
1010 File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
1011
1012 File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
1013 File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
1014
1015 assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
1016 assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
1017 assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
1018 assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
1019
1020
1021 expectedWebSourceFile.delete();
1022 expectedWebSource2File.delete();
1023 expectedEJBArtifact.delete();
1024 expectedEJBDupArtifact.delete();
1025 }
1026
1027
1028
1029
1030
1031 }