View Javadoc
1   package org.apache.maven.plugins.war;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.maven.artifact.handler.ArtifactHandler;
23  import org.apache.maven.plugin.testing.stubs.ArtifactStub;
24  import org.apache.maven.plugins.war.stub.AarArtifactStub;
25  import org.apache.maven.plugins.war.stub.EJBArtifactStub;
26  import org.apache.maven.plugins.war.stub.EJBArtifactStubWithClassifier;
27  import org.apache.maven.plugins.war.stub.EJBClientArtifactStub;
28  import org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub;
29  import org.apache.maven.plugins.war.stub.JarArtifactStub;
30  import org.apache.maven.plugins.war.stub.MarArtifactStub;
31  import org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub;
32  import org.apache.maven.plugins.war.stub.MavenProjectBasicStub;
33  import org.apache.maven.plugins.war.stub.PARArtifactStub;
34  import org.apache.maven.plugins.war.stub.ResourceStub;
35  import org.apache.maven.plugins.war.stub.TLDArtifactStub;
36  import org.apache.maven.plugins.war.stub.WarArtifactStub;
37  import org.apache.maven.plugins.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       * @throws Exception in case of an error.
61       */
62      public void testSimpleExplodedWar()
63          throws Exception
64      {
65          // setup test data
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          // configure mojo
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          // validate operation
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          // house keeping
99          expectedWebSourceFile.delete();
100         expectedWebSource2File.delete();
101         expectedWebResourceFile.delete();
102     }
103 
104     /**
105      * @throws Exception in case of an error.
106      */
107     public void testSimpleExplodedWarWTargetPath()
108         throws Exception
109     {
110         // setup test data
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         // configure mojo
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         // validate operation
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         // house keeping
143         expectedWebSourceFile.delete();
144         expectedWebSource2File.delete();
145         expectedWebResourceFile.delete();
146     }
147 
148     /**
149      * @throws Exception in case of an error.
150      */
151     public void testExplodedWar_WithCustomWebXML()
152         throws Exception
153     {
154         // setup test data
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         // configure mojo
163         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
164         mojo.setWebXml( new File( xmlSource, "web.xml" ) );
165         mojo.execute();
166 
167         // validate operation
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         // house keeping
180         expectedWebSourceFile.delete();
181         expectedWebSource2File.delete();
182         expectedWEBXMLFile.delete();
183         expectedMETAINFDir.delete();
184     }
185 
186     /**
187      * @throws Exception in case of an error.
188      */
189     public void testExplodedWar_WithContainerConfigXML()
190         throws Exception
191     {
192         // setup test data
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         // configure mojo
201         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
202         mojo.setContainerConfigXML( new File( xmlSource, "config.xml" ) );
203         mojo.execute();
204 
205         // validate operation
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         // house keeping
218         expectedWebSourceFile.delete();
219         expectedWebSource2File.delete();
220         expectedContainerConfigXMLFile.delete();
221         expectedWEBINFDir.delete();
222     }
223 
224     /**
225      * @throws Exception in case of an error.
226      */
227     public void testExplodedWar_WithSimpleExternalWARFile()
228         throws Exception
229     {
230         // setup test data
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         // configure mojo
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         // validate operation - META-INF is automatically excluded so remove the file from the list
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         // check simple.war in the unit test dir under resources to verify the list of files
260         assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
261         assertTrue( "war file not found: " + expectedWARFile.toString(), expectedWARFile.exists() );
262 
263         // house keeping
264         expectedWebSourceFile.delete();
265         expectedWebSource2File.delete();
266         expectedWEBXMLFile.delete();
267         expectedWARFile.delete();
268     }
269 
270     /**
271      * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
272      * @throws Exception in case of an error.
273      */
274     public void testExplodedWarMergeWarLocalFileOverride()
275         throws Exception
276     {
277         // setup test data
278         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
279         WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
280 
281         String testId = "testExplodedWarMergeWarLocalFileOverride";
282         File webAppDirectory = new File( getTestDirectory(), testId );
283         File webAppSource = getWebAppSource( testId );
284         File simpleJSP = new File( webAppSource, "org/sample/company/test.jsp" );
285         createFile( simpleJSP );
286 
287         File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
288         createDir( workDirectory );
289 
290         File classesDir = createClassesDir( testId, true );
291 
292         // configure mojo
293         project.addArtifact( warArtifact );
294         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
295         setVariableValueToObject( mojo, "workDirectory", workDirectory );
296         mojo.execute();
297 
298         // validate operation
299         File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
300 
301         assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
302         assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
303 
304         // check when the merged war file is newer - so set an old time on the local file
305         long time = new SimpleDateFormat( "yyyy-MM-dd", Locale.US ).parse( "2005-1-1" ).getTime();
306         simpleJSP.setLastModified( time );
307         expectedFile.setLastModified( time );
308 
309         project.addArtifact( warArtifact );
310         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
311         setVariableValueToObject( mojo, "workDirectory", workDirectory );
312         mojo.execute();
313 
314         assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
315         assertEquals( "file incorrect", simpleJSP.toString(), FileUtils.fileRead( expectedFile ) );
316 
317         // house keeping
318         expectedFile.delete();
319     }
320 
321     // The last modified thingy behavior is not applicable anymore. This is the only test that
322     // has been removed.
323     // /**
324     // * Merge a dependent WAR that gets updated since the last run.
325     // */
326     // public void testExplodedWarMergeWarUpdated()
327     // throws Exception
328     // {
329     // // setup test data
330     // MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
331     // WarArtifactStub warArtifact = new WarArtifactStub( getBasedir() );
332     //
333     // String testId = "testExplodedWarMergeWarUpdated";
334     // File webAppDirectory = new File( getTestDirectory(), testId );
335     // FileUtils.deleteDirectory( webAppDirectory );
336     //
337     // File webAppSource = getWebAppSource( testId );
338     //
339     // File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
340     // createDir( workDirectory );
341     //
342     // File classesDir = createClassesDir( testId, true );
343     //
344     // // configure mojo
345     // project.addArtifact( warArtifact );
346     // this.configureMojo( mojo, new LinkedList(), classesDir, webAppSource, webAppDirectory, project );
347     // setVariableValueToObject( mojo, "workDirectory", workDirectory );
348     // mojo.execute();
349     //
350     // // validate operation
351     // File expectedFile = new File( webAppDirectory, "/org/sample/company/test.jsp" );
352     //
353     // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
354     // assertEquals( "file incorrect", "", FileUtils.fileRead( expectedFile ) );
355     //
356     // // update file, so the local one is older
357     // warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple-updated.war" ) );
358     //
359     // mojo.execute();
360     //
361     // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
362     // assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
363     //
364     // // update file, so the local one is newer
365     // warArtifact.setFile( new File( warArtifact.getFile().getParentFile(), "simple.war" ) );
366     //
367     // mojo.execute();
368     //
369     // assertTrue( "file not found: " + expectedFile.toString(), expectedFile.exists() );
370     // assertEquals( "file incorrect", "updated\n", FileUtils.fileRead( expectedFile ) );
371     //
372     // // house keeping
373     // expectedFile.delete();
374     // }
375 
376     /**
377      * @throws Exception in case of an error.
378      */
379     public void testExplodedWar_WithEJB()
380         throws Exception
381     {
382         // setup test data
383         String testId = "ExplodedWar_WithEJB";
384         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
385         File webAppDirectory = new File( getTestDirectory(), testId );
386         File webAppSource = createWebAppSource( testId );
387         File classesDir = createClassesDir( testId, true );
388         EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
389         File ejbFile = ejbArtifact.getFile();
390 
391         assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
392 
393         // configure mojo
394         project.addArtifact( ejbArtifact );
395         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
396         mojo.execute();
397 
398         // validate operation
399         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
400         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
401         // final name form is <artifactId>-<version>.<type>
402         File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
403         // File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
404 
405         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
406         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
407         assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
408 
409         // house keeping
410         expectedWebSourceFile.delete();
411         expectedWebSource2File.delete();
412         expectedEJBArtifact.delete();
413     }
414 
415     public void testExplodedWarWithJar()
416         throws Exception
417     {
418         // setup test data
419         String testId = "ExplodedWarWithJar";
420         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
421         File webAppDirectory = new File( getTestDirectory(), testId );
422         File webAppSource = createWebAppSource( testId );
423         File classesDir = createClassesDir( testId, true );
424         ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
425         ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
426         File jarFile = jarArtifact.getFile();
427 
428         assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
429 
430         // configure mojo
431         project.addArtifact( jarArtifact );
432         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
433         mojo.execute();
434 
435         // validate operation
436         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
437         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
438         // final name form is <artifactId>-<version>.<type>
439         File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact-0.0-Test.jar" );
440 
441         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
442         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
443         assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
444 
445         // house keeping
446         expectedWebSourceFile.delete();
447         expectedWebSource2File.delete();
448         expectedJarArtifact.delete();
449     }
450 
451     /**
452      * @throws Exception in case of an error.
453      */
454     public void testExplodedWar_WithEJBClient()
455         throws Exception
456     {
457         // setup test data
458         String testId = "ExplodedWar_WithEJB";
459         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
460         File webAppDirectory = new File( getTestDirectory(), testId );
461         File webAppSource = createWebAppSource( testId );
462         File classesDir = createClassesDir( testId, true );
463         EJBClientArtifactStub ejbArtifact = new EJBClientArtifactStub( getBasedir() );
464         File ejbFile = ejbArtifact.getFile();
465 
466         assertTrue( "ejb jar not found: " + ejbFile.toString(), ejbFile.exists() );
467 
468         // configure mojo
469         project.addArtifact( ejbArtifact );
470         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
471         mojo.execute();
472 
473         // validate operation
474         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
475         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
476         // final name form is <artifactId>-<version>.<type>
477         File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbclientartifact-0.0-Test-client.jar" );
478 
479         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
480         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
481         assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
482 
483         // house keeping
484         expectedWebSourceFile.delete();
485         expectedWebSource2File.delete();
486         expectedEJBArtifact.delete();
487     }
488 
489     /**
490      * @throws Exception in case of an error.
491      */
492     public void testExplodedWar_WithTLD()
493         throws Exception
494     {
495         // setup test data
496         String testId = "ExplodedWar_WithTLD";
497         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
498         File webAppDirectory = new File( getTestDirectory(), testId );
499         File webAppSource = createWebAppSource( testId );
500         File classesDir = createClassesDir( testId, true );
501         TLDArtifactStub tldArtifact = new TLDArtifactStub( getBasedir() );
502         File tldFile = tldArtifact.getFile();
503 
504         assertTrue( "tld jar not found: " + tldFile.getAbsolutePath(), tldFile.exists() );
505 
506         // configure mojo
507         project.addArtifact( tldArtifact );
508         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
509         mojo.execute();
510 
511         // validate operation
512         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
513         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
514         // final name form is <artifactId>-<version>.<type>
515         File expectedTLDArtifact = new File( webAppDirectory, "WEB-INF/tld/tldartifact-0.0-Test.tld" );
516 
517         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
518         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
519         assertTrue( "tld artifact not found: " + expectedTLDArtifact.toString(), expectedTLDArtifact.exists() );
520 
521         // house keeping
522         expectedWebSourceFile.delete();
523         expectedWebSource2File.delete();
524         expectedTLDArtifact.delete();
525     }
526 
527     /**
528      * @throws Exception in case of an error.
529      */
530     public void testExplodedWar_WithPAR()
531         throws Exception
532     {
533         // setup test data
534         String testId = "ExplodedWar_WithPAR";
535         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
536         File webAppDirectory = new File( getTestDirectory(), testId );
537         File webAppSource = createWebAppSource( testId );
538         File classesDir = createClassesDir( testId, true );
539         PARArtifactStub parartifact = new PARArtifactStub( getBasedir() );
540         File parFile = parartifact.getFile();
541 
542         assertTrue( "par not found: " + parFile.getAbsolutePath(), parFile.exists() );
543 
544         // configure mojo
545         project.addArtifact( parartifact );
546         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
547         mojo.execute();
548 
549         // validate operation
550         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
551         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
552         // final name form is <artifactId>-<version>.<type>
553         File expectedPARArtifact = new File( webAppDirectory, "WEB-INF/lib/parartifact-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( "par artifact not found: " + expectedPARArtifact.toString(), expectedPARArtifact.exists() );
558 
559         // house keeping
560         expectedWebSourceFile.delete();
561         expectedWebSource2File.delete();
562         expectedPARArtifact.delete();
563     }
564 
565     /**
566      * @throws Exception in case of an error.
567      */
568     public void testExplodedWarWithAar()
569         throws Exception
570     {
571         // setup test data
572         String testId = "ExplodedWarWithAar";
573         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
574         File webAppDirectory = new File( getTestDirectory(), testId );
575         File webAppSource = createWebAppSource( testId );
576         File classesDir = createClassesDir( testId, true );
577         // Fake here since the aar artifact handler does not exist: no biggie
578         ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
579         ArtifactStub aarArtifact = new AarArtifactStub( getBasedir(), artifactHandler );
580         File aarFile = aarArtifact.getFile();
581 
582         assertTrue( "jar not found: " + aarFile.toString(), aarFile.exists() );
583 
584         // configure mojo
585         project.addArtifact( aarArtifact );
586         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
587         mojo.execute();
588 
589         // validate operation
590         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
591         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
592         // final name form is <artifactId>-<version>.<type>
593         File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/services/aarartifact-0.0-Test.jar" );
594 
595         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
596         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
597         assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
598 
599         // house keeping
600         expectedWebSourceFile.delete();
601         expectedWebSource2File.delete();
602         expectedJarArtifact.delete();
603     }
604 
605     /**
606      * @throws Exception in case of an error.
607      */
608     public void testExplodedWarWithMar()
609         throws Exception
610     {
611         // setup test data
612         String testId = "ExplodedWarWithMar";
613         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
614         File webAppDirectory = new File( getTestDirectory(), testId );
615         File webAppSource = createWebAppSource( testId );
616         File classesDir = createClassesDir( testId, true );
617         // Fake here since the mar artifact handler does not exist: no biggie
618         ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
619         ArtifactStub marArtifact = new MarArtifactStub( getBasedir(), artifactHandler );
620         File marFile = marArtifact.getFile();
621 
622         assertTrue( "jar not found: " + marFile.toString(), marFile.exists() );
623 
624         // configure mojo
625         project.addArtifact( marArtifact );
626         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
627         mojo.execute();
628 
629         // validate operation
630         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
631         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
632         // final name form is <artifactId>-<version>.<type>
633         File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/modules/marartifact-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( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
638 
639         // house keeping
640         expectedWebSourceFile.delete();
641         expectedWebSource2File.delete();
642         expectedJarArtifact.delete();
643     }
644 
645     /**
646      * @throws Exception in case of an error.
647      */
648     public void testExplodedWarWithXar()
649         throws Exception
650     {
651         // setup test data
652         String testId = "ExplodedWarWithXar";
653         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
654         File webAppDirectory = new File( getTestDirectory(), testId );
655         File webAppSource = createWebAppSource( testId );
656         File classesDir = createClassesDir( testId, true );
657         // Fake here since the xar artifact handler does not exist: no biggie
658         ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
659         ArtifactStub xarArtifact = new XarArtifactStub( getBasedir(), artifactHandler );
660         File xarFile = xarArtifact.getFile();
661 
662         assertTrue( "jar not found: " + xarFile.toString(), xarFile.exists() );
663 
664         // configure mojo
665         project.addArtifact( xarArtifact );
666         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
667         mojo.execute();
668 
669         // validate operation
670         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
671         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
672         // final name form is <artifactId>-<version>.<type>
673         File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar" );
674 
675         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
676         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
677         assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
678 
679         // house keeping
680         expectedWebSourceFile.delete();
681         expectedWebSource2File.delete();
682         expectedJarArtifact.delete();
683     }
684 
685     /**
686      * @throws Exception in case of an error.
687      */
688     public void testExplodedWar_WithDuplicateDependencies()
689         throws Exception
690     {
691         // setup test data
692         String testId = "ExplodedWar_WithDuplicateDependencies";
693         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
694         File webAppDirectory = new File( getTestDirectory(), testId );
695         File webAppSource = createWebAppSource( testId );
696         File classesDir = createClassesDir( testId, true );
697         EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
698         EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
699         File ejbFile = ejbArtifact.getFile();
700 
701         // ejbArtifact has a hard coded file, only one assert is needed
702         assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
703 
704         // configure mojo
705         ejbArtifact.setGroupId( "org.sample.ejb" );
706         ejbArtifactDup.setGroupId( "org.dup.ejb" );
707         project.addArtifact( ejbArtifact );
708         project.addArtifact( ejbArtifactDup );
709         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
710         mojo.execute();
711 
712         // validate operation
713         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
714         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
715         // final name form is <artifactId>-<version>.<type>
716         File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact-0.0-Test.jar" );
717         File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact-0.0-Test.jar" );
718 
719         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
720         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
721         assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
722         assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
723 
724         // house keeping
725         expectedWebSourceFile.delete();
726         expectedWebSource2File.delete();
727         expectedEJBArtifact.delete();
728         expectedEJBDupArtifact.delete();
729     }
730 
731     /**
732      * @throws Exception in case of an error.
733      */
734     public void testExplodedWar_DuplicateWithClassifier()
735         throws Exception
736     {
737         // setup test data
738         String testId = "ExplodedWar_DuplicateWithClassifier";
739         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
740         File webAppDirectory = new File( getTestDirectory(), testId );
741         File webAppSource = createWebAppSource( testId );
742         File classesDir = createClassesDir( testId, true );
743         EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
744         EJBArtifactStubWithClassifier ejbArtifactDup = new EJBArtifactStubWithClassifier( getBasedir() );
745 
746         File ejbFile = ejbArtifact.getFile();
747 
748         // ejbArtifact has a hard coded file, only one assert is needed
749         assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
750 
751         // configure mojo
752 
753         ejbArtifact.setGroupId( "org.sample.ejb" );
754         ejbArtifactDup.setGroupId( "org.sample.ejb" );
755 
756         ejbArtifactDup.setClassifier( "classifier" );
757 
758         project.addArtifact( ejbArtifact );
759         project.addArtifact( ejbArtifactDup );
760 
761         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
762         mojo.execute();
763 
764         // validate operation
765         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
766         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
767         // final name form is <artifactId>-<version>.<type>
768         File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test.jar" );
769         File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/ejbartifact-0.0-Test-classifier.jar" );
770 
771         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
772         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
773         assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
774         assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
775 
776         // house keeping
777         expectedWebSourceFile.delete();
778         expectedWebSource2File.delete();
779         expectedEJBArtifact.delete();
780         expectedEJBDupArtifact.delete();
781     }
782 
783     /**
784      * @throws Exception in case of an error.
785      */
786     public void testExplodedWar_WithClasses()
787         throws Exception
788     {
789         // setup test data
790         String testId = "ExplodedWar_WithClasses";
791         MavenProjectBasicStub project = new MavenProjectBasicStub();
792         File webAppDirectory = new File( getTestDirectory(), testId );
793         File webAppSource = createWebAppSource( testId );
794         File classesDir = createClassesDir( testId, false );
795 
796         // configure mojo
797         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
798         mojo.execute();
799 
800         // validate operation
801         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
802         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
803         // final name form is <artifactId>-<version>.<type>
804         File expectedClass = new File( webAppDirectory, "WEB-INF/classes/sample-servlet.class" );
805 
806         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
807         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
808         assertTrue( "classes not found: " + expectedClass.toString(), expectedClass.exists() );
809 
810         // house keeping
811         expectedWebSourceFile.delete();
812         expectedWebSource2File.delete();
813         expectedClass.delete();
814     }
815 
816     /**
817      * @throws Exception in case of an error.
818      */
819     public void testExplodedWar_WithSourceIncludeExclude()
820         throws Exception
821     {
822         // setup test data
823         String testId = "ExplodedWar_WithSourceIncludeExclude";
824         MavenProjectBasicStub project = new MavenProjectBasicStub();
825         File webAppSource = createWebAppSource( testId );
826         File classesDir = createClassesDir( testId, true );
827         File webAppDirectory = new File( getTestDirectory(), testId );
828 
829         // configure mojo
830         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
831         setVariableValueToObject( mojo, "warSourceIncludes", "**/*sit.jsp" );
832         setVariableValueToObject( mojo, "warSourceExcludes", "**/last*.*" );
833         mojo.execute();
834 
835         // validate operation
836         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
837         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
838         File expectedWEBXMLDir = new File( webAppDirectory, "WEB-INF" );
839         File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
840 
841         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
842         assertFalse( "source files found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
843         assertTrue( "WEB XML not found: " + expectedWEBXMLDir.toString(), expectedWEBXMLDir.exists() );
844         assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
845 
846         // house keeping
847         expectedWebSourceFile.delete();
848         expectedWebSource2File.delete();
849         expectedWEBXMLDir.delete();
850         expectedMETAINFDir.delete();
851     }
852 
853     /**
854      * @throws Exception in case of an error.
855      */
856     public void testExplodedWar_WithWarDependencyIncludeExclude()
857         throws Exception
858     {
859         // setup test data
860         String testId = "ExplodedWar_WithWarDependencyIncludeExclude";
861         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
862         IncludeExcludeWarArtifactStub includeexcludeWarArtifact = new IncludeExcludeWarArtifactStub( getBasedir() );
863         File webAppDirectory = new File( getTestDirectory(), testId );
864         File webAppSource = createWebAppSource( testId );
865         File classesDir = createClassesDir( testId, true );
866         File workDirectory = new File( getTestDirectory(), "/war/work-" + testId );
867         File includeExcludeWarFile = includeexcludeWarArtifact.getFile();
868 
869         assertTrue( "war not found: " + includeExcludeWarFile.toString(), includeExcludeWarFile.exists() );
870 
871         createDir( workDirectory );
872 
873         // configure mojo
874         project.addArtifact( includeexcludeWarArtifact );
875         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
876         setVariableValueToObject( mojo, "dependentWarIncludes", "**/*Include.jsp,**/*.xml" );
877         setVariableValueToObject( mojo, "dependentWarExcludes", "**/*Exclude*,**/MANIFEST.MF" );
878         setVariableValueToObject( mojo, "workDirectory", workDirectory );
879         mojo.execute();
880 
881         // validate operation
882         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
883         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
884         File expectedManifestFile = new File( webAppDirectory, "META-INF/MANIFEST.MF" );
885         File expectedWEBXMLFile = new File( webAppDirectory, "WEB-INF/web.xml" );
886         File expectedIncludedWARFile = new File( webAppDirectory, "/org/sample/company/testInclude.jsp" );
887         File expectedExcludedWarfile = new File( webAppDirectory, "/org/sample/companyExclude/test.jsp" );
888 
889         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
890         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
891         // check include-exclude.war in the unit test dir under resources to verify the list of files
892         assertTrue( "web xml not found: " + expectedWEBXMLFile.toString(), expectedWEBXMLFile.exists() );
893         assertFalse( "manifest file found: " + expectedManifestFile.toString(), expectedManifestFile.exists() );
894         assertTrue( "war file not found: " + expectedIncludedWARFile.toString(), expectedIncludedWARFile.exists() );
895         assertFalse( "war file not found: " + expectedExcludedWarfile.toString(), expectedExcludedWarfile.exists() );
896 
897         // house keeping
898         expectedWebSourceFile.delete();
899         expectedWebSource2File.delete();
900         expectedManifestFile.delete();
901         expectedWEBXMLFile.delete();
902         expectedIncludedWARFile.delete();
903         expectedExcludedWarfile.delete();
904     }
905 
906     /**
907      * @throws Exception in case of an error.
908      */
909     public void testExplodedWarWithSourceModificationCheck()
910         throws Exception
911     {
912         // setup test data
913         String testId = "ExplodedWarWithSourceModificationCheck";
914         MavenProjectBasicStub project = new MavenProjectBasicStub();
915         File webAppSource = createWebAppSource( testId );
916         File classesDir = createClassesDir( testId, false );
917         File webAppDirectory = new File( getTestDirectory(), testId );
918 
919         // configure mojo
920         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
921 
922         // destination file is already created manually containing an "error" string
923         // source is newer than the destination file
924         mojo.execute();
925 
926         // validate operation
927 
928         File expectedWEBINFDir = new File( webAppDirectory, "WEB-INF" );
929         File expectedMETAINFDir = new File( webAppDirectory, "META-INF" );
930         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
931         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
932 
933         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
934         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
935         assertTrue( "WEB-INF not found", expectedWEBINFDir.exists() );
936         assertTrue( "META-INF not found", expectedMETAINFDir.exists() );
937 
938         // 1st phase destination is older than source
939         // destination starts with a value of error replaced with a blank source
940         assertFalse( "source files not updated with new copy: " + expectedWebSourceFile.toString(),
941                      "error".equals( FileUtils.fileRead( expectedWebSourceFile ) ) );
942 
943         // TODO: uncomment when lastModified problem is resolved
944         // FileWriter writer = new FileWriter(expectedWebSourceFile);
945         //
946         // // 2nd phase destination is newer than source
947         // // destination should not be replaced with an blank source
948         // writer.write("newdata");
949         // mojo.execute();
950         // reader = new FileReader(expectedWebSourceFile);
951         // reader.read(data);
952         // assertTrue("source file updated with old copy: "
953         // +expectedWebSourceFile.toString(),String.valueOf(data).equals("newdata") ); }
954 
955         // house keeping
956         expectedWEBINFDir.delete();
957         expectedMETAINFDir.delete();
958         expectedWebSourceFile.delete();
959         expectedWebSource2File.delete();
960     }
961 
962     /**
963      * @throws Exception in case of an error.
964      */
965     public void testExplodedWarWithOutputFileNameMapping()
966         throws Exception
967     {
968         // setup test data
969         String testId = "ExplodedWarWithFileNameMapping";
970         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
971         File webAppDirectory = new File( getTestDirectory(), testId );
972         File webAppSource = createWebAppSource( testId );
973         File classesDir = createClassesDir( testId, true );
974         ArtifactHandler artifactHandler = (ArtifactHandler) lookup( ArtifactHandler.ROLE, "jar" );
975         ArtifactStub jarArtifact = new JarArtifactStub( getBasedir(), artifactHandler );
976         File jarFile = jarArtifact.getFile();
977 
978         assertTrue( "jar not found: " + jarFile.toString(), jarFile.exists() );
979 
980         // configure mojo
981         project.addArtifact( jarArtifact );
982         mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
983         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
984         mojo.execute();
985 
986         // validate operation
987         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
988         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
989         // final name form is <artifactId>-<version>.<type>
990         File expectedJarArtifact = new File( webAppDirectory, "WEB-INF/lib/jarartifact.jar" );
991 
992         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
993         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
994         assertTrue( "jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists() );
995 
996         // house keeping
997         expectedWebSourceFile.delete();
998         expectedWebSource2File.delete();
999         expectedJarArtifact.delete();
1000     }
1001 
1002     /**
1003      * @throws Exception in case of an error.
1004      */
1005     public void testExplodedWarWithOutputFileNameMappingAndDuplicateDependencies()
1006         throws Exception
1007     {
1008         // setup test data
1009         String testId = "ExplodedWarWithFileNameMappingAndDuplicateDependencies";
1010         MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
1011         File webAppDirectory = new File( getTestDirectory(), testId );
1012         File webAppSource = createWebAppSource( testId );
1013         File classesDir = createClassesDir( testId, true );
1014         EJBArtifactStub ejbArtifact = new EJBArtifactStub( getBasedir() );
1015         EJBArtifactStub ejbArtifactDup = new EJBArtifactStub( getBasedir() );
1016         File ejbFile = ejbArtifact.getFile();
1017 
1018         // ejbArtifact has a hard coded file, only one assert is needed
1019         assertTrue( "ejb not found: " + ejbFile.getAbsolutePath(), ejbFile.exists() );
1020 
1021         // configure mojo
1022         ejbArtifact.setGroupId( "org.sample.ejb" );
1023         ejbArtifactDup.setGroupId( "org.dup.ejb" );
1024         project.addArtifact( ejbArtifact );
1025         project.addArtifact( ejbArtifactDup );
1026         mojo.setOutputFileNameMapping( "@{artifactId}@.@{extension}@" );
1027         this.configureMojo( mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project );
1028         mojo.execute();
1029 
1030         // validate operation
1031         File expectedWebSourceFile = new File( webAppDirectory, "pansit.jsp" );
1032         File expectedWebSource2File = new File( webAppDirectory, "org/web/app/last-exile.jsp" );
1033         // final name form is <artifactId>-<version>.<type>
1034         File expectedEJBArtifact = new File( webAppDirectory, "WEB-INF/lib/org.sample.ejb-ejbartifact.jar" );
1035         File expectedEJBDupArtifact = new File( webAppDirectory, "WEB-INF/lib/org.dup.ejb-ejbartifact.jar" );
1036 
1037         assertTrue( "source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists() );
1038         assertTrue( "source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists() );
1039         assertTrue( "ejb artifact not found: " + expectedEJBArtifact.toString(), expectedEJBArtifact.exists() );
1040         assertTrue( "ejb dup artifact not found: " + expectedEJBDupArtifact.toString(), expectedEJBDupArtifact.exists() );
1041 
1042         // house keeping
1043         expectedWebSourceFile.delete();
1044         expectedWebSource2File.delete();
1045         expectedEJBArtifact.delete();
1046         expectedEJBDupArtifact.delete();
1047     }
1048 
1049     /* --------------------- 2.1 Overlay tests ----------------------------------- */
1050 
1051     /*---------------------------*/
1052 
1053 }