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