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