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