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.plugin.testing.stubs.ArtifactStub;
23  import org.apache.maven.plugins.war.Overlay;
24  import org.apache.maven.plugins.war.overlay.DefaultOverlay;
25  import org.codehaus.plexus.util.FileUtils;
26  
27  import java.io.File;
28  import java.io.FileFilter;
29  import java.io.IOException;
30  import java.util.ArrayList;
31  import java.util.LinkedList;
32  import java.util.List;
33  
34  /**
35   * @author Stephane Nicoll
36   */
37  public class WarOverlaysTest
38      extends AbstractWarExplodedMojoTest
39  {
40  
41      private static File pomFile = new File( getBasedir(), "target/test-classes/unit/waroverlays/default.xml" );
42  
43      public void setUp()
44          throws Exception
45      {
46          super.setUp();
47          generateFullOverlayWar( "overlay-full-1" );
48          generateFullOverlayWar( "overlay-full-2" );
49          generateFullOverlayWar( "overlay-full-3" );
50      }
51  
52      protected File getPomFile()
53      {
54          return pomFile;
55      }
56  
57      protected File getTestDirectory()
58      {
59          return new File( getBasedir(), "target/test-classes/unit/waroverlays" );
60      }
61  
62      public void testEnvironment()
63          throws Exception
64      {
65          // see setup
66      }
67  
68      public void testNoOverlay()
69          throws Exception
70      {
71          // setup test data
72          final String testId = "no-overlay";
73          final File xmlSource = createXMLConfigDir( testId, new String[] { "web.xml" } );
74  
75          final File webAppDirectory = setUpMojo( testId, null );
76          try
77          {
78              mojo.setWebXml( new File( xmlSource, "web.xml" ) );
79              mojo.execute();
80  
81              // Validate content of the webapp
82              assertDefaultContent( webAppDirectory );
83              assertWebXml( webAppDirectory );
84          }
85          finally
86          {
87              cleanDirectory( webAppDirectory );
88          }
89      }
90  
91      public void testDefaultOverlay()
92          throws Exception
93      {
94          // setup test data
95          final String testId = "default-overlay";
96  
97          // Add an overlay
98          final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
99  
100         final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay } );
101         final List<File> assertedFiles = new ArrayList<File>();
102         try
103         {
104             mojo.execute();
105             assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
106             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
107             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp" },
108                                                        "overlay file not found" ) );
109 
110             // index and login come from overlay1
111             assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" );
112             assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
113 
114             // Ok now check that there is no more files/directories
115             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
116             assertWebAppContent( webAppDirectory, assertedFiles, filter );
117         }
118         finally
119         {
120             cleanDirectory( webAppDirectory );
121         }
122     }
123 
124     public void testDefaultOverlays()
125         throws Exception
126     {
127         // setup test data
128         final String testId = "default-overlays";
129 
130         // Add an overlay
131         final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
132         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-two" );
133 
134         final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay, overlay2 } );
135         final List<File> assertedFiles = new ArrayList<File>();
136         try
137         {
138             mojo.execute();
139             assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
140             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
141             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp",
142                 "admin.jsp" }, "overlay file not found" ) );
143 
144             // index and login come from overlay1
145             assertOverlayedFile( webAppDirectory, "overlay-one", "index.jsp" );
146             assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
147 
148             // admin comes from overlay2
149             // index and login comes from overlay1
150             assertOverlayedFile( webAppDirectory, "overlay-two", "admin.jsp" );
151 
152             // Ok now check that there is no more files/directories
153             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
154             assertWebAppContent( webAppDirectory, assertedFiles, filter );
155         }
156         finally
157         {
158             cleanDirectory( webAppDirectory );
159         }
160     }
161 
162     /**
163      * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
164      * 
165      * It also tests completeness of the resulting war as well as the proper order of dependencies.
166      *
167      * @throws Exception if any error occurs
168      */
169     public void testScenarioOneWithDefaulSettings()
170         throws Exception
171     {
172         // setup test data
173         final String testId = "scenario-one-default-settings";
174 
175         // Add an overlay
176         final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
177         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
178         final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
179 
180         final File webAppDirectory =
181             setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
182                 "org/sample/company/test.jsp", "jsp/b.jsp" } );
183 
184         assertScenariOne( testId, webAppDirectory );
185     }
186 
187     /**
188      * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
189      * 
190      * The default project is not specified in this case so it is processed first by default
191      *
192      * @throws Exception if an error occurs
193      */
194     public void testScenarioOneWithOverlaySettings()
195         throws Exception
196     {
197         // setup test data
198         final String testId = "scenario-one-overlay-settings";
199 
200         // Add an overlay
201         final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
202         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
203         final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
204 
205         final File webAppDirectory =
206             setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
207                 "org/sample/company/test.jsp", "jsp/b.jsp" } );
208 
209         // Add the tags
210         final List<Overlay> overlays = new ArrayList<Overlay>();
211         overlays.add( new DefaultOverlay( overlay1 ) );
212         overlays.add( new DefaultOverlay( overlay2 ) );
213         overlays.add( new DefaultOverlay( overlay3 ) );
214         mojo.setOverlays( overlays );
215 
216         // current project ignored. Should be on top of the list
217         assertScenariOne( testId, webAppDirectory );
218     }
219 
220     /**
221      * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
222      * 
223      * The default project is explicitely specified so this should match the default.
224      *
225      * @throws Exception if an error occurs
226      */
227     public void testScenarioOneWithFullSettings()
228         throws Exception
229     {
230         // setup test data
231         final String testId = "scenario-one-full-settings";
232 
233         // Add an overlay
234         final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
235         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
236         final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
237 
238         final File webAppDirectory =
239             setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
240                 "org/sample/company/test.jsp", "jsp/b.jsp" } );
241 
242         // Add the tags
243         final List<Overlay> overlays = new ArrayList<Overlay>();
244 
245         // Add the default project explicitely
246         overlays.add( mojo.getCurrentProjectOverlay() );
247 
248         // Other overlays
249         overlays.add( new DefaultOverlay( overlay1 ) );
250         overlays.add( new DefaultOverlay( overlay2 ) );
251         overlays.add( new DefaultOverlay( overlay3 ) );
252         mojo.setOverlays( overlays );
253 
254         // current project ignored. Should be on top of the list
255         assertScenariOne( testId, webAppDirectory );
256     }
257 
258     /**
259      * Runs the mojo and asserts a scenerio with 3 overlays and no includes/excludes settings.
260      *
261      * @param testId thie id of the test
262      * @param webAppDirectory the webapp directory
263      * @throws Exception if an exception occurs
264      */
265     private void assertScenariOne( String testId, File webAppDirectory )
266         throws Exception
267     {
268         final List<File> assertedFiles = new ArrayList<File>();
269         try
270         {
271             mojo.execute();
272             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
273             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
274                 "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
275                 "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
276                 "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
277 
278             // Those files should come from the source webapp without any config
279             assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" );
280             assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
281 
282             // Everything else comes from overlay1 (order of addition in the dependencies)
283             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/a.jsp" );
284             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/c.jsp" );
285             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/a.jsp" );
286             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/b.jsp" );
287             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
288             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/web.xml" );
289             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/a.class" );
290             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/b.class" );
291             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/classes/c.class" );
292             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/a.jar" );
293             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/b.jar" );
294             assertOverlayedFile( webAppDirectory, "overlay-full-1", "WEB-INF/lib/c.jar" );
295 
296             // Ok now check that there is no more files/directories
297             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
298             assertWebAppContent( webAppDirectory, assertedFiles, filter );
299         }
300         finally
301         {
302             cleanDirectory( webAppDirectory );
303         }
304     }
305 
306     public void testOverlaysIncludesExcludesWithMultipleDefinitions()
307         throws Exception
308     {
309         // setup test data
310         final String testId = "overlays-includes-excludes-multiple-defs";
311 
312         // Add an overlay
313         final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
314         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
315         final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
316 
317         final File webAppDirectory =
318             setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
319                 "org/sample/company/test.jsp", "jsp/b.jsp" } );
320 
321         Overlay over1 = new DefaultOverlay( overlay3 );
322         over1.setExcludes( "**/a.*,**/c.*,**/*.xml" );
323 
324         Overlay over2 = new DefaultOverlay( overlay1 );
325         over2.setIncludes( "jsp/d/*" );
326         over2.setExcludes( "jsp/d/a.jsp" );
327 
328         Overlay over3 = new DefaultOverlay( overlay3 );
329         over3.setIncludes( "**/*.jsp" );
330 
331         Overlay over4 = new DefaultOverlay( overlay2 );
332 
333         mojo.setOverlays( new LinkedList<Overlay>() );
334         mojo.addOverlay( over1 );
335         mojo.addOverlay( over2 );
336         mojo.addOverlay( over3 );
337         mojo.addOverlay( mojo.getCurrentProjectOverlay() );
338         mojo.addOverlay( over4 );
339 
340         final List<File> assertedFiles = new ArrayList<File>();
341         try
342         {
343             mojo.execute();
344             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
345             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
346                 "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
347                 "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
348                 "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
349 
350             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" );
351             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/b.jsp" );
352             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" );
353             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" );
354             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" );
355             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
356             assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
357             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" );
358             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" );
359             assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" );
360             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" );
361             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" );
362             assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" );
363             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" );
364 
365             // Ok now check that there is no more files/directories
366             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
367             assertWebAppContent( webAppDirectory, assertedFiles, filter );
368         }
369         finally
370         {
371             cleanDirectory( webAppDirectory );
372         }
373     }
374 
375     public void testOverlaysIncludesExcludesWithMultipleDefinitions2()
376         throws Exception
377     {
378         // setup test data
379         final String testId = "overlays-includes-excludes-multiple-defs2";
380 
381         // Add an overlay
382         final ArtifactStub overlay1 = buildWarOverlayStub( "overlay-full-1" );
383         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-full-2" );
384         final ArtifactStub overlay3 = buildWarOverlayStub( "overlay-full-3" );
385 
386         final File webAppDirectory =
387             setUpMojo( testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] {
388                 "org/sample/company/test.jsp", "jsp/b.jsp" } );
389 
390         Overlay over1 = new DefaultOverlay( overlay3 );
391         over1.setExcludes( "**/a.*,**/c.*,**/*.xml,jsp/b.jsp" );
392 
393         Overlay over2 = new DefaultOverlay( overlay1 );
394         over2.setIncludes( "jsp/d/*" );
395         over2.setExcludes( "jsp/d/a.jsp" );
396 
397         Overlay over3 = new DefaultOverlay( overlay3 );
398         over3.setIncludes( "**/*.jsp" );
399         over3.setExcludes( "jsp/b.jsp" );
400 
401         Overlay over4 = new DefaultOverlay( overlay2 );
402 
403         mojo.setOverlays( new LinkedList<Overlay>() );
404         mojo.addOverlay( over1 );
405         mojo.addOverlay( over2 );
406         mojo.addOverlay( over3 );
407         mojo.addOverlay( mojo.getCurrentProjectOverlay() );
408         mojo.addOverlay( over4 );
409 
410         final List<File> assertedFiles = new ArrayList<File>();
411         try
412         {
413             mojo.execute();
414             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
415             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp",
416                 "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp",
417                 "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar",
418                 "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found" ) );
419 
420             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/a.jsp" );
421             assertDefaultFileContent( testId, webAppDirectory, "jsp/b.jsp" );
422             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/c.jsp" );
423             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/a.jsp" );
424             assertOverlayedFile( webAppDirectory, "overlay-full-3", "jsp/d/b.jsp" );
425             assertOverlayedFile( webAppDirectory, "overlay-full-1", "jsp/d/c.jsp" );
426             assertDefaultFileContent( testId, webAppDirectory, "org/sample/company/test.jsp" );
427             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/web.xml" );
428             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class" );
429             assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class" );
430             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class" );
431             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar" );
432             assertOverlayedFile( webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar" );
433             assertOverlayedFile( webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar" );
434 
435             // Ok now check that there is no more files/directories
436             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
437             assertWebAppContent( webAppDirectory, assertedFiles, filter );
438         }
439         finally
440         {
441             cleanDirectory( webAppDirectory );
442         }
443 
444     }
445 
446     public void testCacheWithUpdatedOverlay()
447         throws Exception
448     {
449         // setup test data
450         final String testId = "cache-updated-overlay";
451 
452         // Add an overlay
453         final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
454         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-two" );
455 
456         final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay, overlay2 } );
457         final List<File> assertedFiles = new ArrayList<File>();
458         try
459         {
460             // Use the cache
461             setVariableValueToObject( mojo, "useCache", Boolean.TRUE );
462             setVariableValueToObject( mojo, "cacheFile", new File( mojo.getWorkDirectory(), "cache.xml" ) );
463 
464             final LinkedList<Overlay> overlays = new LinkedList<Overlay>();
465             overlays.add( new DefaultOverlay( overlay ) );
466             overlays.add( new DefaultOverlay( overlay2 ) );
467             mojo.setOverlays( overlays );
468 
469             mojo.execute();
470 
471             // Now change the overlay order and make sure the right file is overwritten
472             final LinkedList<Overlay> updatedOverlays = new LinkedList<Overlay>();
473             updatedOverlays.add( new DefaultOverlay( overlay2 ) );
474             updatedOverlays.add( new DefaultOverlay( overlay ) );
475             mojo.setOverlays( updatedOverlays );
476 
477             mojo.execute();
478 
479             assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
480             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
481             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp",
482                 "admin.jsp" }, "overlay file not found" ) );
483 
484             // index and login come from overlay2 now
485             assertOverlayedFile( webAppDirectory, "overlay-two", "index.jsp" );
486             assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
487             assertOverlayedFile( webAppDirectory, "overlay-two", "admin.jsp" );
488 
489             // Ok now check that there is no more files/directories
490             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
491             assertWebAppContent( webAppDirectory, assertedFiles, filter );
492         }
493         finally
494         {
495             cleanDirectory( webAppDirectory );
496         }
497     }
498 
499     public void testCacheWithRemovedOverlay()
500         throws Exception
501     {
502         // setup test data
503         final String testId = "cache-removed-overlay";
504 
505         // Add an overlay
506         final ArtifactStub overlay = buildWarOverlayStub( "overlay-one" );
507         final ArtifactStub overlay2 = buildWarOverlayStub( "overlay-two" );
508 
509         final File webAppDirectory = setUpMojo( testId, new ArtifactStub[] { overlay, overlay2 } );
510         final List<File> assertedFiles = new ArrayList<File>();
511         try
512         {
513             // Use the cache
514             setVariableValueToObject( mojo, "useCache", Boolean.TRUE );
515             setVariableValueToObject( mojo, "cacheFile", new File( mojo.getWorkDirectory(), "cache.xml" ) );
516 
517             final LinkedList<Overlay> overlays = new LinkedList<Overlay>();
518             overlays.add( new DefaultOverlay( overlay ) );
519             overlays.add( new DefaultOverlay( overlay2 ) );
520             mojo.setOverlays( overlays );
521 
522             mojo.execute();
523 
524             // Now remove overlay one the right file is overwritten
525             final LinkedList<Overlay> updatedOverlays = new LinkedList<Overlay>();
526             updatedOverlays.add( new DefaultOverlay( overlay2 ) );
527             mojo.setOverlays( updatedOverlays );
528 
529             // Remove overlay one as a dep
530             mojo.getProject().getArtifacts().remove( overlay );
531 
532             mojo.execute();
533 
534             assertedFiles.addAll( assertDefaultContent( webAppDirectory ) );
535             assertedFiles.addAll( assertWebXml( webAppDirectory ) );
536             assertedFiles.addAll( assertCustomContent( webAppDirectory, new String[] { "index.jsp", "login.jsp",
537                 "admin.jsp" }, "overlay file not found" ) );
538 
539             // index and login come from overlay2 now
540             assertOverlayedFile( webAppDirectory, "overlay-two", "index.jsp" );
541             assertOverlayedFile( webAppDirectory, "overlay-one", "login.jsp" );
542             assertOverlayedFile( webAppDirectory, "overlay-two", "admin.jsp" );
543 
544             // Ok now check that there is no more files/directories
545             final FileFilter filter = new FileFilterImpl( webAppDirectory, new String[] { MANIFEST_PATH } );
546             assertWebAppContent( webAppDirectory, assertedFiles, filter );
547         }
548         finally
549         {
550             cleanDirectory( webAppDirectory );
551         }
552     }
553 
554     // Helpers
555 
556     /**
557      * Asserts that the content of an overlayed file is correct.
558      * 
559      * Note that the <tt>filePath</tt> is relative to both the webapp directory and the overlayed directory, defined by
560      * the <tt>overlayId</tt>.
561      *
562      * @param webAppDirectory the webapp directory
563      * @param overlayId the id of the overlay
564      * @param filePath the relative path
565      * @throws IOException if an error occurred while reading the files
566      */
567     protected void assertOverlayedFile( File webAppDirectory, String overlayId, String filePath )
568         throws IOException
569     {
570         final File webAppFile = new File( webAppDirectory, filePath );
571         final File overlayFile = getOverlayFile( overlayId, filePath );
572         assertEquals( "Wrong content for overlayed file " + filePath, FileUtils.fileRead( overlayFile ),
573                       FileUtils.fileRead( webAppFile ) );
574 
575     }
576 
577     /**
578      * Asserts that the content of an overlayed file is correct.
579      * 
580      * Note that the <tt>filePath</tt> is relative to both the webapp directory and the overlayed directory, defined by
581      * the <tt>overlayId</tt>.
582      *
583      * @param testId te id of the test
584      * @param webAppDirectory the webapp directory
585      * @param filePath the relative path
586      * @throws IOException if an error occurred while reading the files
587      */
588     protected void assertDefaultFileContent( String testId, File webAppDirectory, String filePath )
589         throws Exception
590     {
591         final File webAppFile = new File( webAppDirectory, filePath );
592         final File sourceFile = new File( getWebAppSource( testId ), filePath );
593         final String expectedContent = sourceFile.toString();
594         assertEquals( "Wrong content for file " + filePath, expectedContent, FileUtils.fileRead( webAppFile ) );
595 
596     }
597 
598     protected ArtifactStub generateSimpleWarArtifactStub( String id )
599         throws Exception
600     {
601         return buildWarOverlayStub( id );
602     }
603 }