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